aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/semantic_tokens.lua
diff options
context:
space:
mode:
authorjdrouhard <john@drouhard.dev>2022-12-09 04:54:09 -0600
committerGitHub <noreply@github.com>2022-12-09 11:54:09 +0100
commit5e6a288ce7ee079e7695525f2e9e99d071ccdfbf (patch)
tree723adee97dc5dcf22f1c4d4b6ca46ff3cc857671 /runtime/lua/vim/lsp/semantic_tokens.lua
parentb5edea6553b4c1b5dd3530061d907848d7272d8c (diff)
downloadrneovim-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/semantic_tokens.lua')
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua17
1 files changed, 7 insertions, 10 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua
index 99cdc20f54..66e656abb6 100644
--- a/runtime/lua/vim/lsp/semantic_tokens.lua
+++ b/runtime/lua/vim/lsp/semantic_tokens.lua
@@ -313,18 +313,15 @@ function STHighlighter:process_response(response, client, version)
return a.start < b.start
end)
- ---@private
- local function _splice(list, start, remove_count, data)
- local ret = vim.list_slice(list, 1, start)
- vim.list_extend(ret, data)
- vim.list_extend(ret, list, start + remove_count + 1)
- return ret
- end
-
- tokens = state.current_result.tokens
+ tokens = {}
+ local old_tokens = state.current_result.tokens
+ local idx = 1
for _, token_edit in ipairs(token_edits) do
- tokens = _splice(tokens, token_edit.start, token_edit.deleteCount, token_edit.data)
+ vim.list_extend(tokens, old_tokens, idx, token_edit.start)
+ vim.list_extend(tokens, token_edit.data)
+ idx = token_edit.start + token_edit.deleteCount + 1
end
+ vim.list_extend(tokens, old_tokens, idx)
else
tokens = response.data
end