1
0
Fork 0
This commit is contained in:
zymon 2024-08-29 21:29:28 +02:00
parent 966e52643d
commit db91953a2a
2 changed files with 165 additions and 4 deletions

View file

@ -6,6 +6,8 @@ return {
"https://github.com/hrsh7th/cmp-buffer", "https://github.com/hrsh7th/cmp-buffer",
"https://github.com/hrsh7th/cmp-path", "https://github.com/hrsh7th/cmp-path",
"https://github.com/hrsh7th/cmp-cmdline", "https://github.com/hrsh7th/cmp-cmdline",
"https://github.com/hrsh7th/cmp-nvim-lsp",
"https://github.com/hrsh7th/cmp-nvim-lsp-signature-help",
}, },
event = { "InsertEnter", "CmdlineEnter", "BufReadPost" }, event = { "InsertEnter", "CmdlineEnter", "BufReadPost" },
config = function() config = function()
@ -20,10 +22,10 @@ return {
["<C-e>"] = cmp.mapping.abort(), ["<C-e>"] = cmp.mapping.abort(),
}), }),
sources = cmp.config.sources({ sources = cmp.config.sources({
{ { name = "buffer", option = { keyword_length = 3 }, },
name = "buffer", { name = "path" },
option = { keyword_length = 3 }, { name = "nvim_lsp" },
}, { name = 'nvim_lsp_signature_help' },
}), }),
window = { window = {
completion = cmp.config.window.bordered(), completion = cmp.config.window.bordered(),

159
lua/znvim/plugins/lsp.lua Normal file
View file

@ -0,0 +1,159 @@
return {
{ -- lsp configurations
"https://github.com/neovim/nvim-lspconfig",
event = "BufReadPre",
dependencies = {
"https://github.com/williamboman/mason.nvim",
"https://github.com/williamboman/mason-lspconfig.nvim",
},
config = function()
local lspconfig = require("lspconfig")
vim.diagnostic.config({
float = {
border = "rounded",
},
virtual_text = false,
virtual_lines = {
only_current_line = true,
},
})
local opts = { noremap = true, silent = true }
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
-- vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
local on_attach = function(_, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
local function bufopts(desc)
return { buffer = bufnr, noremap = true, silent = true, desc = desc }
end
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts("go to definition"))
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts("go to declaration"))
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts("hover"))
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts("go to implementation"))
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts("help signature"))
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts("references"))
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, bufopts("type definition"))
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts("rename"))
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts("code action"))
vim.keymap.set("n", "<leader>ff", function()
vim.lsp.buf.format({ async = true })
end, bufopts("format code"))
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
lspconfig.bashls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
lspconfig.texlab.setup({
on_attach = on_attach,
capabilities = capabilities,
})
lspconfig.typst_lsp.setup({
on_attach = on_attach,
capabilities = capabilities,
})
lspconfig.elixirls.setup({
cmd = { "/usr/lib/elixir-ls/language_server.sh" },
on_attach = on_attach,
capabilities = capabilities,
})
lspconfig.pyright.setup({
on_attach = on_attach,
capabilities = capabilities,
})
lspconfig.rust_analyzer.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
diagnostics = {
enable = true,
},
},
},
})
-- Trzeba stworzyć odpowiedniego enva i zainstalować paczki
lspconfig.julials.setup({
-- This just adds dirname(fname) as a fallback (see nvim-lspconfig#1768).
on_new_config = function(new_config, _)
-- https://discourse.julialang.org/t/neovim-languageserver-jl/37286/83
local julia = vim.fn.expand("~/.local/share/julia/environments/nvim-lspconfig/bin/julia")
if require("lspconfig").util.path.is_file(julia) then
new_config.cmd[1] = julia
end
end,
root_dir = function(fname)
local util = require("lspconfig.util")
return util.root_pattern("Project.toml")(fname)
or util.find_git_ancestor(fname)
or util.path.dirname(fname)
end,
on_attach = on_attach,
capabilities = capabilities,
settings = {
julia = {
lint = {
call = false,
},
},
}
})
lspconfig.clangd.setup({
on_attach = on_attach,
capabilities = capabilities,
})
lspconfig.lua_ls.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { "vim" },
},
telemetry = {
enable = false,
},
},
},
})
end,
},
{ -- portable package manager
"https://github.com/williamboman/mason.nvim",
cmd = "Mason",
keys = {
{ "<leader>pm", "<cmd>Mason<CR>", desc = "Mason" },
},
opts = {
ui = {
border = "double",
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
},
},
},
},
}