feat(nvim): add lsp name to cmp menu
This commit is contained in:
parent
57ea529b3f
commit
55dd3b27c3
@ -145,7 +145,6 @@ return {
|
|||||||
---@param entry cmp.Entry
|
---@param entry cmp.Entry
|
||||||
---@param vim_item vim.CompletedItem
|
---@param vim_item vim.CompletedItem
|
||||||
format = function(entry, vim_item)
|
format = function(entry, vim_item)
|
||||||
-- vim.notify(vim.inspect(entry))
|
|
||||||
local selections = {
|
local selections = {
|
||||||
["vim-dadbod-completion"] = { symbol = " ", name = "DB", hl_group = "DadbodCompletion" },
|
["vim-dadbod-completion"] = { symbol = " ", name = "DB", hl_group = "DadbodCompletion" },
|
||||||
calc = { symbol = " ", name = "Calculator", hl_group = "Calculator" },
|
calc = { symbol = " ", name = "Calculator", hl_group = "Calculator" },
|
||||||
@ -167,16 +166,19 @@ return {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local selection
|
local selection
|
||||||
|
local lsp_name
|
||||||
if entry.source.name == "nvim_lsp" then
|
if entry.source.name == "nvim_lsp" then
|
||||||
-- vim.notify(vim.inspect(entry.source.source))
|
lsp_name = entry.source.source.client.name
|
||||||
selection = selections[entry.source.source.client.name]
|
selection = selections[lsp_name]
|
||||||
else
|
else
|
||||||
selection = selections[entry.source.name]
|
selection = selections[entry.source.name]
|
||||||
end
|
end
|
||||||
|
local completion_item = vim_item
|
||||||
|
local abbr_max_width = 50
|
||||||
if not selection then
|
if not selection then
|
||||||
local kind = require("lspkind").cmp_format({
|
local kind = require("lspkind").cmp_format({
|
||||||
mode = "symbol_text",
|
mode = "symbol_text",
|
||||||
maxwidth = 50,
|
maxwidth = abbr_max_width,
|
||||||
})(entry, vim_item)
|
})(entry, vim_item)
|
||||||
if string.match(kind.kind, ".* Color$") or string.match(kind.kind, ".* Variable$") then
|
if string.match(kind.kind, ".* Color$") or string.match(kind.kind, ".* Variable$") then
|
||||||
---@type string
|
---@type string
|
||||||
@ -234,24 +236,30 @@ return {
|
|||||||
strings[1] = extra_kind_icons[strings[1]] or ""
|
strings[1] = extra_kind_icons[strings[1]] or ""
|
||||||
end
|
end
|
||||||
kind.kind = " " .. strings[1] .. " "
|
kind.kind = " " .. strings[1] .. " "
|
||||||
|
if not kind.menu and lsp_name then
|
||||||
|
kind.menu = " " .. lsp_name
|
||||||
|
end
|
||||||
|
|
||||||
return kind
|
completion_item = kind
|
||||||
else
|
else
|
||||||
|
completion_item.kind = " " .. selection.symbol
|
||||||
|
completion_item.menu = selection.symbol .. selection.name
|
||||||
|
completion_item.kind_hl_group = "CmpCustomSelection" .. selection.hl_group
|
||||||
|
end
|
||||||
|
|
||||||
|
if not completion_item.abbr then
|
||||||
local word = entry:get_insert_text()
|
local word = entry:get_insert_text()
|
||||||
word = str.oneline(word)
|
word = str.oneline(word)
|
||||||
|
completion_item.abbr = word
|
||||||
-- concatenates the string
|
|
||||||
local max = 50
|
|
||||||
if string.len(word) >= max then
|
|
||||||
local before = string.sub(word, 1, math.floor((max - 3) / 2))
|
|
||||||
word = before .. "..."
|
|
||||||
end
|
|
||||||
vim_item.kind = " " .. selection.symbol
|
|
||||||
vim_item.menu = selection.symbol .. selection.name
|
|
||||||
vim_item.kind_hl_group = "CmpCustomSelection" .. selection.hl_group
|
|
||||||
vim_item.abbr = word
|
|
||||||
return vim_item
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if string.len(completion_item.abbr) >= abbr_max_width then
|
||||||
|
local before = string.sub(completion_item.abbr, 1, math.floor((abbr_max_width - 3) / 2))
|
||||||
|
completion_item.abbr = before .. "..."
|
||||||
|
end
|
||||||
|
|
||||||
|
-- concatenates the string
|
||||||
|
return completion_item
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
view = {
|
view = {
|
||||||
|
Loading…
Reference in New Issue
Block a user