mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
refactor: tabnine
This commit is contained in:
parent
be92041084
commit
c810074a48
3 changed files with 9 additions and 56 deletions
|
|
@ -84,6 +84,7 @@ local defaults = {
|
||||||
Snippet = " ",
|
Snippet = " ",
|
||||||
String = " ",
|
String = " ",
|
||||||
Struct = " ",
|
Struct = " ",
|
||||||
|
TabNine = " ",
|
||||||
Text = " ",
|
Text = " ",
|
||||||
TypeParameter = " ",
|
TypeParameter = " ",
|
||||||
Unit = " ",
|
Unit = " ",
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ return {
|
||||||
local icons = require("lazyvim.config").icons.kinds
|
local icons = require("lazyvim.config").icons.kinds
|
||||||
if icons[item.kind] then
|
if icons[item.kind] then
|
||||||
item.kind = icons[item.kind] .. item.kind
|
item.kind = icons[item.kind] .. item.kind
|
||||||
|
item.menu = ""
|
||||||
end
|
end
|
||||||
return item
|
return item
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
-- TODO: add TabNine icon if is available
|
local Util = require("lazyvim.util")
|
||||||
local tabnine_icon = ""
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
-- Tabnine cmp source
|
-- Tabnine cmp source
|
||||||
|
|
@ -30,25 +29,12 @@ return {
|
||||||
priority = 100,
|
priority = 100,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Format the completion menu, remove the percentage and add icons
|
opts.formatting.format = Util.inject.args(opts.formatting.format, function(entry, item)
|
||||||
opts.formatting.format = function(entry, vim_item)
|
-- Hide percentage in the menu
|
||||||
local icons = require("lazyvim.config").icons.kinds
|
|
||||||
if icons[vim_item.kind] then
|
|
||||||
vim_item.kind = icons[vim_item.kind] .. vim_item.kind
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add tabnine icon and hide percentage in the menu
|
|
||||||
if entry.source.name == "cmp_tabnine" then
|
if entry.source.name == "cmp_tabnine" then
|
||||||
vim_item.kind = tabnine_icon .. " TabNine"
|
item.menu = ""
|
||||||
vim_item.menu = ""
|
|
||||||
|
|
||||||
if (entry.completion_item.data or {}).multiline then
|
|
||||||
vim_item.kind = vim_item.kind .. " " .. "[ML]"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
return vim_item
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- Show TabNine status in lualine
|
-- Show TabNine status in lualine
|
||||||
|
|
@ -57,43 +43,8 @@ return {
|
||||||
optional = true,
|
optional = true,
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
local started = false
|
local icon = require("lazyvim.config").icons.kinds.TabNine
|
||||||
local function status()
|
table.insert(opts.sections.lualine_x, 2, require("lazyvim.util").lualine.cmp_source("cmp_tabnine", icon))
|
||||||
if not package.loaded["cmp"] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for _, s in ipairs(require("cmp").core.sources) do
|
|
||||||
if s.name == "cmp_tabnine" then
|
|
||||||
if s.source:is_available() then
|
|
||||||
started = true
|
|
||||||
else
|
|
||||||
return started and "error" or nil
|
|
||||||
end
|
|
||||||
if s.status == s.SourceStatus.FETCHING then
|
|
||||||
return "pending"
|
|
||||||
end
|
|
||||||
return "ok"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local Util = require("lazyvim.util")
|
|
||||||
local colors = {
|
|
||||||
ok = Util.ui.fg("Special"),
|
|
||||||
error = Util.ui.fg("DiagnosticError"),
|
|
||||||
pending = Util.ui.fg("DiagnosticWarn"),
|
|
||||||
}
|
|
||||||
table.insert(opts.sections.lualine_x, 3, {
|
|
||||||
function()
|
|
||||||
return tabnine_icon
|
|
||||||
end,
|
|
||||||
cond = function()
|
|
||||||
return status() ~= nil
|
|
||||||
end,
|
|
||||||
color = function()
|
|
||||||
return colors[status()] or colors.ok
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue