feat: clean up

This commit is contained in:
Matthew Leong 2024-06-08 19:50:51 -07:00
parent 11e7a914cb
commit 359e38969d
3 changed files with 27 additions and 27 deletions

View file

@ -21,12 +21,13 @@ function M.on_attach(client, bufnr)
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
end
if client.supports_method('textDocument/formatting') and can_format_on_save(client) then
if client.supports_method('textDocument/formatting') then
-- set up :LspFormat for clients that are capable
vim.cmd(
string.format("command! -nargs=? LspFormat lua require('cosmic.utils.lsp').force_format(%s, <q-args>)", bufnr)
)
if can_format_on_save(client) then
-- set up auto format on save
vim.api.nvim_clear_autocmds({
group = M.group,
@ -40,6 +41,7 @@ function M.on_attach(client, bufnr)
group = M.group,
})
end
end
-- set up default mappings
require('cosmic.lsp.mappings').init(client, bufnr)

View file

@ -56,7 +56,7 @@ return {
custom_sections.diff,
},
lualine_x = { 'diagnostics' },
lualine_y = { lsp_utils.get_active_clients_str },
lualine_y = { lsp_utils.buf_get_active_clients_str },
lualine_z = { 'location', 'progress' },
},
inactive_sections = {

View file

@ -58,16 +58,14 @@ function M.format(bufnr, timeout)
})
end
function M.get_active_lsp_clients()
local active_clients = vim.lsp.get_clients()
function M.buf_get_active_client_names(bufnr)
local active_clients = vim.lsp.get_clients({
bufnr = bufnr or vim.api.nvim_get_current_buf(),
})
local client_names = {}
for _, client in pairs(active_clients or {}) do
local buf = vim.api.nvim_get_current_buf()
-- only return attached buffers
if vim.lsp.buf_is_attached(buf, client.id) then
table.insert(client_names, client.name)
end
end
if not vim.tbl_isempty(client_names) then
table.sort(client_names)
@ -75,17 +73,17 @@ function M.get_active_lsp_clients()
return client_names
end
function M.get_active_clients_str()
local clients = M.get_active_lsp_clients()
function M.buf_get_active_clients_str()
local client_names = M.buf_get_active_client_names()
local client_str = ''
if #clients < 1 then
if #client_names < 1 then
return
end
for i, client in ipairs(clients) do
client_str = client_str .. client
if i < #clients then
for i, client_name in ipairs(client_names) do
client_str = client_str .. client_name
if i < #client_names then
client_str = client_str .. ', '
end
end