Sha256: c798487a6a329b8cdcc9f89fad1a604aeacc13b731ad5b526a48d5fd801c7ecc

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  module LanguageServer
    class AssignmentsCompletionProvider < CompletionProvider
      def completions(context)
        content = context.buffer_until_previous_row

        return [] if content.nil?
        return [] unless (variable_lookup = VariableLookupFinder.lookup(context))
        return [] unless variable_lookup.lookups.empty?
        return [] if context.content[context.cursor - 1] == "."

        finder = VariableLookupFinder::AssignmentsFinder.new(content)
        finder.find!
        finder
          .assignments
          .map { |label, potential_lookup| object_to_completion(label, object_name(potential_lookup)) }
          .compact
      end

      private

      def object_to_completion(label, object)
        content = ShopifyLiquid::Documentation.object_doc(object)

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

      def object_name(potential_lookup)
        object, _property = VariableLookupTraverser.lookup_object_and_property(potential_lookup)
        object&.name
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
theme-check-1.15.0 lib/theme_check/language_server/completion_providers/assignments_completion_provider.rb
theme-check-1.14.0 lib/theme_check/language_server/completion_providers/assignments_completion_provider.rb
theme-check-1.13.0 lib/theme_check/language_server/completion_providers/assignments_completion_provider.rb
theme-check-1.12.1 lib/theme_check/language_server/completion_providers/assignments_completion_provider.rb