return { "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { "hrsh7th/cmp-nvim-lsp", { "antosha417/nvim-lsp-file-operations", config = true }, { "folke/neodev.nvim", opts = {} }, }, config = function() -- Replace symbols to use for diagnostics vim.diagnostic.config({ signs = { text = { [vim.diagnostic.severity.ERROR] = " ", [vim.diagnostic.severity.WARN] = " ", [vim.diagnostic.severity.HINT] = "󰠠 ", [vim.diagnostic.severity.INFO] = " ", }, }, }) -- -- Create keymaps when using an LSP local keymap = vim.keymap vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("UserLspConfig", {}), callback = function(ev) local opts = { buffer = ev.buf, silent = true } opts.desc = "Show LSP references" keymap.set("n", "gR", "Telescope lsp_references", opts) -- show definition, references opts.desc = "Go to declaration" keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration opts.desc = "Show LSP definitions" keymap.set("n", "gd", "Telescope lsp_definitions", opts) -- show lsp definitions opts.desc = "Show LSP implementations" keymap.set("n", "gi", "Telescope lsp_implementations", opts) -- show lsp implementations opts.desc = "Show LSP type definitions" keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) -- show lsp type definitions opts.desc = "See available code actions" keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection opts.desc = "Smart rename" keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- smart rename opts.desc = "Show buffer diagnostics" keymap.set("n", "D", "Telescope diagnostics bufnr=0", opts) -- show diagnostics for file opts.desc = "Show line diagnostics" keymap.set("n", "d", vim.diagnostic.open_float, opts) -- show diagnostics for line opts.desc = "Go to previous diagnostic" keymap.set("n", "[d", function() vim.diagnostic.jump({ count = -1, float = true }) end, opts) -- jump to previous diagnostic in buffer opts.desc = "Go to next diagnostic" keymap.set("n", "]d", function() vim.diagnostic.jump({ count = 1, float = true }) end, opts) -- jump to next diagnostic in buffer opts.desc = "Show documentation for what is under cursor" keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor opts.desc = "Restart LSP" keymap.set("n", "rs", ":LspRestart", opts) -- mapping to restart lsp if necessary end, }) -- Enable autocompletion capabilities local capabilities = require("cmp_nvim_lsp").default_capabilities() -- Configure for language servers -- lua_ls vim.lsp.config("lua_ls", { on_init = function(client) print(client.root_dir) if client.workspace_folders then local path = client.workspace_folders[1].name print(path) if path ~= vim.fn.stdpath("config") and (vim.uv.fs_stat(path .. "/.luarc.json") or vim.uv.fs_stat(path .. "/.luarc.jsonc")) then print(path) return end end client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, { runtime = { version = "LuaJIT", -- Tell the language server how to find Lua modules same way as Neovim -- (see `:h lua-module-load`) path = { "lua/?.lua", "lua/?/init.lua", }, }, -- Make the server aware of Neovim runtime files workspace = { checkThirdParty = false, library = { vim.env.VIMRUNTIME, "${3rd}/luv/library", }, }, -- Add the default completion capabilities capabilities = capabilities, }) end, settings = { Lua = {}, }, }) -- ts_ls vim.lsp.config("ts_ls", { on_attach = function(client) -- Disable formatting capability for tsserver client.server_capabilities.documentFormattingProvider = false client.server_capabilities.documentRangeFormattingProvider = false end, filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact", }, root_markers = { "tsconfig.json", "jsconfig.json", "package.json" }, }) vim.lsp.config("pylsp", { on_attach = function(client) client.server_capabilities.documentFormattingProvider = false client.server_capabilities.documentRangeFormattingProvider = false end, filetypes = { "python", }, root_markers = { "requirements.txt" }, }) end, }