diff --git a/changelog/fix_handling_of_text_document_diagnostic.md b/changelog/fix_handling_of_text_document_diagnostic.md new file mode 100644 index 000000000000..02a0e77cd60b --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/lsp/routes.rb b/lib/rubocop/lsp/routes.rb index 922560a4cebe..9adc2dfeea4d 100644 --- a/lib/rubocop/lsp/routes.rb +++ b/lib/rubocop/lsp/routes.rb @@ -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| diff --git a/spec/rubocop/lsp/server_spec.rb b/spec/rubocop/lsp/server_spec.rb index dcb357a03097..9b7b0a2e3ffb 100644 --- a/spec/rubocop/lsp/server_spec.rb +++ b/spec/rubocop/lsp/server_spec.rb @@ -103,10 +103,7 @@ 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' } } ] @@ -114,32 +111,7 @@ 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