feat: clean up
This commit is contained in:
parent
11e7a914cb
commit
359e38969d
3 changed files with 27 additions and 27 deletions
|
@ -21,24 +21,26 @@ function M.on_attach(client, bufnr)
|
||||||
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
|
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
|
||||||
end
|
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
|
-- set up :LspFormat for clients that are capable
|
||||||
vim.cmd(
|
vim.cmd(
|
||||||
string.format("command! -nargs=? LspFormat lua require('cosmic.utils.lsp').force_format(%s, <q-args>)", bufnr)
|
string.format("command! -nargs=? LspFormat lua require('cosmic.utils.lsp').force_format(%s, <q-args>)", bufnr)
|
||||||
)
|
)
|
||||||
|
|
||||||
-- set up auto format on save
|
if can_format_on_save(client) then
|
||||||
vim.api.nvim_clear_autocmds({
|
-- set up auto format on save
|
||||||
group = M.group,
|
vim.api.nvim_clear_autocmds({
|
||||||
buffer = bufnr,
|
group = M.group,
|
||||||
})
|
buffer = bufnr,
|
||||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
})
|
||||||
callback = function()
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||||
require('cosmic.utils.lsp').format(bufnr)
|
callback = function()
|
||||||
end,
|
require('cosmic.utils.lsp').format(bufnr)
|
||||||
buffer = bufnr,
|
end,
|
||||||
group = M.group,
|
buffer = bufnr,
|
||||||
})
|
group = M.group,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set up default mappings
|
-- set up default mappings
|
||||||
|
|
|
@ -56,7 +56,7 @@ return {
|
||||||
custom_sections.diff,
|
custom_sections.diff,
|
||||||
},
|
},
|
||||||
lualine_x = { 'diagnostics' },
|
lualine_x = { 'diagnostics' },
|
||||||
lualine_y = { lsp_utils.get_active_clients_str },
|
lualine_y = { lsp_utils.buf_get_active_clients_str },
|
||||||
lualine_z = { 'location', 'progress' },
|
lualine_z = { 'location', 'progress' },
|
||||||
},
|
},
|
||||||
inactive_sections = {
|
inactive_sections = {
|
||||||
|
|
|
@ -58,15 +58,13 @@ function M.format(bufnr, timeout)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_active_lsp_clients()
|
function M.buf_get_active_client_names(bufnr)
|
||||||
local active_clients = vim.lsp.get_clients()
|
local active_clients = vim.lsp.get_clients({
|
||||||
|
bufnr = bufnr or vim.api.nvim_get_current_buf(),
|
||||||
|
})
|
||||||
local client_names = {}
|
local client_names = {}
|
||||||
for _, client in pairs(active_clients or {}) do
|
for _, client in pairs(active_clients or {}) do
|
||||||
local buf = vim.api.nvim_get_current_buf()
|
table.insert(client_names, client.name)
|
||||||
-- only return attached buffers
|
|
||||||
if vim.lsp.buf_is_attached(buf, client.id) then
|
|
||||||
table.insert(client_names, client.name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not vim.tbl_isempty(client_names) then
|
if not vim.tbl_isempty(client_names) then
|
||||||
|
@ -75,17 +73,17 @@ function M.get_active_lsp_clients()
|
||||||
return client_names
|
return client_names
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_active_clients_str()
|
function M.buf_get_active_clients_str()
|
||||||
local clients = M.get_active_lsp_clients()
|
local client_names = M.buf_get_active_client_names()
|
||||||
local client_str = ''
|
local client_str = ''
|
||||||
|
|
||||||
if #clients < 1 then
|
if #client_names < 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, client in ipairs(clients) do
|
for i, client_name in ipairs(client_names) do
|
||||||
client_str = client_str .. client
|
client_str = client_str .. client_name
|
||||||
if i < #clients then
|
if i < #client_names then
|
||||||
client_str = client_str .. ', '
|
client_str = client_str .. ', '
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue