Class: RubyLsp::Requests::Definition
- Defined in:
- lib/ruby_lsp/requests/definition.rb
Overview
The [definition request](microsoft.github.io/language-server-protocol/specification#textDocument_definition) jumps to the definition of the symbol under the cursor.
Instance Method Summary collapse
-
#initialize(document, global_state, position, dispatcher, sorbet_level) ⇒ Definition
constructor
: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void.
-
#perform ⇒ Object
: -> Array[(Interface::Location | Interface::LocationLink)].
Constructor Details
#initialize(document, global_state, position, dispatcher, sorbet_level) ⇒ Definition
: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ruby_lsp/requests/definition.rb', line 13 def initialize(document, global_state, position, dispatcher, sorbet_level) super() @response_builder = ResponseBuilders::CollectionResponseBuilder .new #: ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)] @dispatcher = dispatcher char_position, _ = document.find_index_by_position(position) delegate_request_if_needed!(global_state, document, char_position) node_context = RubyDocument.locate( document.ast, char_position, node_types: [ Prism::CallNode, Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::BlockArgumentNode, Prism::GlobalVariableAndWriteNode, Prism::GlobalVariableOperatorWriteNode, Prism::GlobalVariableOrWriteNode, Prism::GlobalVariableReadNode, Prism::GlobalVariableTargetNode, Prism::GlobalVariableWriteNode, Prism::InstanceVariableReadNode, Prism::InstanceVariableAndWriteNode, Prism::InstanceVariableOperatorWriteNode, Prism::InstanceVariableOrWriteNode, Prism::InstanceVariableTargetNode, Prism::InstanceVariableWriteNode, Prism::SymbolNode, Prism::StringNode, Prism::SuperNode, Prism::ForwardingSuperNode, Prism::ClassVariableAndWriteNode, Prism::ClassVariableOperatorWriteNode, Prism::ClassVariableOrWriteNode, Prism::ClassVariableReadNode, Prism::ClassVariableTargetNode, Prism::ClassVariableWriteNode, ], code_units_cache: document.code_units_cache, ) target = node_context.node parent = node_context.parent if target.is_a?(Prism::ConstantReadNode) && parent.is_a?(Prism::ConstantPathNode) # If the target is part of a constant path node, we need to find the exact portion of the constant that the # user is requesting to go to definition for target = determine_target( target, parent, position, ) elsif position_outside_target?(position, target) target = nil # For methods with block arguments using symbol-to-proc elsif target.is_a?(Prism::SymbolNode) && parent.is_a?(Prism::BlockArgumentNode) target = parent end if target Listeners::Definition.new( @response_builder, global_state, document.language_id, document.uri, node_context, dispatcher, sorbet_level, ) Addon.addons.each do |addon| addon.create_definition_listener(@response_builder, document.uri, node_context, dispatcher) end end @target = target #: Prism::Node? end |
Instance Method Details
#perform ⇒ Object
: -> Array[(Interface::Location | Interface::LocationLink)]
95 96 97 98 |
# File 'lib/ruby_lsp/requests/definition.rb', line 95 def perform @dispatcher.dispatch_once(@target) if @target @response_builder.response end |