Sha256: b4155b5927c7901284a9d76193f21f351eb902e2f4195f26abc915e03ea0f879

Contents?: true

Size: 808 Bytes

Versions: 3

Compression:

Stored size: 808 Bytes

Contents

# frozen_string_literal: true

module ThemeCheck
  module LanguageServer
    class TagCompletionProvider < CompletionProvider
      def completions(content, cursor)
        return [] unless can_complete?(content, cursor)
        partial = first_word(content) || ''
        ShopifyLiquid::Tag.labels
          .select { |w| w.starts_with?(partial) }
          .map { |tag| tag_to_completion(tag) }
      end

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

      private

      def tag_to_completion(tag)
        {
          label: tag,
          kind: CompletionItemKinds::KEYWORD,
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
theme-check-0.6.0 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-0.5.0 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-0.4.0 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb