--[ -- Ensure that the LSP feature is up and runing. --] return { "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { "hrsh7th/cmp-nvim-lsp", "williamboman/mason-lspconfig.nvim", { "antosha417/nvim-lsp-file-operations", config = true }, { "folke/neodev.nvim", opts = {} }, }, config = function() local lspconfig = require("lspconfig") local mason_lspconfig = require("mason-lspconfig") local cmp_nvim_lsp = require("cmp_nvim_lsp") vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("UserLspConfig", {}), callback = function(ev) -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the functions below. -- Keybinds vim.keymap.set( "n", "gR", "Telescope lsp_references", { buffer = ev.buf, silent = true, desc = "Show LSP references" } ) vim.keymap.set( "n", "gD", vim.lsp.buf.declaration, { buffer = ev.buf, silent = true, desc = "Go to declaration" } ) vim.keymap.set( "n", "gd", "Telescope lsp_definitions", { buffer = ev.buf, silent = true, desc = "Show LSP definitions" } ) vim.keymap.set( "n", "gi", "Telescope lsp_implementations", { buffer = ev.buf, silent = true, desc = "Show LSP implementations" } ) vim.keymap.set( "n", "gt", "Telescope lsp_type_definitions", { buffer = ev.buf, silent = true, desc = "Show LSP type definitions" } ) vim.keymap.set( { "n", "v" }, "ca", vim.lsp.buf.code_action, { buffer = ev.buf, silent = true, desc = "See available code actions" } ) vim.keymap.set( "n", "rn", vim.lsp.buf.rename, { buffer = ev.buf, silent = true, desc = "Smart rename" } ) vim.keymap.set( "n", "D", "Telescope diagnostics bufnr=0", { buffer = ev.buf, silent = true, desc = "Show buffer diagnostics" } ) vim.keymap.set( "n", "d", vim.diagnostic.open_float, { buffer = ev.buf, silent = true, desc = "Show line diagnostics" } ) vim.keymap.set( "n", "d", vim.diagnostic.goto_next, { buffer = ev.buf, silent = true, desc = "Go to next diagnostic" } ) vim.keymap.set( "n", "K", vim.lsp.buf.hover, { buffer = ev.buf, silent = true, desc = "Show documentation for what is under the cursor" } ) vim.keymap.set( "n", "rs", "LspRestart", { buffer = ev.buf, silent = true, desc = "Restart LSP" } ) end, }) -- used to enable autocompletion (assign to every lsp server config) local capabilities = cmp_nvim_lsp.default_capabilities() -- Change the diagnostics symbols in the sign column (gutter) local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end mason_lspconfig.setup_handlers({ -- default handler for installed servers function(server_name) lspconfig[server_name].setup({ capabilities = capabilities, }) end, ["svelte"] = function() -- Configuration specific to svelte LSP server lspconfig["svelte"].setup({ capabilities = capabilities, on_attach = function(client, _) vim.api.nvim_create_autocmd("BufWritePost", { pattern = { "*.js", "*.ts" }, callback = function(ctx) -- Here use ctx.match instead of ctx.file client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match }) end, }) end, }) end, ["ltex"] = function() lspconfig["ltex"].setup({ filetypes = { "latex", "typst", "typ", "bib", "markdown", "plaintex", "tex" }, settings = { ltex = { enabled = { "latex", "typst", "typ", "bib", "markdown", "plaintex", "tex" }, language = { "en-GB", "fr-FR" }, setenceCacheSize = 2000, additionalRules = { enablePickyRules = true, motherTongue = "fr-FR", }, checkFrequency = "edit", }, }, }) end, ["lua_ls"] = function() lspconfig["lua_ls"].setup({ capabilities = capabilities, settings = { Lua = { -- make the language server recognize the "vim" global variable diagnostics = { globals = { "vim" }, }, completion = { callSnippet = "Replace", }, }, }, }) end, ["pyright"] = function() lspconfig["pyright"].setup({ capabilities = capabilities, settings = { python = { pythonPath = "/usr/bin/python", }, }, }) end, }) end, }