Sha256: 92cb56ff0a732b33cd3ed7c996eb0fd75b2aaf6d25d13aa6ee23ebb90055378c

Contents?: true

Size: 1.42 KB

Versions: 14

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  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] == "."

        current_file_type = file_type(find_file(context))

        PlatformosLiquid::SourceIndex
          .objects
          .select(&:global?)
          .select { |object| object.app_file_type ? object.app_file_type == current_file_type : true }
          .select { |object| object.name.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 = PlatformosLiquid::Documentation.render_doc(object)

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

      def find_file(context)
        @storage.platformos_app[context.relative_path]
      end

      def file_type(app_file)
        StringHelpers.underscore(StringHelpers.demodulize(app_file.class.name)).gsub(/_file$/, '')
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
platformos-check-0.4.14 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.13 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.12 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.11 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.10 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.9 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.8 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.7 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.6 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.5 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.4 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.3 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.2 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb
platformos-check-0.4.1 lib/platformos_check/language_server/completion_providers/object_completion_provider.rb