updated lspconfig
This commit is contained in:
@@ -5,77 +5,69 @@ return {
|
|||||||
"hrsh7th/cmp-nvim-lsp",
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
{ "antosha417/nvim-lsp-file-operations", config = true },
|
{ "antosha417/nvim-lsp-file-operations", config = true },
|
||||||
{ "folke/neodev.nvim", opts = {} },
|
{ "folke/neodev.nvim", opts = {} },
|
||||||
|
-- Falls nicht bereits woanders eingebunden:
|
||||||
|
-- { "mason-org/mason-lspconfig.nvim", opts = {} },
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- import lspconfig plugin
|
-- cmp capabilities global setzen (für alle Server)
|
||||||
local lspconfig = require("lspconfig")
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
|
vim.lsp.config("*", {
|
||||||
-- import mason_lspconfig plugin
|
capabilities = capabilities,
|
||||||
local mason_lspconfig = require("mason-lspconfig")
|
}) -- :help lsp-config-merge
|
||||||
|
|
||||||
-- import cmp-nvim-lsp plugin
|
|
||||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
|
||||||
|
|
||||||
local keymap = vim.keymap -- for conciseness
|
|
||||||
|
|
||||||
|
-- Keymaps bei Attach (deins, unveraendert)
|
||||||
vim.api.nvim_create_autocmd("LspAttach", {
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
-- Buffer local mappings.
|
local keymap = vim.keymap
|
||||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
||||||
local opts = { buffer = ev.buf, silent = true }
|
local opts = { buffer = ev.buf, silent = true }
|
||||||
|
|
||||||
-- set keybinds
|
|
||||||
opts.desc = "Show LSP references"
|
opts.desc = "Show LSP references"
|
||||||
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts) -- show definition, references
|
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "Go to declaration"
|
opts.desc = "Go to declaration"
|
||||||
keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration
|
keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||||
|
|
||||||
opts.desc = "Show LSP definitions"
|
opts.desc = "Show LSP definitions"
|
||||||
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) -- show lsp definitions
|
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "Show LSP implementations"
|
opts.desc = "Show LSP implementations"
|
||||||
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts) -- show lsp implementations
|
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "Show LSP type definitions"
|
opts.desc = "Show LSP type definitions"
|
||||||
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts) -- show lsp type definitions
|
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "See available code actions"
|
opts.desc = "See available code actions"
|
||||||
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
|
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||||
|
|
||||||
opts.desc = "Smart rename"
|
opts.desc = "Smart rename"
|
||||||
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename
|
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||||
|
|
||||||
opts.desc = "Show buffer diagnostics"
|
opts.desc = "Show buffer diagnostics"
|
||||||
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
|
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "Show line diagnostics"
|
opts.desc = "Show line diagnostics"
|
||||||
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line
|
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
|
||||||
|
|
||||||
opts.desc = "Go to previous diagnostic"
|
opts.desc = "Go to previous diagnostic"
|
||||||
keymap.set("n", "[d", function()
|
keymap.set("n", "[d", function()
|
||||||
vim.diagnostic.jump({ count = -1, float = true })
|
vim.diagnostic.jump({ count = -1, float = true })
|
||||||
end, opts) -- jump to previous diagnostic in buffer
|
end, opts)
|
||||||
|
|
||||||
opts.desc = "Go to next diagnostic"
|
opts.desc = "Go to next diagnostic"
|
||||||
keymap.set("n", "]d", function()
|
keymap.set("n", "]d", function()
|
||||||
vim.diagnostic.jump({ count = 1, float = true })
|
vim.diagnostic.jump({ count = 1, float = true })
|
||||||
end, opts) -- jump to next diagnostic in buffer
|
end, opts)
|
||||||
|
|
||||||
opts.desc = "Show documentation for what is under cursor"
|
opts.desc = "Show documentation"
|
||||||
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
|
keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||||
|
|
||||||
opts.desc = "Restart LSP"
|
opts.desc = "Restart LSP"
|
||||||
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
|
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- used to enable autocompletion (assign to every lsp server config)
|
-- Diagnostics-UI
|
||||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
|
||||||
|
|
||||||
-- Change the Diagnostic symbols in the sign column (gutter)
|
|
||||||
-- (not in youtube nvim video)
|
|
||||||
local x = vim.diagnostic.severity
|
local x = vim.diagnostic.severity
|
||||||
vim.diagnostic.config({
|
vim.diagnostic.config({
|
||||||
virtual_text = { prefix = "" },
|
virtual_text = { prefix = "" },
|
||||||
@@ -84,25 +76,8 @@ return {
|
|||||||
float = { border = "single" },
|
float = { border = "single" },
|
||||||
})
|
})
|
||||||
|
|
||||||
-- local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
-- Server-spezifisch: Lua
|
||||||
-- for type, icon in pairs(signs) do
|
vim.lsp.config("lua_ls", {
|
||||||
-- local hl = "DiagnosticSign" .. type
|
|
||||||
-- vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
for _, server in ipairs({
|
|
||||||
"html",
|
|
||||||
"cssls",
|
|
||||||
"tailwindcss",
|
|
||||||
"lua_ls",
|
|
||||||
"pyright",
|
|
||||||
}) do
|
|
||||||
lspconfig[server].setup({ capabilities = capabilities })
|
|
||||||
end
|
|
||||||
|
|
||||||
-- lua config
|
|
||||||
lspconfig.lua_ls.setup({
|
|
||||||
capabilities = capabilities,
|
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
diagnostics = { globals = { "vim" } },
|
diagnostics = { globals = { "vim" } },
|
||||||
@@ -110,5 +85,17 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- (Optional) Mason-LSPConfig: Installer + kein Auto-Enable (wir enablen selbst)
|
||||||
|
local ok_mason, mason_lspconfig = pcall(require, "mason-lspconfig")
|
||||||
|
if ok_mason then
|
||||||
|
mason_lspconfig.setup({
|
||||||
|
ensure_installed = { "html", "cssls", "tailwindcss", "lua_ls", "pyright" },
|
||||||
|
automatic_enable = false, -- sonst wuerde Mason selbst enable() rufen
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Neovim 0.11+: Server aktivieren (statt lspconfig[server].setup)
|
||||||
|
vim.lsp.enable({ "html", "cssls", "tailwindcss", "lua_ls", "pyright" })
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user