Skip to content

Commit

Permalink
fix: hide copilot and null-ls on lsp server name
Browse files Browse the repository at this point in the history
  • Loading branch information
zztrieuzz committed Sep 24, 2022
1 parent da7fd52 commit 0a6a0b4
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions lua/windline/components/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local M = {}

local windline = require('windline')
local cache_utils = require('windline.cache_utils')
local utils = require('windline.utils')
local state = windline.state

local get_diagnostics_count = function(bufnr)
Expand All @@ -17,44 +18,42 @@ local get_diagnostics_count = function(bufnr)
count[vim.diagnostic.severity.HINT]
end


local function is_lsp(bufnr)
return next(vim.lsp.get_active_clients({ bufnr = bufnr or vim.api.nvim_get_current_buf() })) ~= nil
local get_lsp_client = nil
if vim.fn.has('nvim-0.8') > 0 then
get_lsp_client = function(bufnr)
return vim.lsp.get_active_clients({
bufnr = bufnr or vim.api.nvim_get_current_buf()
})
end
else
get_lsp_client = vim.lsp.buf_get_clients
end

local lsp_client_names = function(bufnr, opt)
local function is_lsp(bufnr, opt)
opt = opt or {}
local hide_server_names = opt.hide_server_names or { 'copilot' }
local clients = {}
local icon = opt.icon or ''
local sep = opt.separator or '|'

for _, client in pairs(vim.lsp.get_active_clients({ bufnr = bufnr or vim.api.nvim_get_current_buf() })) do
clients[#clients + 1] = client.name
end
if next(clients) then
return icon .. table.concat(clients, sep)
for _, client in pairs(get_lsp_client(bufnr)) do
if not utils.is_in_table(hide_server_names, client.name) then
clients[#clients + 1] = client.name
end
end
return nil
return next(clients) ~= nil
end

M.check_custom_lsp = function(opt)
opt = opt or {}
local lsp_check = opt.func_check or is_lsp

return function(bufnr)
if state.comp.lsp == nil and lsp_check(bufnr) then
return function(bufnr, config)
if state.comp.lsp == nil and lsp_check(bufnr, config) then
local error, warning, information, hint = get_diagnostics_count(bufnr)
state.comp.lsp_error = error
state.comp.lsp_warning = warning
state.comp.lsp_information = information
state.comp.lsp_hint = hint
-- save lsp_name on buffer variable

if error > 0 or warning > 0 then
state.comp.lsp = 1
else
state.comp.lsp = 2
end
state.comp.lsp = 1
end
return state.comp.lsp ~= nil
end
Expand All @@ -63,6 +62,24 @@ end
-- it make sure we only call the diagnostic 1 time on render function
M.check_lsp = M.check_custom_lsp()

local lsp_client_names = function(bufnr, opt)
opt = opt or {}
local clients = {}
local icon = opt.icon or ''
local sep = opt.separator or '|'
local hide_server_names = opt.hide_server_names or { 'null-ls', 'copilot' }

for _, client in pairs(get_lsp_client(bufnr)) do
if not utils.is_in_table(hide_server_names, client.name) then
clients[#clients + 1] = client.name
end
end
if next(clients) then
return icon .. table.concat(clients, sep)
end
return nil
end

M.lsp_name = function(opt)
return cache_utils.cache_on_buffer('BufEnter', 'lsp_server_name', function(bufnr)
local lsp_name = lsp_client_names(bufnr, opt)
Expand Down

0 comments on commit 0a6a0b4

Please sign in to comment.