updated lspconfig
This commit is contained in:
@@ -5,77 +5,69 @@ return {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
{ "antosha417/nvim-lsp-file-operations", config = true },
|
||||
{ "folke/neodev.nvim", opts = {} },
|
||||
-- Falls nicht bereits woanders eingebunden:
|
||||
-- { "mason-org/mason-lspconfig.nvim", opts = {} },
|
||||
},
|
||||
config = function()
|
||||
-- import lspconfig plugin
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
-- import mason_lspconfig plugin
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
|
||||
-- import cmp-nvim-lsp plugin
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
|
||||
local keymap = vim.keymap -- for conciseness
|
||||
-- cmp capabilities global setzen (für alle Server)
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
vim.lsp.config("*", {
|
||||
capabilities = capabilities,
|
||||
}) -- :help lsp-config-merge
|
||||
|
||||
-- Keymaps bei Attach (deins, unveraendert)
|
||||
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 below functions
|
||||
local keymap = vim.keymap
|
||||
local opts = { buffer = ev.buf, silent = true }
|
||||
|
||||
-- set keybinds
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
keymap.set("n", "[d", function()
|
||||
vim.diagnostic.jump({ count = -1, float = true })
|
||||
end, opts) -- jump to previous diagnostic in buffer
|
||||
end, opts)
|
||||
|
||||
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
|
||||
end, opts)
|
||||
|
||||
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 = "Show documentation"
|
||||
keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
|
||||
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,
|
||||
})
|
||||
|
||||
-- used to enable autocompletion (assign to every lsp server config)
|
||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
|
||||
-- Change the Diagnostic symbols in the sign column (gutter)
|
||||
-- (not in youtube nvim video)
|
||||
-- Diagnostics-UI
|
||||
local x = vim.diagnostic.severity
|
||||
vim.diagnostic.config({
|
||||
virtual_text = { prefix = "" },
|
||||
@@ -84,25 +76,8 @@ return {
|
||||
float = { border = "single" },
|
||||
})
|
||||
|
||||
-- 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
|
||||
--
|
||||
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,
|
||||
-- Server-spezifisch: Lua
|
||||
vim.lsp.config("lua_ls", {
|
||||
settings = {
|
||||
Lua = {
|
||||
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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user