-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix(lsp): make sure to always reset active codelens refreshes #18331
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(lsp): make sure to always reset active codelens refreshes #18331
Conversation
This fixes issues where subsequent calls to vim.lsp.codelens.refresh()
would have no effect due to the buffer not getting cleared from the
active_refresh table.
Examples of how such scenarios would occur are:
- A textDocument/codeLens result yielded an error.
- The 'textDocument/codeLens' handler was overriden in such a way that
it no longer called vim.lsp.codelens.on_codelens().
888d47e to
7c13013
Compare
runtime/lua/vim/lsp/codelens.lua
Outdated
| active_refreshes[bufnr] = true | ||
| vim.lsp.buf_request(0, 'textDocument/codeLens', params) | ||
| vim.lsp.buf_request(0, 'textDocument/codeLens', params, function (...) | ||
| active_refreshes[bufnr] = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would clear it too early in the success case - it should wait until the lenses are all resolved.
M.on_codelens needs to be called always even in the error case and
neovim/runtime/lua/vim/lsp/codelens.lua
Line 217 in cc27540
| assert(not err, vim.inspect(err)) |
Could probably also use a test-case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I figured it was only throttling the initial request.
Could probably also use a test-case
Yeah I wanted to start with a failing test, but struggled a bit with how to pull it off as I couldn't find a way to mock/stub the RPC client interface. Any pointers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See
neovim/test/functional/plugin/lsp_spec.lua
Lines 2784 to 2836 in 039d60b
| describe('vim.lsp.codelens', function() | |
| it('uses client commands', function() | |
| local client | |
| local expected_handlers = { | |
| {NIL, {}, {method="shutdown", client_id=1}}; | |
| {NIL, {}, {method="start", client_id=1}}; | |
| } | |
| test_rpc_server { | |
| test_name = 'clientside_commands', | |
| on_init = function(client_) | |
| client = client_ | |
| end, | |
| on_setup = function() | |
| end, | |
| on_exit = function(code, signal) | |
| eq(0, code, "exit code", fake_lsp_logfile) | |
| eq(0, signal, "exit signal", fake_lsp_logfile) | |
| end, | |
| on_handler = function(err, result, ctx) | |
| eq(table.remove(expected_handlers), {err, result, ctx}) | |
| if ctx.method == 'start' then | |
| local fake_uri = "file:///fake/uri" | |
| local cmd = exec_lua([[ | |
| fake_uri = ... | |
| local bufnr = vim.uri_to_bufnr(fake_uri) | |
| vim.fn.bufload(bufnr) | |
| vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'One line'}) | |
| local lenses = { | |
| { | |
| range = { | |
| start = { line = 0, character = 0, }, | |
| ['end'] = { line = 0, character = 8 } | |
| }, | |
| command = { title = 'Lens1', command = 'Dummy' } | |
| }, | |
| } | |
| vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr}) | |
| local cmd_called = nil | |
| vim.lsp.commands['Dummy'] = function(command) | |
| cmd_called = command | |
| end | |
| vim.api.nvim_set_current_buf(bufnr) | |
| vim.lsp.codelens.run() | |
| return cmd_called | |
| ]], fake_uri) | |
| eq({ command = 'Dummy', title = 'Lens1' }, cmd) | |
| elseif ctx.method == 'shutdown' then | |
| client.stop() | |
| end | |
| end | |
| } | |
| end) | |
| end) |
The test_name links to a fake-server implementation:
neovim/test/functional/plugin/lsp_spec.lua
Line 2792 in 039d60b
| test_name = 'clientside_commands', |
neovim/test/functional/fixtures/fake-lsp-server.lua
Lines 781 to 793 in 039d60b
| function tests.clientside_commands() | |
| skeleton { | |
| on_init = function() | |
| return { | |
| capabilities = {} | |
| } | |
| end; | |
| body = function() | |
| notify('start') | |
| notify('shutdown') | |
| end; | |
| } | |
| end |
You can create a new one that uses expect_request to send an error response to the client.
Similar to here, (except that it should return the error instead of a regular result)
neovim/test/functional/fixtures/fake-lsp-server.lua
Lines 773 to 775 in 039d60b
| expect_request('textDocument/codeAction', function() | |
| return nil, { action, preferred_action, } | |
| end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed fa35548. The test code got a bit messy as I was struggling a bit with the asynchronous nature of vim.lsp.codelens.refresh() (I'd rather not have to override and vim.wait for vim.lsp.codelens.on_codelens, if possible)
| if err then | ||
| active_refreshes[ctx.bufnr] = nil | ||
| local _ = log.error() and log.error("codelens", ctx.client_id, err) | ||
| return | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured logging the error and silently returning would be more in-line with what I'd personally expect. I also think it improves the overall experience, for example rust_analyzer returns errors when trying to retrieve codelenses before its cargo metadata check has resolved. With the error + vim.inspect approach, this is pretty disruptive as it more or less hijacks the entire editor
| active_refreshes[bufnr] = nil | ||
| vim.lsp.handlers['textDocument/codeLens'](...) | ||
| end) | ||
| vim.lsp.buf_request(0, 'textDocument/codeLens', params, M.on_codelens) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure vim.lsp.codelens.on_codelens() is called (so the refresh lock is released), I figured it'd make sense to explicitly pass it as the handler here? I can't think of a use case where a custom textDocument/codeLens handler should be called when calling vim.lsp.codelens.refresh().
…-refresh-clear * origin/master: vim-patch:8.2.1835: ":help ??" finds the "!!" tag (neovim#18350) vim-patch:8.2.3306: unexpected "No matching autocommands" (neovim#17912) fix(api): preserve `cmdmod` on `nvim_parse_cmd` fix(shared): avoid indexing unindexable values in vim.tbl_get() (neovim#18337) build(gen_vimdoc): abort if doxygen version is too old docs: syntax is enabled by default (neovim#17637) chore(editorconfig): unset "charset" for *.vim and *.po files docs(api): more API attributes neovim#18336 docs: move "hl-VertSplit" to deprecated.txt neovim#18328 refactor: replace char_u variables and functions with char fix(lsp): fix infinite loop in resolved_capabilities deprecation message (neovim#18333) fix(lsp): handle textDocumentSync.save bool capability (neovim#18332) fix(mac): use same $LANG fallback mechanism as Vim
|
Backport failed for Please cherry-pick the changes locally. git fetch origin release-0.7
git worktree add -d .worktree/backport-18331-to-release-0.7 origin/release-0.7
cd .worktree/backport-18331-to-release-0.7
git checkout -b backport-18331-to-release-0.7
ancref=$(git merge-base 327a6d885c1f209f232a75670fc6b4613a3633e3 fa35548343afe09c969574e58a50a31b8d14c57b)
git cherry-pick -x $ancref..fa35548343afe09c969574e58a50a31b8d14c57b |
…#18331) This fixes issues where subsequent calls to vim.lsp.codelens.refresh() would have no effect due to the buffer not getting cleared from the active_refresh table. Examples of how such scenarios would occur are: - A textDocument/codeLens result yielded an error. - The 'textDocument/codeLens' handler was overriden in such a way that it no longer called vim.lsp.codelens.on_codelens().
This fixes issues where subsequent calls to vim.lsp.codelens.refresh()
would have no effect due to the buffer not getting cleared from the
active_refresh table.
Examples of how such scenarios would occur are:
- A textDocument/codeLens result yielded an error.
- The 'textDocument/codeLens' handler was overriden in such a way that
it no longer called vim.lsp.codelens.on_codelens().
(cherry picked from commit 94eb72c)
BREAKING CHANGES: fdd5178 neovim#18986 introduce $NVIM, unset $NVIM_LISTEN_ADDRESS VIM PATCHES: git log --oneline --grep "vim-patch" v0.7.0..v0.7.1 FEATURES: 0b8facc neovim#18440 feat(api): add `group_name` to `nvim_get_autocmds` b7a5278 neovim#18440 feat(api): add `group_name` to `nvim_get_autocmds` 9e5cef9 neovim#18264 feat(tui): query terminal for CSI u support FIXES: b477afa neovim#19088 71e2c49 refactor(tests): introduce testprg() 175892f neovim#15913 fix: make_filter_cmd for :! powershell f2b4652 neovim#18331 fix(lsp): make sure to always reset active codelens refreshes b3d754c neovim#18869 fix(lsp): fix multi client handling in code action e820c6d neovim#19069 cf9c097 fix(api): check for inclusive buffer line index out of bounds correctly a05da1c neovim#19053 17299b3 fix(input): use correct grid when restoring cursor for <expr> mapping 7266150 neovim#19025 40e13c8 neovim#19010 fix(decorations): nvim_buf_set_extmark breaks conceal 38928b5 neovim#19023 18e0d64 fix(tui): fix piping output make nvim unusable cd7ac0e neovim#19014 433f306 fix: use ctermbg/fg instead of bg/fg when use_rgb is false 30ae06c neovim#19009 777d415 fix(highlight): let winhighlight use cursor f70e083 neovim#18981 fix(hl): return cterm fg/bg even if they match Normal ee210b0 fix(hl): DRY set_hl_group() sg_attr set 512a819 test(hl): Add Normal group set_hl/get_hl_by_name check 79ca64a neovim#18024) fix(hl): set Normal hl group sg_attr value (fixes 2ebc76b neovim#19001 4170983 fix(startup): nvim with --clean should not load user rplugins ed9e6d1 neovim#18990 fix(treesitter): new iter if folded 05ce04e neovim#18984 fe42dea neovim#18976 fix(lua): highlight.on_yank can close timer in twice f15d609 neovim#18824 fix(lua): stop pending highlight.on_yank timer, if any 5243cb8 neovim#18975 bf4df2a fix(ui): do not call showmode() when setting window height 3cea4d6 neovim#18942 05f6883 fix(buffer): disable buffer-updates before removing buffer from window 1dba6cf neovim#18918 0c9d666 fix(input): fix macro recording with ALT and special key fc4e4b3 neovim#18905 bd3bb12 test(ts): skip test if C parser is not available d317cb2 neovim#18886 1496f42 fix(input): allow Ctrl-C to interrupt a recursive mapping even if mapped 0dc5bcd neovim#18680 3a1e8ef neovim#18617 fix(autocmds): separate command from desc cb1b4bb neovim#18655 fix(lsp): only send diagnostics from current buffer in code_action() 01d0d2c neovim#18517 build(deps): bump Luv to HEAD - c51e7052e f3ffb73 neovim#18612 fix(health): return 0 if file not exists 496e786 neovim#18534 0377973 fix(runtime/genvimvim): omit s[ubstitute] from vimCommand 35075dc neovim#18469 fix(lsp): fix unnecessary buffers being added on empty diagnostics 9e040ac neovim#18468 fix(lsp): unify progress message handling e28799f neovim#18436 fix: display global statusline correctly with ext_messages 1e28068 neovim#18415 fix: ensure has() does not change v:shell_error 203b088 neovim#18411 build(deps): bump LuaJIT to HEAD - 91bc6b8ad e502e81 neovim#18400 fix(treesitter): bump match limit up 7567d21 neovim#18390 d165289 fix(lsp): add missing bufnr argument f3587ba neovim#18367 631393a fix(filetype.lua): escape expansion of ~ when used as a pattern 08cd391 neovim#18360 fix(shared): avoid indexing unindexable values in vim.tbl_get() 508c8a5 neovim#18362 fix(ftdetect): source plugins in autogroup ffd46b7 neovim#18351 2a61983 fix(mac): use same $LANG fallback mechanism as Vim 8d4fbcb neovim#18324 b80ef0d fix(tui): disable extended keys before exiting alternate screen 14a5b6b neovim#18312 89260ea fix(input): only disable mapped CTRL-C interrupts when getting input ef43e7d neovim#18298 fix: suppress "is a directory" messages with shortmess 'F' aff05c5 neovim#18256 fix: show autocmd output when F is in shortmess fa7d8c3 neovim#18229 d916d2f neovim#18227 fix(lua): don't mutate opts parameter of vim.keymap.del f7e2ad7 neovim#18220 fix(treesitter): create new parser if language is not the same as cached parser 7f8faac neovim#18205 fix(diagnostic): use nvim_exec_autocmds to trigger DiagnosticChanged 3ee089e neovim#18167 0f811af fix(tui): update modifyOtherKeys reporting
BREAKING CHANGES: fdd5178 #18986 introduce $NVIM, unset $NVIM_LISTEN_ADDRESS VIM PATCHES: git log --oneline --grep "vim-patch" v0.7.0..v0.7.1 FEATURES: 0b8facc #18440 feat(api): add `group_name` to `nvim_get_autocmds` b7a5278 #18440 feat(api): add `group_name` to `nvim_get_autocmds` 9e5cef9 #18264 feat(tui): query terminal for CSI u support FIXES: b477afa #19088 71e2c49 refactor(tests): introduce testprg() 175892f #15913 fix: make_filter_cmd for :! powershell f2b4652 #18331 fix(lsp): make sure to always reset active codelens refreshes b3d754c #18869 fix(lsp): fix multi client handling in code action e820c6d #19069 cf9c097 fix(api): check for inclusive buffer line index out of bounds correctly a05da1c #19053 17299b3 fix(input): use correct grid when restoring cursor for <expr> mapping 7266150 #19025 40e13c8 #19010 fix(decorations): nvim_buf_set_extmark breaks conceal 38928b5 #19023 18e0d64 fix(tui): fix piping output make nvim unusable cd7ac0e #19014 433f306 fix: use ctermbg/fg instead of bg/fg when use_rgb is false 30ae06c #19009 777d415 fix(highlight): let winhighlight use cursor f70e083 #18981 fix(hl): return cterm fg/bg even if they match Normal ee210b0 fix(hl): DRY set_hl_group() sg_attr set 512a819 test(hl): Add Normal group set_hl/get_hl_by_name check 79ca64a #18024) fix(hl): set Normal hl group sg_attr value (fixes 2ebc76b #19001 4170983 fix(startup): nvim with --clean should not load user rplugins ed9e6d1 #18990 fix(treesitter): new iter if folded 05ce04e #18984 fe42dea #18976 fix(lua): highlight.on_yank can close timer in twice f15d609 #18824 fix(lua): stop pending highlight.on_yank timer, if any 5243cb8 #18975 bf4df2a fix(ui): do not call showmode() when setting window height 3cea4d6 #18942 05f6883 fix(buffer): disable buffer-updates before removing buffer from window 1dba6cf #18918 0c9d666 fix(input): fix macro recording with ALT and special key fc4e4b3 #18905 bd3bb12 test(ts): skip test if C parser is not available d317cb2 #18886 1496f42 fix(input): allow Ctrl-C to interrupt a recursive mapping even if mapped 0dc5bcd #18680 3a1e8ef #18617 fix(autocmds): separate command from desc cb1b4bb #18655 fix(lsp): only send diagnostics from current buffer in code_action() 01d0d2c #18517 build(deps): bump Luv to HEAD - c51e7052e f3ffb73 #18612 fix(health): return 0 if file not exists 496e786 #18534 0377973 fix(runtime/genvimvim): omit s[ubstitute] from vimCommand 35075dc #18469 fix(lsp): fix unnecessary buffers being added on empty diagnostics 9e040ac #18468 fix(lsp): unify progress message handling e28799f #18436 fix: display global statusline correctly with ext_messages 1e28068 #18415 fix: ensure has() does not change v:shell_error 203b088 #18411 build(deps): bump LuaJIT to HEAD - 91bc6b8ad e502e81 #18400 fix(treesitter): bump match limit up 7567d21 #18390 d165289 fix(lsp): add missing bufnr argument f3587ba #18367 631393a fix(filetype.lua): escape expansion of ~ when used as a pattern 08cd391 #18360 fix(shared): avoid indexing unindexable values in vim.tbl_get() 508c8a5 #18362 fix(ftdetect): source plugins in autogroup ffd46b7 #18351 2a61983 fix(mac): use same $LANG fallback mechanism as Vim 8d4fbcb #18324 b80ef0d fix(tui): disable extended keys before exiting alternate screen 14a5b6b #18312 89260ea fix(input): only disable mapped CTRL-C interrupts when getting input ef43e7d #18298 fix: suppress "is a directory" messages with shortmess 'F' aff05c5 #18256 fix: show autocmd output when F is in shortmess fa7d8c3 #18229 d916d2f #18227 fix(lua): don't mutate opts parameter of vim.keymap.del f7e2ad7 #18220 fix(treesitter): create new parser if language is not the same as cached parser 7f8faac #18205 fix(diagnostic): use nvim_exec_autocmds to trigger DiagnosticChanged 3ee089e #18167 0f811af fix(tui): update modifyOtherKeys reporting diff --git a/CMakeLists.txt b/CMakeLists.txt index 769a93a..9b5563b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY set(NVIM_VERSION_MAJOR 0) set(NVIM_VERSION_MINOR 7) set(NVIM_VERSION_PATCH 1) -set(NVIM_VERSION_PRERELEASE "-dev") # for package maintainers +set(NVIM_VERSION_PRERELEASE "") # for package maintainers # API level set(NVIM_API_LEVEL 9) # Bump this after any API change. diff --git a/runtime/nvim.appdata.xml b/runtime/nvim.appdata.xml index 1464c27..893023d 100644 --- a/runtime/nvim.appdata.xml +++ b/runtime/nvim.appdata.xml @@ -26,6 +26,7 @@ </screenshots> <releases> + <release date="2022-06-26" version="0.7.1"/> <release date="2022-04-15" version="0.7.0"/> <release date="2021-12-31" version="0.6.1"/> <release date="2021-11-30" version="0.6.0"/>
This fixes issues where subsequent calls to vim.lsp.codelens.refresh()
would have no effect due to the buffer not getting cleared from the
active_refresh table.
Examples of how such scenarios would occur are:
it no longer called vim.lsp.codelens.on_codelens().