Module: RubyLanguageServer::Completion

Defined in:
lib/ruby_language_server/completion.rb

Constant Summary collapse

COMPLETION_ITEM_KIND =
{
  text: 1,
  method: 2,
  function: 3,
  constructor: 4,
  field: 5,
  variable: 6,
  class: 7,
  interface: 8,
  module: 9,
  property: 10,
  unit: 11,
  value: 12,
  enum: 13,
  keyword: 14,
  snippet: 15,
  color: 16,
  file: 17,
  reference: 18
}.freeze

Class Method Summary collapse

Class Method Details

.completion(context, context_scope, position_scopes) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_language_server/completion.rb', line 27

def completion(context, context_scope, position_scopes)
  RubyLanguageServer.logger.debug("completion(#{context}, #{position_scopes.map(&:name)})")
  completions =
    if context.length < 2
      scope_completions(context.first, position_scopes)
    else
      scope_completions_in_target_context(context, context_scope, position_scopes)
    end
  # RubyLanguageServer.logger.debug("completions: #{completions.as_json}")
  {
    isIncomplete: true,
    items: completions.uniq.map do |word, hash|
      {
        label: word,
        kind: COMPLETION_ITEM_KIND[hash[:type]&.to_sym]
      }
    end
  }
end