From af486c16e55d01f6d60e8eb848797e7a6e8f2b26 Mon Sep 17 00:00:00 2001 From: muxcmux Date: Tue, 30 Jan 2024 21:33:34 +0000 Subject: [PATCH] Remove incorrect textDocument/diagnostic request handler The parameters for this request only include a textDocument, which is a TextDocumentIdentifier, an identifier? and a previousResultId?. The TextDocumentIdentifer only has a uri property, which is of type DocumentUri. According to the LSP spec: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_diagnostic this request does not include the contents of the file (which is what the handler was expecting). I have simply made the handling of this request a no-op, since diagnostics are already sent to the client in textDocument/didChange. Note: This also fixes formatting problems related to Neovim 0.10 described in #575 --- lib/standard/lsp/routes.rb | 8 +++----- test/standard/runners/lsp_test.rb | 31 ++----------------------------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/lib/standard/lsp/routes.rb b/lib/standard/lsp/routes.rb index 3afad197..88e53b8f 100644 --- a/lib/standard/lsp/routes.rb +++ b/lib/standard/lsp/routes.rb @@ -13,7 +13,7 @@ def initialize(writer, logger, standardizer) end def self.handle(name, &block) - define_method("handle_#{name}", &block) + define_method(:"handle_#{name}", &block) end def for(name) @@ -51,10 +51,8 @@ def for(name) end end - handle "textDocument/diagnostic" do |request| - doc = request[:params][:textDocument] - result = diagnostic(doc[:uri], doc[:text]) - @writer.write(result) + handle "textDocument/diagnostic" do |_request| + # no op, diagnostics are handled in textDocument/didChange end handle "textDocument/didChange" do |request| diff --git a/test/standard/runners/lsp_test.rb b/test/standard/runners/lsp_test.rb index 4d013baf..4869fecc 100644 --- a/test/standard/runners/lsp_test.rb +++ b/test/standard/runners/lsp_test.rb @@ -72,40 +72,13 @@ def test_diagnotic_route jsonrpc: "2.0", params: { textDocument: { - languageId: "ruby", - text: "def hi\n [1, 2,\n 3 ]\nend\n", - uri: "file:///path/to/file.rb", - version: 0 + uri: "file:///path/to/file.rb" } } }) assert_equal "", err.string - assert_equal 1, msgs.count - assert_equal({ - method: "textDocument/publishDiagnostics", - params: { - diagnostics: [ - {code: "Layout/ArrayAlignment", - message: "Use one level of indentation for elements following the first line of a multi-line array.", - range: {start: {character: 3, line: 2}, end: {character: 3, line: 2}}, - severity: 3, - source: "standard"}, - {code: "Layout/ExtraSpacing", - message: "Unnecessary spacing detected.", - range: {start: {character: 4, line: 2}, end: {character: 4, line: 2}}, - severity: 3, - source: "standard"}, - {code: "Layout/SpaceInsideArrayLiteralBrackets", - message: "Do not use space inside array brackets.", - range: {start: {character: 4, line: 2}, end: {character: 5, line: 2}}, - severity: 3, - source: "standard"} - ], - uri: "file:///path/to/file.rb" - }, - jsonrpc: "2.0" - }, msgs.first) + assert_equal 0, msgs.count end def test_format