Fixed lsp

This commit is contained in:
2024-09-11 16:16:59 +02:00
parent bedfd083b7
commit 977acb17c5
7 changed files with 117 additions and 107 deletions

View File

@@ -1,15 +1,20 @@
{ {
"LuaSnip": { "branch": "master", "commit": "45db5addf8d0a201e1cf247cae4cdce605ad3768" }, "LuaSnip": { "branch": "master", "commit": "45db5addf8d0a201e1cf247cae4cdce605ad3768" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"dichromatic": { "branch": "master", "commit": "9765a72ce24ddae48afe12c316583a22c82ad812" }, "dichromatic": { "branch": "master", "commit": "9765a72ce24ddae48afe12c316583a22c82ad812" },
"fidget.nvim": { "branch": "main", "commit": "d855eed8a06531a7e8fd0684889b2943f373c469" },
"harpoon": { "branch": "master", "commit": "1bc17e3e42ea3c46b33c0bbad6a880792692a1b3" }, "harpoon": { "branch": "master", "commit": "1bc17e3e42ea3c46b33c0bbad6a880792692a1b3" },
"hererocks": { "branch": "master", "commit": "8bd2fcfdd65cfa7535ce39ea372a63b0bdb8e528" },
"lazy.nvim": { "branch": "main", "commit": "48b52b5cfcf8f88ed0aff8fde573a5cc20b1306d" }, "lazy.nvim": { "branch": "main", "commit": "48b52b5cfcf8f88ed0aff8fde573a5cc20b1306d" },
"lsp-zero.nvim": { "branch": "v4.x", "commit": "9823b3e27deaf9f0152f3bc22f05b54f21e234e8" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
"nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" }, "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
"nvim-lspconfig": { "branch": "master", "commit": "d88ae6623fef09251e3aa20001bb761686eae730" }, "nvim-lspconfig": { "branch": "master", "commit": "d88ae6623fef09251e3aa20001bb761686eae730" },
"nvim-treesitter": { "branch": "master", "commit": "d22166e3d8d375b761c32b303176f3e955560b0c" }, "nvim-treesitter": { "branch": "master", "commit": "b6a6d8997c46dc15682020ce4fddc5a89ee1ac0d" },
"plenary": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" }, "plenary": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" },
"plenary.nvim": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" }, "plenary.nvim": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" },
"telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },

View File

@@ -15,15 +15,11 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct. This is done by loading the remap before lazy
-- Setup lazy.nvim -- Setup lazy.nvim
require("lazy").setup({ require("lazy").setup({
spec = { spec = "plugins",
-- import plugins change_detection = { notify = false },
{ import = "plugins" },
},
-- Configure any other settings here. See documentation for details -- Configure any other settings here. See documentation for details
install = { colorscheme = { "habamax" } }, install = { colorscheme = { "habamax" } },
-- automatically check for plugin updates -- automatically check for plugin updates

View File

@@ -13,6 +13,9 @@ vim.keymap.set("n", "J", "mzJ`z")
-- Auto formatting -- Auto formatting
vim.keymap.set("n", "<leader>f", vim.lsp.buf.format) vim.keymap.set("n", "<leader>f", vim.lsp.buf.format)
-- Display type signature
vim.keymap.set("n", "gs", vim.lsp.buf.signature_help)
-- Greatest remap ever -- Greatest remap ever
-- Delete visual selection to null and paste latest clipboard entry -- Delete visual selection to null and paste latest clipboard entry
vim.keymap.set("x", "<leader>p", [["_dP]]) vim.keymap.set("x", "<leader>p", [["_dP]])

View File

@@ -6,4 +6,3 @@ return {
name = "plenary" name = "plenary"
} }
} }

View File

@@ -1,107 +1,116 @@
return { return {
{ "neovim/nvim-lspconfig",
"VonHeikemen/lsp-zero.nvim", dependencies = {
branch = "v4.x",
lazy = true,
config = false,
},
{
"williamboman/mason.nvim", "williamboman/mason.nvim",
lazy = false, "williamboman/mason-lspconfig.nvim",
config = true, "hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"hrsh7th/nvim-cmp",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"j-hui/fidget.nvim",
}, },
-- Autocompletion
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
{ "L3MON4D3/LuaSnip" },
},
config = function() config = function()
local cmp = require('cmp') local cmp = require('cmp')
local cmp_lsp = require("cmp_nvim_lsp")
local capabilities = vim.tbl_deep_extend(
"force",
{},
vim.lsp.protocol.make_client_capabilities(),
cmp_lsp.default_capabilities())
cmp.setup({ require("fidget").setup({})
sources = { require("mason").setup()
{ name = "nvim_lsp" }, require("mason-lspconfig").setup({
ensure_installed = {
"clangd",
"lua_ls",
"rust_analyzer",
}, },
mapping = cmp.mapping.preset.insert({
['<C-Space>'] = cmp.mapping.complete(),
}),
snippet = {
expand = function(args)
vim.snippet.expand(args.body)
end,
},
})
end
},
-- LSP
{
"neovim/nvim-lspconfig",
cmd = { 'LspInfo', 'LspInstall', 'LspStart' },
event = { 'BufReadPre', 'BufNewFile' },
dependencies = {
{ "hrsh7th/cmp-nvim-lsp" },
{ "williamboman/mason.nvim" },
{ "williamboman/mason-lspconfig.nvim" },
},
config = function()
local lsp_zero = require('lsp-zero')
-- lsp_attach is where you enable features that only work
-- if there is a language server active in the file
local lsp_attach = function(client, bufnr)
local opts = { buffer = bufnr }
vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
vim.keymap.set('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
vim.keymap.set({ 'n', 'x' }, '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>', opts)
vim.keymap.set('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
end
lsp_zero.extend_lspconfig({
sign_text = true,
lsp_attach = lsp_attach,
capabilities = require('cmp_nvim_lsp').default_capabilities()
})
require('mason-lspconfig').setup({
ensure_installed = {},
handlers = { handlers = {
function(server_name) function(server_name) -- default handler (optional)
require('lspconfig')[server_name].setup({}) require("lspconfig")[server_name].setup {
capabilities = capabilities
}
end, end,
lua_ls = function()
require('lspconfig').lua_ls.setup({ zls = function()
local lspconfig = require("lspconfig")
lspconfig.zls.setup({
root_dir = lspconfig.util.root_pattern(".git", "build.zig", "zls.json"),
settings = {
zls = {
enable_inlay_hints = true,
enable_snippets = true,
warn_style = true,
},
},
})
vim.g.zig_fmt_parse_errors = 0
vim.g.zig_fmt_autosave = 0
end,
["lua_ls"] = function()
local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup {
capabilities = capabilities,
settings = { settings = {
Lua = { Lua = {
runtime = { runtime = { version = "Lua 5.1" },
version = 'LuaJIT',
path = vim.split(package.path, ';'),
},
diagnostics = { diagnostics = {
globals = { 'vim' }, globals = { "bit", "vim", "it", "describe", "before_each", "after_each" },
}, }
workspace = { }
library = { }
[vim.fn.expand('$VIMRUNTIME/lua')] = true, }
[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
},
},
},
},
})
end, end,
} }
}) })
local cmp_select = { behavior = cmp.SelectBehavior.Select }
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
mapping = cmp.mapping.preset.insert({
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
["<C-Space>"] = cmp.mapping.complete(),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
}, {
{ name = 'buffer' },
})
})
local _border = 'rounded'
vim.diagnostic.config({
-- update_in_insert = true,
float = {
focusable = false,
style = "minimal",
border = _border,
source = "always",
header = "",
prefix = "",
},
})
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
vim.lsp.handlers.hover, { border = _border }
)
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
vim.lsp.handlers.signature_help, { border = _border }
)
require('lspconfig.ui.windows').default_options = { border = _border }
end end
} }
}

View File

@@ -1,7 +1,7 @@
return { return {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
build = function() build = function()
require("nvim-treesitter.instal").update({ with_sync = true})() require("nvim-treesitter.install").update({ with_sync = true })()
end, end,
config = function() config = function()
require("nvim-treesitter.configs").setup({ require("nvim-treesitter.configs").setup({
@@ -35,4 +35,3 @@ return {
vim.treesitter.language.register("templ", "templ") vim.treesitter.language.register("templ", "templ")
end end
} }

View File

@@ -5,4 +5,3 @@ return {
vim.keymap.set("n", "<leader>u", vim.cmd.UndoTreeToggle) vim.keymap.set("n", "<leader>u", vim.cmd.UndoTreeToggle)
end end
} }