Sha256: dda62d8aa34774b1bd21683e60e687c8a66e69f86fc33d31468c6af4c690cf5b

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  module LanguageServer
    class TagCompletionProvider < CompletionProvider
      def completions(context)
        content = context.content
        cursor = context.cursor

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

        partial = first_word(content) || ''
        labels = PlatformosLiquid::Tag.labels
        labels += PlatformosLiquid::Tag.end_labels
        labels
          .select { |w| w.start_with?(partial) }
          .map { |tag| tag_to_completion(tag) }
      end

      def can_complete?(content, cursor)
        content.start_with?(Liquid::TagStart) && (
          cursor_on_first_word?(content, cursor) ||
          cursor_on_start_content?(content, cursor, Liquid::TagStart)
        )
      end

      private

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

        {
          label: tag,
          kind: CompletionItemKinds::KEYWORD,
          **doc_hash(content)
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
platformos-check-0.1.0 lib/platformos_check/language_server/completion_providers/tag_completion_provider.rb
platformos-check-0.0.3 lib/platformos_check/language_server/completion_providers/tag_completion_provider.rb
platformos-check-0.0.2 lib/platformos_check/language_server/completion_providers/tag_completion_provider.rb
platformos-check-0.0.1 lib/platformos_check/language_server/completion_providers/tag_completion_provider.rb