Class: RubyLsp::Requests::Support::RuboCopDiagnostic
- Inherits:
-
Object
- Object
- RubyLsp::Requests::Support::RuboCopDiagnostic
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_lsp/requests/support/rubocop_diagnostic.rb
Constant Summary collapse
- RUBOCOP_TO_LSP_SEVERITY =
T.let( { convention: Constant::DiagnosticSeverity::INFORMATION, info: Constant::DiagnosticSeverity::INFORMATION, refactor: Constant::DiagnosticSeverity::INFORMATION, warning: Constant::DiagnosticSeverity::WARNING, error: Constant::DiagnosticSeverity::ERROR, fatal: Constant::DiagnosticSeverity::ERROR, }.freeze, T::Hash[Symbol, Integer], )
Instance Method Summary collapse
-
#initialize(offense, uri) ⇒ RuboCopDiagnostic
constructor
A new instance of RuboCopDiagnostic.
- #to_lsp_code_action ⇒ Object
- #to_lsp_diagnostic ⇒ Object
Constructor Details
permalink #initialize(offense, uri) ⇒ RuboCopDiagnostic
Returns a new instance of RuboCopDiagnostic.
23 24 25 26 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 23 def initialize(offense, uri) @offense = offense @uri = uri end |
Instance Method Details
permalink #to_lsp_code_action ⇒ Object
[View source]
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 29 def to_lsp_code_action Interface::CodeAction.new( title: "Autocorrect #{@offense.cop_name}", kind: Constant::CodeActionKind::QUICK_FIX, edit: Interface::WorkspaceEdit.new( document_changes: [ Interface::TextDocumentEdit.new( text_document: Interface::OptionalVersionedTextDocumentIdentifier.new( uri: @uri, version: nil, ), edits: @offense.correctable? ? offense_replacements : [], ), ], ), is_preferred: true, ) end |
permalink #to_lsp_diagnostic ⇒ Object
[View source]
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 49 def to_lsp_diagnostic if @offense.correctable? severity = RUBOCOP_TO_LSP_SEVERITY[@offense.severity.name] = @offense. else severity = Constant::DiagnosticSeverity::WARNING = "#{@offense.}\n\nThis offense is not auto-correctable.\n" end Interface::Diagnostic.new( message: , source: "RuboCop", code: @offense.cop_name, severity: severity, range: Interface::Range.new( start: Interface::Position.new( line: @offense.line - 1, character: @offense.column, ), end: Interface::Position.new( line: @offense.last_line - 1, character: @offense.last_column, ), ), data: { correctable: @offense.correctable?, code_action: to_lsp_code_action, }, ) end |