Class: RubyLsp::Requests::CodeActions
- Inherits:
-
BaseRequest
- Object
- SyntaxTree::Visitor
- BaseRequest
- RubyLsp::Requests::CodeActions
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_lsp/requests/code_actions.rb
Overview

The [code actions](microsoft.github.io/language-server-protocol/specification#textDocument_codeAction) request informs the editor of RuboCop quick fixes that can be applied. These are accesible by hovering over a specific diagnostic.
# Example
“‘ruby def say_hello puts “Hello” # –> code action: quick fix indentation end “`
Instance Method Summary collapse
-
#initialize(uri, document, range) ⇒ CodeActions
constructor
A new instance of CodeActions.
- #run ⇒ Object
Methods inherited from BaseRequest
#full_constant_name, #locate_node_and_parent, #range_from_syntax_tree_node
Constructor Details
#initialize(uri, document, range) ⇒ CodeActions
Returns a new instance of CodeActions.
29 30 31 32 33 34 |
# File 'lib/ruby_lsp/requests/code_actions.rb', line 29 def initialize(uri, document, range) super(document) @uri = uri @range = range end |
Instance Method Details
#run ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_lsp/requests/code_actions.rb', line 37 def run diagnostics = Diagnostics.new(@uri, @document).run corrections = diagnostics.select do |diagnostic| diagnostic.correctable? && T.cast(diagnostic, Support::RuboCopDiagnostic).in_range?(@range) end return [] if corrections.empty? T.cast(corrections, T::Array[Support::RuboCopDiagnostic]).map!(&:to_lsp_code_action) end |