Class: RubyLsp::Requests::Diagnostics
- Inherits:
-
BaseRequest
- Object
- YARP::Visitor
- BaseRequest
- RubyLsp::Requests::Diagnostics
- 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
-
#initialize(document) ⇒ Diagnostics
constructor
A new instance of Diagnostics.
- #run ⇒ Object
Methods inherited from BaseRequest
Methods included from Support::Common
#create_code_lens, #markdown_from_index_entries, #range_from_location, #range_from_node, #visible?
Constructor Details
#initialize(document) ⇒ Diagnostics
Returns a new instance of Diagnostics.
25 26 27 28 29 |
# File 'lib/ruby_lsp/requests/diagnostics.rb', line 25 def initialize(document) super(document) @uri = T.let(document.uri, URI::Generic) end |
Instance Method Details
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 syntax_error_diagnostics if @document.syntax_error? return unless defined?(Support::RuboCopDiagnosticsRunner) # Don't try to run RuboCop diagnostics for files outside the current working directory path = @uri.to_standardized_path return unless path.nil? || path.start_with?(T.must(WORKSPACE_URI.to_standardized_path)) Support::RuboCopDiagnosticsRunner.instance.run(@uri, @document).map!(&:to_lsp_diagnostic) end |