Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of textDocument/diagnostic #12664

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_handling_of_text_document_diagnostic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12664](https://github.com/rubocop/rubocop/pull/12664): Fix handling of `textDocument/diagnostic`. ([@muxcmux][])
4 changes: 1 addition & 3 deletions lib/rubocop/lsp/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ def for(name)
end

handle 'textDocument/diagnostic' do |request|
doc = request[:params][:textDocument]
result = diagnostic(doc[:uri], doc[:text])
@server.write(result)
# no-op, diagnostics are handled in textDocument/didChange
end

handle 'textDocument/didChange' do |request|
Expand Down
32 changes: 2 additions & 30 deletions spec/rubocop/lsp/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,43 +103,15 @@
method: 'textDocument/diagnostic',
params: {
textDocument: {
languageId: 'ruby',
text: "def hi#{eol} [1, 2,#{eol} 3 ]#{eol}end#{eol}",
uri: 'file:///path/to/file.rb',
version: 0
uri: 'file:///path/to/file.rb'
}
}
]
end

it 'handles requests' do
expect(stderr).to eq('')
expect(messages.count).to eq(1)
expect(messages.first).to eq(
jsonrpc: '2.0',
method: 'textDocument/publishDiagnostics',
params: {
diagnostics: [
{
code: 'Style/FrozenStringLiteralComment',
message: 'Missing frozen string literal comment.',
range: {
start: { character: 0, line: 0 }, end: { character: 0, line: 0 }
},
severity: 3,
source: 'rubocop'
}, {
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: 'rubocop'
}
], uri: 'file:///path/to/file.rb'
}
)
expect(messages.count).to eq(0)
end
end

Expand Down