class RubyLsp::Requests::CodeActions
specific diagnostic.
request informs the editor of RuboCop quick fixes that can be applied. These are accessible by hovering over a
The [code actions](microsoft.github.io/language-server-protocol/specification#textDocument_codeAction)
def initialize(document, range, context)
def initialize(document, range, context) super() @document = document @uri = T.let(document.uri, URI::Generic) @range = range @context = context end
def perform
def perform diagnostics = @context[:diagnostics] code_actions = diagnostics.flat_map do |diagnostic| diagnostic.dig(:data, :code_actions) || [] end # Only add refactor actions if there's a non empty selection in the editor unless @range.dig(:start) == @range.dig(:end) code_actions << Interface::CodeAction.new( title: EXTRACT_TO_VARIABLE_TITLE, kind: Constant::CodeActionKind::REFACTOR_EXTRACT, data: { range: @range, uri: @uri.to_s }, ) code_actions << Interface::CodeAction.new( title: EXTRACT_TO_METHOD_TITLE, kind: Constant::CodeActionKind::REFACTOR_EXTRACT, data: { range: @range, uri: @uri.to_s }, ) code_actions << Interface::CodeAction.new( title: TOGGLE_BLOCK_STYLE_TITLE, kind: Constant::CodeActionKind::REFACTOR_REWRITE, data: { range: @range, uri: @uri.to_s }, ) end code_actions end
def provider
def provider Interface::CodeActionRegistrationOptions.new( document_selector: [Interface::DocumentFilter.new(language: "ruby")], resolve_provider: true, ) end