Sha256: 466030eb0bc7c8b277f9fea02ccaa41ef82ffeccf90b760faec0ece8cda38af2

Contents?: true

Size: 948 Bytes

Versions: 1

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

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

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

        ShopifyLiquid::Object.labels
          .select { |w| w.start_with?(partial(variable_lookup)) }
          .map { |object| object_to_completion(object) }
      end

      def partial(variable_lookup)
        variable_lookup.name || ''
      end

      private

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
theme-check-1.12.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb