Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
TwIStOy committed Apr 22, 2024
1 parent 8c79c8d commit 6a6b74e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 20 deletions.
3 changes: 3 additions & 0 deletions lua/dotvim/extra/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ M.obsidian = require("dotvim.extra.obsidian")
---@type dotvim.extra.ui
M.ui = require("dotvim.extra.ui")

---@type dotvim.extra.lsp
local Lsp = require("dotvim.extra.lsp")

return M
36 changes: 36 additions & 0 deletions lua/dotvim/extra/lsp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---@class dotvim.extra.lsp
local M = {}

-- thanks to https://www.reddit.com/r/neovim/comments/1c9q60s/tip_cmp_menu_with_rightaligned_import_location/
function M.get_lsp_item_import_location(completion, source)
local ok, source_name = pcall(function()
return source.source.client.config.name
end)
if not ok then
return nil
end

if source_name == "tsserver" then
return completion.detail
elseif source_name == "pyright" and completion.labelDetails ~= nil then
return completion.labelDetails.description
elseif source_name == "texlab" then
return completion.detail
elseif source_name == "clangd" then
local doc = completion.documentation
if doc == nil then
return
end

local import_str = doc.value

local i, j = string.find(import_str, 'From `["<].*[">]`')
if i == nil then
return
end

return string.sub(import_str, i + 6, j - 1)
end
end

return M
34 changes: 14 additions & 20 deletions lua/dotvim/pkgs/lsp/plugins/lspkind.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local MAX_MENU_WIDTH = 20

---@type dotvim.core.plugin.PluginOption
return {
"onsails/lspkind.nvim",
Expand Down Expand Up @@ -25,22 +27,6 @@ return {
ellipsis_char = "...",
show_labelDetails = true,
before = function(e, item)
item.menu = ({
buffer = "[Buf]",
nvim_lsp = "[LSP]",
ultisnips = "[Snip]",
luasnip = "[Snip]",
nvim_lua = "[Lua]",
orgmode = "[Org]",
path = "[Path]",
dap = "[DAP]",
emoji = "[Emoji]",
calc = "[CALC]",
latex_symbols = "[LaTeX]",
cmdline_history = "[History]",
cmdline = "[Command]",
copilot = "[Copilot]",
})[e.source.name] or ("[" .. e.source.name .. "]")
if e.source.name == "latex_symbols" then
item.kind = "Math"
end
Expand All @@ -49,11 +35,19 @@ return {
}(entry, vim_item)
local strings = vim.split(ret.kind, "%s", { trimempty = true })
ret.kind = strings[1] .. " "
if strings[2] and #strings[2] > 0 then
ret.menu = " (" .. strings[2] .. ")"
else
ret.menu = ""

local menu_text = vim.F.if_nil(
require("dotvim.extra.lsp").get_lsp_item_import_location(
entry.completion_item,
entry.source
),
""
)
if #menu_text > MAX_MENU_WIDTH then
menu_text = menu_text:sub(1, MAX_MENU_WIDTH - 3) .. "..."
end
ret.menu = menu_text

return ret
end,
}
Expand Down
2 changes: 2 additions & 0 deletions lua/dotvim/pkgs/theme/plugins/catppuccin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ return {
},
["@variable.builtin"] = { fg = colors.maroon, style = { "italic" } },

CmpItemMenu = { link = "@comment" },

CurSearch = { bg = colors.sky },
IncSearch = { bg = colors.sky },
CursorLineNr = { fg = colors.blue, style = { "bold" } },
Expand Down

0 comments on commit 6a6b74e

Please sign in to comment.