better ltex

This commit is contained in:
cscherr 2025-06-23 16:43:33 +02:00
parent 3dc92d1d5b
commit 505dd0dda0
Signed by: cscherrNT
GPG key ID: 8E2B45BC51A27EA7
2 changed files with 36 additions and 31 deletions

View file

@ -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', '<leader>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', '<leader>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', '<leader>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', '<leader>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

View file

@ -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,
}