Class: RubyLsp::Refactor::Addon
- Inherits:
-
Addon
- Object
- Addon
- RubyLsp::Refactor::Addon
- Defined in:
- lib/ruby_lsp/ruby_lsp_refactor/addon.rb
Class Method Summary collapse
-
.refactor_actions_for(document, range) ⇒ Array<Interface::CodeAction>
Runs the full listener pipeline against
documentatrangeand returns an array of Interface::CodeAction objects.
Instance Method Summary collapse
-
#activate(global_state, message_queue) ⇒ Object
Called once when the language server activates this add-on.
- #deactivate ⇒ Object
- #name ⇒ Object
- #version ⇒ Object
Class Method Details
.refactor_actions_for(document, range) ⇒ Array<Interface::CodeAction>
Runs the full listener pipeline against document at range and returns an array of Interface::CodeAction objects.
Called from CodeActionsExtension#perform and from the test helper.
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 92 93 94 |
# File 'lib/ruby_lsp/ruby_lsp_refactor/addon.rb', line 59 def self.refactor_actions_for(document, range) return [] unless document.is_a?(RubyLsp::RubyDocument) return [] if document.source.empty? cursor_range = Interface::Range.new( start: Interface::Position.new( line: range.dig(:start, :line), character: range.dig(:start, :character), ), end: Interface::Position.new( line: range.dig(:end, :line), character: range.dig(:end, :character), ), ) node_context = NodeContext.new(document.uri.to_s, cursor_range) response_builder = RubyLsp::ResponseBuilders::CollectionResponseBuilder.new dispatcher = Prism::Dispatcher.new # Phase 1 – Local rewrites ConditionalListener.new(response_builder, node_context, dispatcher) StringListener.new(response_builder, node_context, dispatcher) # Phase 2 – Variable & literal optimisation VariableListener.new(response_builder, node_context, dispatcher) HashListener.new(response_builder, node_context, dispatcher) ArrayListener.new(response_builder, node_context, dispatcher) # Phase 3 – Advanced structure MethodListener.new(response_builder, node_context, dispatcher) dispatcher.dispatch(document.ast) response_builder.response rescue StandardError [] end |
Instance Method Details
#activate(global_state, message_queue) ⇒ Object
Called once when the language server activates this add-on.
34 35 36 37 38 39 |
# File 'lib/ruby_lsp/ruby_lsp_refactor/addon.rb', line 34 def activate(global_state, ) @global_state = global_state # Inject our actions into the standard code-actions response. RubyLsp::Requests::CodeActions.prepend(CodeActionsExtension) end |
#deactivate ⇒ Object
41 |
# File 'lib/ruby_lsp/ruby_lsp_refactor/addon.rb', line 41 def deactivate; end |
#name ⇒ Object
43 44 45 |
# File 'lib/ruby_lsp/ruby_lsp_refactor/addon.rb', line 43 def name "Ruby LSP Refactor" end |
#version ⇒ Object
47 48 49 |
# File 'lib/ruby_lsp/ruby_lsp_refactor/addon.rb', line 47 def version "0.1.0" end |