Skip to content

Commit

Permalink
Remove incorrect textDocument/diagnostic request handler
Browse files Browse the repository at this point in the history
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 standardrb#575
  • Loading branch information
muxcmux committed Jan 30, 2024
1 parent fcb21a9 commit af486c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
8 changes: 3 additions & 5 deletions lib/standard/lsp/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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|
Expand Down
31 changes: 2 additions & 29 deletions test/standard/runners/lsp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af486c1

Please sign in to comment.