Sha256: 4b29da0389ac926bd391d01b1914b16184b20d10596cd9ad69973ac46cfff0f3

Contents?: true

Size: 878 Bytes

Versions: 11

Compression:

Stored size: 878 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) || ''
        labels = ShopifyLiquid::Tag.labels
        labels += ShopifyLiquid::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)
        {
          label: tag,
          kind: CompletionItemKinds::KEYWORD,
        }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
theme-check-1.11.0 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.10.3 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.10.2 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.10.1 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.10.0 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.9.2 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.9.1 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.9.0 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.8.0 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.7.2 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb
theme-check-1.7.1 lib/theme_check/language_server/completion_providers/tag_completion_provider.rb