Class: RubyLsp::Rails::DocumentSymbol
- Inherits:
-
Object
- Object
- RubyLsp::Rails::DocumentSymbol
- Extended by:
- T::Sig
- Includes:
- Requests::Support::Common, ActiveSupportTestCaseHelper
- Defined in:
- lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb
Overview
![Document Symbol demo](../../document_symbol.gif)
The [document symbol](microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol) request allows users to navigate between associations, validations, callbacks and ActiveSupport test cases with VS Code’s “Go to Symbol” feature.
Instance Method Summary collapse
-
#initialize(response_builder, dispatcher) ⇒ DocumentSymbol
constructor
A new instance of DocumentSymbol.
- #on_call_node_enter(node) ⇒ Object
- #on_class_node_enter(node) ⇒ Object
- #on_class_node_leave(node) ⇒ Object
- #on_module_node_enter(node) ⇒ Object
- #on_module_node_leave(node) ⇒ Object
Methods included from ActiveSupportTestCaseHelper
Constructor Details
#initialize(response_builder, dispatcher) ⇒ DocumentSymbol
Returns a new instance of DocumentSymbol.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb', line 22 def initialize(response_builder, dispatcher) @response_builder = response_builder @namespace_stack = T.let([], T::Array[String]) dispatcher.register( self, :on_call_node_enter, :on_class_node_enter, :on_class_node_leave, :on_module_node_enter, :on_module_node_leave, ) end |
Instance Method Details
#on_call_node_enter(node) ⇒ Object
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 |
# File 'lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb', line 37 def on_call_node_enter(node) return if @namespace_stack.empty? content = extract_test_case_name(node) if content append_document_symbol( name: content, selection_range: range_from_node(node), range: range_from_node(node), ) end receiver = node.receiver return if receiver && !receiver.is_a?(Prism::SelfNode) = node. case when *Support::Callbacks::ALL, "validate" handle_all_arg_types(node, T.must()) when "validates", "validates!", "validates_each", "belongs_to", "has_one", "has_many", "has_and_belongs_to_many", "attr_readonly", "scope" handle_symbol_and_string_arg_types(node, T.must()) when "validates_with" handle_class_arg_types(node, T.must()) end end |
#on_class_node_enter(node) ⇒ Object
66 67 68 |
# File 'lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb', line 66 def on_class_node_enter(node) add_to_namespace_stack(node) end |
#on_class_node_leave(node) ⇒ Object
71 72 73 |
# File 'lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb', line 71 def on_class_node_leave(node) remove_from_namespace_stack(node) end |
#on_module_node_enter(node) ⇒ Object
76 77 78 |
# File 'lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb', line 76 def on_module_node_enter(node) add_to_namespace_stack(node) end |
#on_module_node_leave(node) ⇒ Object
81 82 83 |
# File 'lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb', line 81 def on_module_node_leave(node) remove_from_namespace_stack(node) end |