aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/completion.lua
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2026-07-28 20:39:03 +0800
committerGitHub <noreply@github.com>2026-07-28 08:39:03 -0400
commit3fa5904cf246b783db778a457e5544272b847eff (patch)
treef0745678afcd4e66519e1e87fa3d9f07f27d8bdb /runtime/lua/vim/lsp/completion.lua
parent089c415cb236512add6c29372e26640ff401d39b (diff)
downloadrneovim-3fa5904cf246b783db778a457e5544272b847eff.tar.gz
rneovim-3fa5904cf246b783db778a457e5544272b847eff.tar.bz2
rneovim-3fa5904cf246b783db778a457e5544272b847eff.zip
fix(lsp): multibyte fragment treated as commit char #41019
Problem: commit_chars_str() reads a 0x80-0xBF byte as a 2-byte lead, so "\xA9x" makes "x" a commit character. nvim_get_hl() returns a dict, so `#` on it is 0 whether or not the group exists Solution: use vim.str_utf_end() and drop entries that are not one whole character. use next check dict length.
Diffstat (limited to 'runtime/lua/vim/lsp/completion.lua')
-rw-r--r--runtime/lua/vim/lsp/completion.lua11
1 files changed, 7 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua
index ee13c915d9..3b2724b170 100644
--- a/runtime/lua/vim/lsp/completion.lua
+++ b/runtime/lua/vim/lsp/completion.lua
@@ -377,7 +377,7 @@ local function generate_kind(item)
hex = hex:lower()
local group = ('@lsp.color.%s'):format(hex)
- if #api.nvim_get_hl(0, { name = group }) == 0 then
+ if next(api.nvim_get_hl(0, { name = group })) == nil then
api.nvim_set_hl(0, group, { fg = '#' .. hex })
end
@@ -435,9 +435,12 @@ local function commit_chars_str(chars)
-- commit characters "should have `length=1`" and superfluous
-- characters are ignored. Keep the first codepoint.
local b = type(ch) == 'string' and ch:byte(1)
- if b then
- local len = b < 0x80 and 1 or b < 0xe0 and 2 or b < 0xf0 and 3 or 4
- result[#result + 1] = ch:sub(1, len)
+ if b and b ~= 0 then
+ local n = vim.str_utf_end(ch, 1)
+ -- Only whole characters: multibyte fragments pair up across entries, NUL truncates.
+ if b < 0x80 or n > 0 then
+ result[#result + 1] = ch:sub(1, 1 + n)
+ end
end
end
return table.concat(result)