diff options
author | jdrouhard <john@drouhard.dev> | 2022-12-09 04:54:09 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-09 11:54:09 +0100 |
commit | 5e6a288ce7ee079e7695525f2e9e99d071ccdfbf (patch) | |
tree | 723adee97dc5dcf22f1c4d4b6ca46ff3cc857671 /runtime/lua/vim/lsp.lua | |
parent | b5edea6553b4c1b5dd3530061d907848d7272d8c (diff) | |
download | rneovim-5e6a288ce7ee079e7695525f2e9e99d071ccdfbf.tar.gz rneovim-5e6a288ce7ee079e7695525f2e9e99d071ccdfbf.tar.bz2 rneovim-5e6a288ce7ee079e7695525f2e9e99d071ccdfbf.zip |
fix(lsp): followup fixes for semantic tokens support (#21357)
1. The algorithm for applying edits was slightly incorrect. It needs to
preserve the original token list as the edits are applied instead of
mutating it as it iterates. From the spec:
Semantic token edits behave conceptually like text edits on
documents: if an edit description consists of n edits all n edits are
based on the same state Sm of the number array. They will move the
number array from state Sm to Sm+1.
2. Schedule the semantic token engine start() call in the
client._on_attach() function so that users who schedule_wrap() their
config.on_attach() functions (like nvim-lspconfig does) can still
disable semantic tokens by deleting the semanticTokensProvider from
their server capabilities.
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 3d3c856fcb..f3ee484024 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -1531,9 +1531,14 @@ function lsp.start_client(config) pcall(config.on_attach, client, bufnr) end - if vim.tbl_get(client.server_capabilities, 'semanticTokensProvider', 'full') then - semantic_tokens.start(bufnr, client.id) - end + -- schedule the initialization of semantic tokens to give the above + -- on_attach and LspAttach callbacks the ability to schedule wrap the + -- opt-out (deleting the semanticTokensProvider from capabilities) + vim.schedule(function() + if vim.tbl_get(client.server_capabilities, 'semanticTokensProvider', 'full') then + semantic_tokens.start(bufnr, client.id) + end + end) client.attached_buffers[bufnr] = true end |