Class: RubyLsp::Requests::Diagnostics
- Defined in:
- lib/ruby_lsp/requests/diagnostics.rb
Overview
The [diagnostics](microsoft.github.io/language-server-protocol/specification#textDocument_publishDiagnostics) request informs the editor of RuboCop offenses for a given file.
Class Method Summary collapse
-
.provider ⇒ Object
: -> Interface::DiagnosticRegistrationOptions.
Instance Method Summary collapse
-
#initialize(global_state, document) ⇒ Diagnostics
constructor
: (GlobalState global_state, RubyDocument document) -> void.
-
#perform ⇒ Object
: -> (Array & Object)?.
Constructor Details
#initialize(global_state, document) ⇒ Diagnostics
: (GlobalState global_state, RubyDocument document) -> void
22 23 24 25 26 27 |
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 22 def initialize(global_state, document) super() @active_linters = global_state.active_linters #: Array[Support::Formatter] @document = document @uri = document.uri #: URI::Generic end |
Class Method Details
.provider ⇒ Object
: -> Interface::DiagnosticRegistrationOptions
12 13 14 15 16 17 18 |
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 12 def provider Interface::DiagnosticRegistrationOptions.new( document_selector: nil, inter_file_dependencies: false, workspace_diagnostics: false, ) end |
Instance Method Details
#perform ⇒ Object
: -> (Array & Object)?
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 31 def perform diagnostics = [] diagnostics.concat(syntax_error_diagnostics, syntax_warning_diagnostics) # Running RuboCop is slow, so to avoid excessive runs we only do so if the file is syntactically valid if @document.syntax_error? || @active_linters.empty? || @document.past_expensive_limit? return diagnostics end @active_linters.each do |linter| linter_diagnostics = linter.run_diagnostic(@uri, @document) diagnostics.concat(linter_diagnostics) if linter_diagnostics end diagnostics end |