Class: Rubocop::Language::Server::Model::DiagnosticCollection
- Inherits:
-
Object
- Object
- Rubocop::Language::Server::Model::DiagnosticCollection
- Defined in:
- lib/rubocop/language/server/model/diagnostic_collection.rb
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #code_actions(line_range) ⇒ Object
- #correctable_diagnostics ⇒ Object
-
#initialize(uri, offenses) ⇒ DiagnosticCollection
constructor
A new instance of DiagnosticCollection.
- #response ⇒ Object
Constructor Details
#initialize(uri, offenses) ⇒ DiagnosticCollection
Returns a new instance of DiagnosticCollection.
13 14 15 16 17 18 |
# File 'lib/rubocop/language/server/model/diagnostic_collection.rb', line 13 def initialize(uri, offenses) @uri = uri @diagnostics = offenses.map do |offense| Diagnostic.new(offense) end end |
Instance Attribute Details
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
11 12 13 |
# File 'lib/rubocop/language/server/model/diagnostic_collection.rb', line 11 def diagnostics @diagnostics end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
11 12 13 |
# File 'lib/rubocop/language/server/model/diagnostic_collection.rb', line 11 def uri @uri end |
Instance Method Details
#code_actions(line_range) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rubocop/language/server/model/diagnostic_collection.rb', line 28 def code_actions(line_range) line_diagnostics = correctable_diagnostics.select do |diagnostic| line_range.include?(diagnostic.start.line) end actions = line_diagnostics.map do |diagnostic| code_action_from( diagnostic, title: "Autocorrect `#{diagnostic.cop_name}`", kind: Constant::CodeActionKind::QUICK_FIX ) end if actions.any? actions << code_action_from( line_diagnostics, title: 'Autocorrect all offenses on line', kind: 'rubocop.fix' ) end actions end |
#correctable_diagnostics ⇒ Object
24 25 26 |
# File 'lib/rubocop/language/server/model/diagnostic_collection.rb', line 24 def correctable_diagnostics @correctable_diagnostics ||= diagnostics.select(&:correctable?) end |
#response ⇒ Object
20 21 22 |
# File 'lib/rubocop/language/server/model/diagnostic_collection.rb', line 20 def response diagnostics.map(&:diagnostic_response) end |