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( { info: Constant::DiagnosticSeverity::HINT, refactor: Constant::DiagnosticSeverity::INFORMATION, convention: 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(document, offense, uri) ⇒ RuboCopDiagnostic
constructor
A new instance of RuboCopDiagnostic.
- #to_lsp_code_actions ⇒ Object
- #to_lsp_diagnostic ⇒ Object
Constructor Details
#initialize(document, offense, uri) ⇒ RuboCopDiagnostic
Returns a new instance of RuboCopDiagnostic.
25 26 27 28 29 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 25 def initialize(document, offense, uri) @document = document @offense = offense @uri = uri end |
Instance Method Details
#to_lsp_code_actions ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 32 def to_lsp_code_actions code_actions = [] code_actions << autocorrect_action if @offense.correctable? code_actions << disable_line_action code_actions end |
#to_lsp_diagnostic ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ruby_lsp/requests/support/rubocop_diagnostic.rb', line 42 def to_lsp_diagnostic Interface::Diagnostic.new( message: , source: "RuboCop", code: @offense.cop_name, code_description: code_description, 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_actions: to_lsp_code_actions, }, ) end |