Class: RubyLsp::Requests::Diagnostics

Inherits:
Request
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/requests/diagnostics.rb

Overview

![Diagnostics demo](../../diagnostics.gif)

The [diagnostics](microsoft.github.io/language-server-protocol/specification#textDocument_publishDiagnostics) request informs the editor of RuboCop offenses for a given file.

# Example

“‘ruby def say_hello puts “Hello” # –> diagnostics: incorrect indentation end “`

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Diagnostics

Returns a new instance of Diagnostics.



37
38
39
40
41
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 37

def initialize(document)
  super()
  @document = document
  @uri = T.let(document.uri, URI::Generic)
end

Class Method Details

.providerObject



28
29
30
31
32
33
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 28

def provider
  {
    interFileDependencies: false,
    workspaceDiagnostics: false,
  }
end

Instance Method Details

#performObject



44
45
46
47
48
49
50
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 44

def perform
  # Running RuboCop is slow, so to avoid excessive runs we only do so if the file is syntactically valid
  return syntax_error_diagnostics if @document.syntax_error?
  return [] unless defined?(Support::RuboCopDiagnosticsRunner)

  Support::RuboCopDiagnosticsRunner.instance.run(@uri, @document).map!(&:to_lsp_diagnostic)
end