diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-09-24 23:38:46 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-09-24 23:38:46 +0200 |
commit | b80ae6cec34639abfb1a7080fb633346a81a5770 (patch) | |
tree | f718fb24f66452f57e78e1e37fdfa650f78e906f /src/testdir/test_channel.vim | |
parent | ceffca683ba986065e583d02e7ace964efdb256e (diff) |
patch 9.0.1939: still a problem when processing LSP RPC requestsv9.0.1939
Problem: still a problem when processing LSP RPC requests
Solution: When processing async LSP RPC requests, compare sequence
numbers only in response messages
A LSP request message can be sent to the language server either
synchronously (ch_evalexpr) or asynchronously (ch_sendexpr). In both
cases, when looking for response messages by using the sequence number,
LSP requests messages from the language server with the same sequence
number should not be used. Patch 9.0.1927 fixed this issue for
synchronous requests. This PR fixes the issue for asynchronous requests
and adds additional tests.
closes: #13158
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/testdir/test_channel.vim')
-rw-r--r-- | src/testdir/test_channel.vim | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim index edfd56e0ba..8f1291c22c 100644 --- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -2478,23 +2478,32 @@ func Test_job_start_with_invalid_argument() call assert_fails('call job_start([0zff])', 'E976:') endfunc -" Test for the 'lsp' channel mode +" Process requests received from the LSP server +func LspProcessServerRequests(chan, msg) + if a:msg['method'] == 'server-req-in-middle' + \ && a:msg['params']['text'] == 'server-req' + call ch_sendexpr(a:chan, #{method: 'server-req-in-middle-resp', + \ id: a:msg['id'], params: #{text: 'client-resp'}}) + endif +endfunc + +" LSP channel message callback function func LspCb(chan, msg) call add(g:lspNotif, a:msg) if a:msg->has_key('method') - " Requests received from the LSP server - if a:msg['method'] == 'server-req-in-middle' - \ && a:msg['params']['text'] == 'server-req' - call ch_sendexpr(a:chan, #{method: 'server-req-in-middle-resp', - \ id: a:msg['id'], params: #{text: 'client-resp'}}) - endif + call LspProcessServerRequests(a:chan, a:msg) endif endfunc +" LSP one-time message callback function (used for ch_sendexpr()) func LspOtCb(chan, msg) call add(g:lspOtMsgs, a:msg) + if a:msg->has_key('method') + call LspProcessServerRequests(a:chan, a:msg) + endif endfunc +" Test for the 'lsp' channel mode func LspTests(port) " call ch_logfile('Xlspclient.log', 'w') let ch = ch_open(s:localhost .. a:port, #{mode: 'lsp', callback: 'LspCb'}) @@ -2661,7 +2670,7 @@ func LspTests(port) call assert_equal('alive', ch_evalexpr(ch, #{method: 'ping'}).result) " Test for processing a request message from the server while the client - " is waiting for a response with the same identifier. + " is waiting for a response with the same identifier (sync-rpc) let g:lspNotif = [] let resp = ch_evalexpr(ch, #{method: 'server-req-in-middle', \ params: #{text: 'client-req'}}) @@ -2673,6 +2682,44 @@ func LspTests(port) \ #{id: 28, jsonrpc: '2.0', method: 'server-req-in-middle', \ params: #{text: 'server-req'}}], g:lspNotif) + " Test for processing a request message from the server while the client + " is waiting for a response with the same identifier (async-rpc using the + " channel callback function) + let g:lspNotif = [] + call ch_sendexpr(ch, #{method: 'server-req-in-middle', id: 500, + \ params: #{text: 'client-req'}}) + " Send three pings to wait for all the notification messages to arrive + for i in range(3) + call assert_equal('alive', ch_evalexpr(ch, #{method: 'ping'}).result) + endfor + call assert_equal([ + \ #{id: -1, jsonrpc: '2.0', method: 'server-req-in-middle', + \ params: #{text: 'server-notif'}}, + \ #{id: 500, jsonrpc: '2.0', method: 'server-req-in-middle', + \ params: #{text: 'server-req'}}, + \ #{id: 500, jsonrpc: '2.0', result: #{text: 'server-resp'}} + \ ], g:lspNotif) + + " Test for processing a request message from the server while the client + " is waiting for a response with the same identifier (async-rpc using a + " one-time callback function) + let g:lspNotif = [] + let g:lspOtMsgs = [] + call ch_sendexpr(ch, #{method: 'server-req-in-middle', + \ params: #{text: 'client-req'}}, #{callback: 'LspOtCb'}) + " Send a ping to wait for all the notification messages to arrive + for i in range(3) + call assert_equal('alive', ch_evalexpr(ch, #{method: 'ping'}).result) + endfor + call assert_equal([ + \ #{id: 32, jsonrpc: '2.0', result: #{text: 'server-resp'}}], + \ g:lspOtMsgs) + call assert_equal([ + \ #{id: -1, jsonrpc: '2.0', method: 'server-req-in-middle', + \ params: #{text: 'server-notif'}}, + \ #{id: 32, jsonrpc: '2.0', method: 'server-req-in-middle', + \ params: {'text': 'server-req'}}], g:lspNotif) + " Test for invoking an unsupported method let resp = ch_evalexpr(ch, #{method: 'xyz', params: {}}, #{timeout: 200}) call assert_equal({}, resp) |