Sha256: d880c4fa059bd2911b9466557defd9f86c725c778ae779bcf2379bed44aa0c8d

Contents?: true

Size: 903 Bytes

Versions: 30

Compression:

Stored size: 903 Bytes

Contents

# frozen_string_literal: true

module ThemeCheck
  module LanguageServer
    class ObjectCompletionProvider < CompletionProvider
      def completions(content, cursor)
        return [] unless (variable_lookup = variable_lookup_at_cursor(content, cursor))
        return [] unless variable_lookup.lookups.empty?
        return [] if content[cursor - 1] == "."
        ShopifyLiquid::Object.labels
          .select { |w| w.start_with?(partial(variable_lookup)) }
          .map { |object| object_to_completion(object) }
      end

      def variable_lookup_at_cursor(content, cursor)
        VariableLookupFinder.lookup(content, cursor)
      end

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

      private

      def object_to_completion(object)
        {
          label: object,
          kind: CompletionItemKinds::VARIABLE,
        }
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
theme-check-1.11.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.10.3 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.10.2 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.10.1 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.10.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.9.2 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.9.1 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.9.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.8.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.7.2 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.7.1 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.7.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.6.2 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.6.1 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.6.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.5.2 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.5.1 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.5.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.4.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb
theme-check-1.3.0 lib/theme_check/language_server/completion_providers/object_completion_provider.rb