Class: RubyLsp::Requests::PathCompletion
- Extended by:
- T::Generic, T::Sig
- Defined in:
- lib/ruby_lsp/requests/path_completion.rb
Overview

The [completion](microsoft.github.io/language-server-protocol/specification#textDocument_completion) request looks up Ruby files in the $LOAD_PATH to suggest path completion inside ‘require` statements.
# Example
“‘ruby require “ruby_lsp/requests” # –> completion: suggests `base_request`, `code_actions`, … “`
Constant Summary collapse
- ResponseType =
type_member { { fixed: T::Array[Interface::CompletionItem] } }
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(emitter, message_queue) ⇒ PathCompletion
constructor
A new instance of PathCompletion.
- #on_tstring_content(node) ⇒ Object
Methods inherited from Listener
Methods included from Support::Common
#create_code_lens, #full_constant_name, #range_from_syntax_tree_node, #visible?
Constructor Details
#initialize(emitter, message_queue) ⇒ PathCompletion
Returns a new instance of PathCompletion.
26 27 28 29 30 31 32 |
# File 'lib/ruby_lsp/requests/path_completion.rb', line 26 def initialize(emitter, ) super @response = T.let([], ResponseType) @tree = T.let(Support::PrefixTree.new(collect_load_path_files), Support::PrefixTree) emitter.register(self, :on_tstring_content) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
23 24 25 |
# File 'lib/ruby_lsp/requests/path_completion.rb', line 23 def response @response end |
Instance Method Details
#on_tstring_content(node) ⇒ Object
35 36 37 38 39 |
# File 'lib/ruby_lsp/requests/path_completion.rb', line 35 def on_tstring_content(node) @tree.search(node.value).sort.each do |path| @response << build_completion(path, node) end end |