146 lines
4.9 KiB
Lua
146 lines
4.9 KiB
Lua
local utils = require("utils")
|
|
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] = " ",
|
|
},
|
|
},
|
|
})
|
|
--
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
|
callback = function(ev)
|
|
local opts = { buffer = ev.buf, silent = true }
|
|
local telescope = require("telescope.builtin")
|
|
|
|
utils.nmapkey("gR", telescope.lsp_references, "Show LSP references", opts) -- show definition, references
|
|
utils.nmapkey("gD", vim.lsp.buf.declaration, "Go to declaration", opts) -- go to declaration
|
|
utils.nmapkey("K", vim.lsp.buf.hover, "Show documentation for what is under cursor", opts) -- show documentation for what is under cursor
|
|
utils.nmapkey("gd", telescope.lsp_definitions, "Show LSP definitions", opts)
|
|
utils.nmapkey("gi", telescope.lsp_implementations, "Show LSP implementations", opts)
|
|
utils.nmapkey("gt", telescope.lsp_type_definitions, "Show LSP type definitions", opts)
|
|
utils.mapkey({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, "See available code actions", opts) -- see available code actions
|
|
utils.nmapkey("<leader>rn", vim.lsp.buf.rename, "Smart rename", opts) -- smart rename
|
|
utils.nmapkey("<leader>D", telescope.diagnostics, "Show buffer diagnostics", opts) -- show diagnostics for file
|
|
utils.nmapkey("<leader>d", vim.diagnostic.open_float, "Show line diagnostics", opts) -- show diagnostics for line
|
|
utils.nmapkey("[d", function()
|
|
vim.diagnostic.jump({ count = -1, float = true })
|
|
end, "Go to previous diagnostic", opts) -- jump to previous diagnostic in buffer
|
|
utils.nmapkey("]d", function()
|
|
vim.diagnostic.jump({ count = 1, float = true })
|
|
end, "Go to next diagnostic", opts) -- jump to next diagnostic in buffer
|
|
utils.nmapkey("<leader>rs", "<cmd>LspRestart<cr>", "Restart LSP", 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",
|
|
},
|
|
},
|
|
capabilities = capabilities,
|
|
})
|
|
end,
|
|
})
|
|
|
|
-- ts_ls
|
|
vim.lsp.config("ts_ls", {
|
|
on_attach = function(client)
|
|
-- Disable formatting capability for tsserver (see conform.lua and nvim-lint.lua)
|
|
client.server_capabilities.documentFormattingProvider = false
|
|
client.server_capabilities.documentRangeFormattingProvider = false
|
|
end,
|
|
filetypes = {
|
|
"javascript",
|
|
"javascriptreact",
|
|
"typescript",
|
|
"typescriptreact",
|
|
},
|
|
root_markers = { "tsconfig.json", "jsconfig.json", "package.json" },
|
|
capabilities = capabilities,
|
|
})
|
|
|
|
vim.lsp.config("jsonls", {
|
|
on_attach = function(client)
|
|
-- Disable formatting capability for tsserver
|
|
client.server_capabilities.documentFormattingProvider = false
|
|
client.server_capabilities.documentRangeFormattingProvider = false
|
|
end,
|
|
filetypes = {
|
|
"json",
|
|
},
|
|
capabilities = capabilities,
|
|
})
|
|
|
|
vim.lsp.config("pylsp", {
|
|
settings = { pylsp = { plugins = { pycodestyle = { enabled = false } } } },
|
|
on_attach = function(client)
|
|
client.server_capabilities.documentFormattingProvider = false
|
|
client.server_capabilities.documentRangeFormattingProvider = false
|
|
end,
|
|
filetypes = {
|
|
"python",
|
|
},
|
|
root_markers = { "requirements.txt" },
|
|
capabilities = capabilities,
|
|
})
|
|
|
|
vim.lsp.config("bashls", {
|
|
on_attach = function(client)
|
|
client.server_capabilities.documentFormattingProvider = false
|
|
client.server_capabilities.documentRangeFormattingProvider = false
|
|
end,
|
|
filetypes = {
|
|
"sh",
|
|
},
|
|
capabilities = capabilities,
|
|
})
|
|
end,
|
|
}
|