diff --git a/lua/custom/plugins/configs/lsp.lua b/lua/custom/plugins/configs/lsp.lua index 3d6622e..4b874ce 100644 --- a/lua/custom/plugins/configs/lsp.lua +++ b/lua/custom/plugins/configs/lsp.lua @@ -115,8 +115,27 @@ vim.api.nvim_create_autocmd('LspAttach', { -- By default, Neovim doesn't support everything that is in the LSP specification. -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities. -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers. -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) +CAPABILITIES = vim.lsp.protocol.make_client_capabilities() +CAPABILITIES = vim.tbl_deep_extend('force', CAPABILITIES, require('cmp_nvim_lsp').default_capabilities()) + +DEFAULT_ON_ATTACH = function(client, bufnr) + vim.keymap.set('n', 'tp', function() + print('pinning this file: ', vim.api.nvim_buf_get_name(0), 'bufnr: ', bufnr) + client:exec_cmd({ + title = 'pin', + command = 'tinymist.pinMain', + arguments = { vim.api.nvim_buf_get_name(0) }, + }, { bufnr = bufnr }) + end, { desc = '[T]oggle [P]in (pin this file as main file)', noremap = true }) + + vim.keymap.set('n', 'tu', function() + client:exec_cmd({ + title = 'unpin', + command = 'tinymist.pinMain', + arguments = { vim.v.null }, + }, { bufnr = bufnr }) + end, { desc = '[T]oggle [U]npin (unpin this file as main file)', noremap = true }) +end -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. @@ -134,24 +153,7 @@ local servers = { exportPdf = 'never', semanticTokens = 'disable', }, - on_attach = function(client, bufnr) - vim.keymap.set('n', 'tp', function() - print('pinning this file: ', vim.api.nvim_buf_get_name(0), 'bufnr: ', bufnr) - client:exec_cmd({ - title = 'pin', - command = 'tinymist.pinMain', - arguments = { vim.api.nvim_buf_get_name(0) }, - }, { bufnr = bufnr }) - end, { desc = '[T]oggle [P]in (pin this file as main file)', noremap = true }) - - vim.keymap.set('n', 'tu', function() - client:exec_cmd({ - title = 'unpin', - command = 'tinymist.pinMain', - arguments = { vim.v.null }, - }, { bufnr = bufnr }) - end, { desc = '[T]oggle [U]npin (unpin this file as main file)', noremap = true }) - end, + on_attach = DEFAULT_ON_ATTACH, }, html = {}, taplo = {}, @@ -195,7 +197,6 @@ local servers = { }, }, }, - ltex_plus = LTEX_SETTINGS, } -- Ensure the servers and tools above are installed @@ -224,7 +225,7 @@ for server_name, server in pairs(servers) do -- This handles overriding only values explicitly passed -- by the server configuration above. Useful when disabling -- certain features of an LSP (for example, turning off formatting for tsserver) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + server.capabilities = vim.tbl_deep_extend('force', {}, CAPABILITIES, server.capabilities or {}) require('lspconfig')[server_name].setup(server) end diff --git a/lua/custom/plugins/ltex.lua b/lua/custom/plugins/ltex.lua index eecb691..a2574fd 100644 --- a/lua/custom/plugins/ltex.lua +++ b/lua/custom/plugins/ltex.lua @@ -28,6 +28,10 @@ local ltex_fts = { } LTEX_SETTINGS = { + capabilities = CAPABILITIES, + on_attach = function(client, bufnr) + DEFAULT_ON_ATTACH(client, bufnr) + end, use_spellfile = true, autostart = false, filetypes = ltex_fts, @@ -73,13 +77,13 @@ else end return { - { - 'vigoux/ltex-ls.nvim', - enabled = false, - requires = 'neovim/nvim-lspconfig', - filetypes = { 'latex', 'tex', 'bib', 'markdown', 'gitcommit', 'text', 'typst' }, - config = function() - require('ltex-ls').setup { LTEX_SETTINGS } - end, - }, + 'barreiroleo/ltex_extra.nvim', + ft = { 'markdown', 'tex' }, + dependencies = { 'neovim/nvim-lspconfig' }, + -- yes, you can use the opts field, just I'm showing the setup explicitly + config = function() + require('ltex_extra').setup { + server_opts = LTEX_SETTINGS, + } + end, }