From 7f510c5fa9808807672a1cd9af3d28649d85f9a1 Mon Sep 17 00:00:00 2001 From: Hawtian Wang Date: Mon, 22 Apr 2024 15:28:17 +0800 Subject: [PATCH] ... --- lua/dotvim/extra/lsp.lua | 13 +++++++++++++ lua/dotvim/pkgs/lsp/plugins/lspkind.lua | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/lua/dotvim/extra/lsp.lua b/lua/dotvim/extra/lsp.lua index 00d40028..454d1fcd 100644 --- a/lua/dotvim/extra/lsp.lua +++ b/lua/dotvim/extra/lsp.lua @@ -30,6 +30,19 @@ function M.get_lsp_item_import_location(completion, source) end return string.sub(import_str, i + 6, j - 1) + elseif source_name == "rust-analyzer" then + local imports = vim.tbl_get(completion, "data", "imports") + if imports == nil or type(imports) ~= "table" or #imports == 0 then + return + end + local import = imports[1] + local full_import_path = import.full_import_path + local imported_name = import.imported_name + local i, j = full_import_path:find("::" .. imported_name .. "$") + if i == nil then + return + end + return string.sub(full_import_path, 1, i - 1) end end diff --git a/lua/dotvim/pkgs/lsp/plugins/lspkind.lua b/lua/dotvim/pkgs/lsp/plugins/lspkind.lua index 1f274a18..0e8a7aad 100644 --- a/lua/dotvim/pkgs/lsp/plugins/lspkind.lua +++ b/lua/dotvim/pkgs/lsp/plugins/lspkind.lua @@ -1,4 +1,5 @@ local MAX_MENU_WIDTH = 20 +local MIN_ABBR_WIDTH = 25 ---@type dotvim.core.plugin.PluginOption return { @@ -36,6 +37,10 @@ return { local strings = vim.split(ret.kind, "%s", { trimempty = true }) ret.kind = strings[1] .. " " + if #ret.abbr < MIN_ABBR_WIDTH then + ret.abbr = ret.abbr .. string.rep(" ", MIN_ABBR_WIDTH - #ret.abbr) + end + local menu_text = vim.F.if_nil( require("dotvim.extra.lsp").get_lsp_item_import_location( entry.completion_item,