fix(nvim): improve statusline handling of lsp servers
Some lsp servers don't return a list/blob of filetypes, but only a single string filetype which causes some issues when indexing. This fixes those edge cases
This commit is contained in:
parent
dc77098877
commit
e29608a3f4
@ -41,25 +41,30 @@ end
|
|||||||
|
|
||||||
local show_lsp_name = {
|
local show_lsp_name = {
|
||||||
function()
|
function()
|
||||||
local msg = "No Active Lsp"
|
local buf_ft = vim.api.nvim_get_option_value("filetype", { scope = "local" })
|
||||||
local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
|
|
||||||
local clients = vim.lsp.get_active_clients()
|
local clients = vim.lsp.get_active_clients()
|
||||||
if next(clients) == nil then
|
if next(clients) == nil then
|
||||||
return msg
|
return "No Active Lsp"
|
||||||
else
|
else
|
||||||
msg = ""
|
local msg = nil
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
local filetypes = client.config.filetypes
|
local filetypes = client.config.filetypes
|
||||||
|
-- Prep filetypes for indexing, some language servers only register with a single filetype so we need to
|
||||||
|
-- convert them into a blob so vim.fn.index doesn't throw a fit
|
||||||
|
if type(filetypes) == "string" then
|
||||||
|
filetypes = { filetypes }
|
||||||
|
end
|
||||||
|
|
||||||
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
|
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
|
||||||
if msg == "" then
|
if not msg then
|
||||||
msg = client.name
|
msg = client.name
|
||||||
else
|
else
|
||||||
msg = msg .. ", " .. client.name
|
msg = msg .. ", " .. client.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return msg
|
||||||
end
|
end
|
||||||
return msg
|
|
||||||
end,
|
end,
|
||||||
icon = " LSP:",
|
icon = " LSP:",
|
||||||
color = { fg = "#957fb8" },
|
color = { fg = "#957fb8" },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user