diff --git a/lua/cosmic/lsp/commands.lua b/lua/cosmic/lsp/commands.lua deleted file mode 100644 index ed43ebf..0000000 --- a/lua/cosmic/lsp/commands.lua +++ /dev/null @@ -1,28 +0,0 @@ -local augroup_name = 'CosmicNvimLspFormat' -local group = vim.api.nvim_create_augroup(augroup_name, { clear = true }) -local user_config = require('cosmic.core.user') - -if user_config.lsp.format_on_save then - local format_filetypes = '' - if vim.tbl_islist(user_config.lsp.format_on_save) then - for _, ft in pairs(user_config.lsp.format_on_save) do - format_filetypes = format_filetypes .. '*' .. ft - end - else - format_filetypes = '*' - end - - vim.api.nvim_create_autocmd(string.format('BufWritePre %s', format_filetypes), { - callback = function() - vim.lsp.buf.format({ - timeout_ms = user_config.lsp.format_timeout, - -- check user config to see if we can format on save - filter = function(client) - return user_config.lsp.can_client_format(client.name) - end, - }) - end, - group = group, - nested = true, - }) -end diff --git a/lua/cosmic/lsp/init.lua b/lua/cosmic/lsp/init.lua index f990387..92f7ba0 100644 --- a/lua/cosmic/lsp/init.lua +++ b/lua/cosmic/lsp/init.lua @@ -1,11 +1,3 @@ require('cosmic.lsp.diagnostics') -require('cosmic.lsp.commands') --- handled via noice ---[[ vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { ]] ---[[ border = user_config.border, ]] ---[[ }) ]] ---[[]] ---[[ vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { ]] ---[[ border = user_config.border, ]] ---[[ }) ]] +-- LSP server initialization can be found in mason-lspconfig setup diff --git a/lua/cosmic/lsp/providers/defaults.lua b/lua/cosmic/lsp/providers/defaults.lua index 81bb3ab..4cb5aee 100644 --- a/lua/cosmic/lsp/providers/defaults.lua +++ b/lua/cosmic/lsp/providers/defaults.lua @@ -16,15 +16,15 @@ function M.on_attach(client, bufnr) -- set up :LspFormat for clients that are capable vim.cmd(string.format("command! LspFormat lua require('cosmic.utils.lsp').format(%s)", bufnr)) + -- set up auto format on save if user_config.lsp.format_on_save then - -- collect filetype(s) + -- collect filetype(s) from user config local format_filetypes = '' if vim.tbl_islist(user_config.lsp.format_on_save) then for _, ft in pairs(user_config.lsp.format_on_save) do format_filetypes = format_filetypes .. '*' .. ft end - else - -- any filetype + else -- any filetype if none set format_filetypes = '*' end diff --git a/lua/cosmic/utils/lsp.lua b/lua/cosmic/utils/lsp.lua index d65f0d6..3ecdac4 100644 --- a/lua/cosmic/utils/lsp.lua +++ b/lua/cosmic/utils/lsp.lua @@ -1,5 +1,18 @@ +local user_config = require('cosmic.core.user') local M = {} +-- format current buffer w/user settings +function M.format(bufnr) + vim.lsp.buf.format({ + timeout_ms = user_config.lsp.format_timeout, + -- check user config to see if we can format on save + filter = function(client) + return user_config.lsp.can_client_format(client) + end, + bufnr = bufnr or 0, + }) +end + function M.get_active_lsp_client_names() local active_clients = vim.lsp.get_active_clients() local client_names = {}