Class: RubyLsp::Requests::Support::RuboCopDiagnostic
- Inherits:
-
Object
- Object
- RubyLsp::Requests::Support::RuboCopDiagnostic
- Defined in:
- lib/ruby_lsp/requests/support/rubocop_diagnostic.rb
Constant Summary collapse
- RUBOCOP_TO_LSP_SEVERITY =
{ convention: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION, info: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION, refactor: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION, warning: LanguageServer::Protocol::Constant::DiagnosticSeverity::WARNING, error: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR, fatal: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR, }.freeze
Instance Attribute Summary collapse
-
#replacements ⇒ Object
readonly
Returns the value of attribute replacements.
Instance Method Summary collapse
- #correctable? ⇒ Boolean
- #in_range?(range) ⇒ Boolean
-
#initialize(offense, uri) ⇒ RuboCopDiagnostic
constructor
A new instance of RuboCopDiagnostic.
- #to_lsp_code_action ⇒ Object
- #to_lsp_diagnostic ⇒ Object
Constructor Details
#initialize(offense, uri) ⇒ RuboCopDiagnostic
19 20 21 22 23 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 19 def initialize(offense, uri) @offense = offense @uri = uri @replacements = offense.correctable? ? offense_replacements : [] end |
Instance Attribute Details
#replacements ⇒ Object (readonly)
Returns the value of attribute replacements.
17 18 19 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 17 def replacements @replacements end |
Instance Method Details
#correctable? ⇒ Boolean
25 26 27 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 25 def correctable? @offense.correctable? end |
#in_range?(range) ⇒ Boolean
29 30 31 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 29 def in_range?(range) range.cover?(@offense.line - 1) end |
#to_lsp_code_action ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 33 def to_lsp_code_action LanguageServer::Protocol::Interface::CodeAction.new( title: "Autocorrect #{@offense.cop_name}", kind: LanguageServer::Protocol::Constant::CodeActionKind::QUICK_FIX, edit: LanguageServer::Protocol::Interface::WorkspaceEdit.new( document_changes: [ LanguageServer::Protocol::Interface::TextDocumentEdit.new( text_document: LanguageServer::Protocol::Interface::OptionalVersionedTextDocumentIdentifier.new( uri: @uri, version: nil ), edits: @replacements ), ] ), is_preferred: true, ) end |
#to_lsp_diagnostic ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 52 def to_lsp_diagnostic LanguageServer::Protocol::Interface::Diagnostic.new( message: @offense., source: "RuboCop", code: @offense.cop_name, severity: RUBOCOP_TO_LSP_SEVERITY[@offense.severity.name], range: LanguageServer::Protocol::Interface::Range.new( start: LanguageServer::Protocol::Interface::Position.new( line: @offense.line - 1, character: @offense.column ), end: LanguageServer::Protocol::Interface::Position.new( line: @offense.last_line - 1, character: @offense.last_column ) ) ) end |