Sha256: 903339ff467a514c8d972026aaa185d38c87749d5d521e1cc60b88d2ac2a9d12

Contents?: true

Size: 1.09 KB

Versions: 21

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  module LanguageServer
    class TagHoverProvider < HoverProvider
      def completions(context)
        content = context.content

        return [] if content.nil?
        return [] unless can_complete?(context)

        partial = first_word(context.buffer.lines[context.line]) || ''
        PlatformosLiquid::SourceIndex.tags.select { |tag| tag.name.start_with?(partial) }
                                     .map { |tag| tag_to_completion(tag) }.first
      end

      def can_complete?(context)
        context.content.start_with?(Liquid::TagStart) && (cursor_on_first_word?(context.buffer.lines[context.line], context.col) || cursor_on_start_content?(context.buffer.lines[context.line], context.col, Liquid::TagStart))
      end

      private

      def tag_to_completion(tag)
        content = PlatformosLiquid::Documentation.tag_doc(tag.name)

        {
          contents: content,
          label: tag.name,
          kind: CompletionItemKinds::KEYWORD,
          **format_hash(tag),
          **doc_hash(content)
        }
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
platformos-check-0.4.14 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.13 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.12 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.11 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.10 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.9 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.8 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.7 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.6 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.5 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.4 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.3 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.2 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.1 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.4.0 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.3.3 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.3.1 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.3.0 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.2.2 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb
platformos-check-0.2.1 lib/platformos_check/language_server/hover_providers/tag_hover_provider.rb