Module: Holistic::Ruby::Autocompletion::Suggest

Extended by:
Suggest
Included in:
Suggest
Defined in:
lib/holistic/ruby/autocompletion/suggest.rb

Constant Summary collapse

Suggestion =
::Data.define(:code, :kind)
StartsWithLowerCaseLetter =
->(code) do
  return false if [".", ":", "@"].include?(code[0])

  code[0] == code[0].downcase
end

Instance Method Summary collapse

Instance Method Details

#call(code:, scope:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/holistic/ruby/autocompletion/suggest.rb', line 15

def call(code:, scope:)
  lookup_scope = scope

  if code.start_with?("::")
    lookup_scope = lookup_scope.lexical_parent until lookup_scope.root?
  end

  if StartsWithLowerCaseLetter[code]
    suggest_local_methods_from_current_scope(code:, scope: lookup_scope)
  elsif code.include?(".")
    suggest_methods_from_scope(code:, scope: lookup_scope)
  else
    suggest_namespaces_from_scope(code:, scope: lookup_scope)
  end
end