Sha256: b4f0a41acbf074973f619a2f7d66a1c97d43693125b4883775ce72c667686a23
Contents?: true
Size: 1.34 KB
Versions: 8
Compression:
Stored size: 1.34 KB
Contents
# typed: strict # frozen_string_literal: true module RubyLsp module Requests # ![Code actions demo](../../misc/code_actions.gif) # # 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 accesible 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( uri: String, document: Document, range: T::Range[Integer] ).void end def initialize(uri, document, range) super(document) @uri = uri @range = range end sig { override.returns(T.all(T::Array[LanguageServer::Protocol::Interface::CodeAction], Object)) } 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 end end end
Version data entries
8 entries across 8 versions & 1 rubygems