Sha256: 4f55cad97b677b69178fe3de8de1973ae75f4830b97f0d86c353516d4714d865
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
# typed: strict # frozen_string_literal: true module RubyLsp module Requests #  # # The [code actions](https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction) # request informs the editor of RuboCop quick fixes that can be applied. These are accessible by hovering over a # specific diagnostic. # # # Example # # ```ruby # def say_hello # puts "Hello" # --> code action: quick fix indentation # end # ``` class CodeActions < BaseRequest extend T::Sig sig do params( document: Document, range: Document::RangeShape, context: T::Hash[Symbol, T.untyped], ).void end def initialize(document, range, context) super(document) @uri = T.let(document.uri, URI::Generic) @range = range @context = context end sig { override.returns(T.nilable(T.all(T::Array[Interface::CodeAction], Object))) } def run 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 code_actions << refactor_code_action(@range, @uri) unless @range.dig(:start) == @range.dig(:end) code_actions end private sig { params(range: Document::RangeShape, uri: URI::Generic).returns(Interface::CodeAction) } def refactor_code_action(range, uri) Interface::CodeAction.new( title: "Refactor: Extract Variable", kind: Constant::CodeActionKind::REFACTOR_EXTRACT, data: { range: range, uri: uri.to_s, }, ) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-lsp-0.13.1 | lib/ruby_lsp/requests/code_actions.rb |