sauce-nvim-config/lua/themenacesauce/plugins/lsp/lspconfig.lua

205 lines
6.4 KiB
Lua

return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
"hrsh7th/cmp-nvim-lsp", { "antosha417/nvim-lsp-file-operations", config = true },
},
config = function()
-- NOTE: LSP Keybinds
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Buffer local mappings
local opts = { buffer = ev.buf, silent = true }
-- Keymaps
opts.desc = "Show LSP references"
vim.keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
opts.desc = "Go to declaration"
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
opts.desc = "Show LSP definitions"
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
opts.desc = "Show LSP implementations"
vim.keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
opts.desc = "Show LSP type definitions"
vim.keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
opts.desc = "See available code actions"
vim.keymap.set({ "n", "v" }, "<leader>vca", function()
vim.lsp.buf.code_action()
end, opts)
opts.desc = "Smart rename"
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
opts.desc = "Show buffer diagnostics"
vim.keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts)
opts.desc = "Show line diagnostics"
vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
opts.desc = "Show documentation for what is under cursor"
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
opts.desc = "Restart LSP"
vim.keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts)
vim.keymap.set("i", "<C-h>", function()
vim.lsp.buf.signature_help()
end, opts)
end,
})
-- Define sign icons for each severity
local signs = {
[vim.diagnostic.severity.ERROR] = "",
[vim.diagnostic.severity.WARN] = "",
[vim.diagnostic.severity.HINT] = "󰠠 ",
[vim.diagnostic.severity.INFO] = "",
}
-- Set diagnostic config
vim.diagnostic.config({
signs = {
text = signs,
},
virtual_text = true,
underline = true,
update_in_insert = false,
})
-- Setup servers
local cmp_nvim_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_nvim_lsp.default_capabilities()
-- Global LSP settings (applied to all servers)
vim.lsp.config('*', {
capabilities = capabilities,
})
-- Configure and enable LSP servers
-- lua_ls
vim.lsp.config("lua_ls", {
settings = {
Lua = {
diagnostics = {
globals = { "vim" },
},
completion = {
callSnippet = "Replace",
},
workspace = {
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.stdpath("config") .. "/lua"] = true,
},
},
},
},
})
-- emmet_language_server
vim.lsp.config("emmet_language_server", {
filetypes = {
"css",
"eruby",
"html",
"javascript",
"javascriptreact",
"less",
"sass",
"scss",
"pug",
"typescriptreact",
},
init_options = {
includeLanguages = {},
excludeLanguages = {},
extensionsPath = {},
preferences = {},
showAbbreviationSuggestions = true,
showExpandedAbbreviation = "always",
showSuggestionsAsSnippets = false,
syntaxProfiles = {},
variables = {},
},
})
-- emmet_ls
vim.lsp.config("emmet_ls", {
filetypes = {
"html",
"typescriptreact",
"javascriptreact",
"css",
"sass",
"scss",
"less",
"svelte",
},
})
-- ts_ls (TypeScript/JavaScript)
vim.lsp.config("ts_ls", {
filetypes = {
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
},
single_file_support = true,
init_options = {
preferences = {
includeCompletionsForModuleExports = true,
includeCompletionsForImportStatements = true,
},
},
})
-- gopls
vim.lsp.config("gopls", {
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
gofumpt = true,
},
},
})
-- tailwind
vim.lsp.config("tailwindcss", {
filetypes = {
"html",
"css",
"javascript",
"typescript",
"javascriptreact",
"typescriptreact",
"svelte",
"vue",
"astro",
},
init_options = {
userLanguages = {
astro = "html",
},
},
})
vim.lsp.enable("lua_ls")
vim.lsp.enable("emmet_language_server")
vim.lsp.enable("emmet_ls")
vim.lsp.enable("ts_ls")
vim.lsp.enable("gopls")
vim.lsp.enable("astro")
vim.lsp.enable("tailwindcss")
end,
}