Sha256: e61b3b21de80ee1c361c38cc93fd0230bb01db4c92c931c1098c2dbd00499ccd

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

module RubyLsp
  module Requests
    # The
    # [diagnostics](https://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 indentantion
    # end
    # ```
    class Diagnostics < RuboCopRequest
      def run
        return syntax_error_diagnostics if @document.syntax_errors?

        super

        @diagnostics
      end

      def file_finished(_file, offenses)
        @diagnostics = offenses.map { |offense| Support::RuboCopDiagnostic.new(offense, @uri) }
      end

      private

      def syntax_error_diagnostics
        @document.syntax_error_edits.map { |e| Support::SyntaxErrorDiagnostic.new(e) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-lsp-0.0.3 lib/ruby_lsp/requests/diagnostics.rb