Class: RubyLsp::Requests::Diagnostics

Inherits:
BaseRequest
  • 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 “`

Instance Method Summary collapse

Methods inherited from BaseRequest

#visit_all

Methods included from Support::Common

#create_code_lens, #full_constant_name, #range_from_syntax_tree_node, #visible?

Constructor Details

#initialize(document) ⇒ Diagnostics

Returns a new instance of Diagnostics.

[View source]

25
26
27
28
29
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 25

def initialize(document)
  super(document)

  @uri = T.let(document.uri, String)
end

Instance Method Details

#runObject

[View source]

32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 32

def run
  # Running RuboCop is slow, so to avoid excessive runs we only do so if the file is syntactically valid
  return if @document.syntax_error?

  return unless defined?(Support::RuboCopDiagnosticsRunner)

  # Don't try to run RuboCop diagnostics for files outside the current working directory
  return unless URI(@uri).path&.start_with?(T.must(WORKSPACE_URI.path))

  Support::RuboCopDiagnosticsRunner.instance.run(@uri, @document)
end