Skip to content

Commit

Permalink
Merge pull request #12664 from muxcmux/master
Browse files Browse the repository at this point in the history
Fix handling of textDocument/diagnostic
  • Loading branch information
koic committed Apr 24, 2024
2 parents 5f4bbaa + 48b8620 commit 84877a3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
1 change: 1 addition & 0 deletions changelog/fix_handling_of_text_document_diagnostic.md
@@ -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
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
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

0 comments on commit 84877a3

Please sign in to comment.