Sha256: 42bc3bd4ab4c8826747bbcaba82020e5e7d8c1bfe8aae57f27e31b8bcdea7044

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  module LanguageServer
    class ObjectAttributeCompletionProvider < CompletionProvider
      def completions(context)
        content = context.content
        cursor = context.cursor

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

        # Navigate through lookups until the last valid [object, property] level
        object, property = VariableLookupTraverser.lookup_object_and_property(variable_lookup)

        # If the last lookup level is incomplete/invalid, use the partial term
        # to filter object properties.
        partial = partial_property_name(property, variable_lookup)

        return [] unless object

        object
          .properties
          .select { |prop| partial.nil? || prop.name.start_with?(partial) }
          .map { |prop| property_to_completion(prop) }
      end

      private

      def partial_property_name(property, variable_lookup)
        last_property = variable_lookup.lookups.last
        last_property if last_property != property&.name
      end

      def property_to_completion(prop)
        content = PlatformosLiquid::Documentation.render_doc(prop)

        {
          label: prop.name,
          kind: CompletionItemKinds::PROPERTY,
          **format_hash(prop),
          **doc_hash(content)
        }
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
platformos-check-0.4.3 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.4.2 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.4.1 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.4.0 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.3.3 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.3.1 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.3.0 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.2.2 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.2.1 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.2.0 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.1.0 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.0.3 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.0.2 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb
platformos-check-0.0.1 lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb