Sha256: 925b22f64bccbc67e641d19afc5447e28a3ea3abe75e23ffb2129c67dbfa0c9d

Contents?: true

Size: 837 Bytes

Versions: 3

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

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

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

      private

      def object_to_completion(object)
        {
          label: object,
          kind: CompletionItemKinds::VARIABLE,
        }
      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/object_completion_provider.rb
theme-check-0.5.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-0.4.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb