lsp setup
This commit is contained in:
parent
5c937dc1c8
commit
5bd1837e7d
18 changed files with 260 additions and 195 deletions
|
|
@ -5,7 +5,6 @@ return {
|
|||
dashboard = {
|
||||
preset = {
|
||||
pick = nil,
|
||||
---@type snacks.dashboard.Item[]
|
||||
keys = {
|
||||
{ icon = " ", key = "f", desc = "Find File", action = ":lua Snacks.dashboard.pick('files')" },
|
||||
{ icon = " ", key = "n", desc = "New File", action = ":ene | startinsert" },
|
||||
|
|
|
|||
130
lua/plugins/lsp.lua
Normal file
130
lua/plugins/lsp.lua
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
-- return {
|
||||
-- "mason-org/mason-lspconfig.nvim",
|
||||
-- opts = {
|
||||
-- ensure_installed = { "lua_ls", "rust_analyzer", "pyright" },
|
||||
-- },
|
||||
-- dependencies = {
|
||||
-- { "mason-org/mason.nvim", opts = {} },
|
||||
-- "neovim/nvim-lspconfig",
|
||||
-- },
|
||||
-- }
|
||||
return {
|
||||
"VonHeikemen/lsp-zero.nvim",
|
||||
branch = "v2.x",
|
||||
dependencies = {
|
||||
-- LSP Support
|
||||
{ "neovim/nvim-lspconfig" }, -- Required
|
||||
{ -- Optional
|
||||
"williamboman/mason.nvim",
|
||||
build = function()
|
||||
pcall(vim.cmd, "MasonUpdate")
|
||||
end,
|
||||
},
|
||||
{ "williamboman/mason-lspconfig.nvim" }, -- Optional
|
||||
|
||||
-- Autocompletion
|
||||
{ "hrsh7th/nvim-cmp" }, -- Required
|
||||
{ "hrsh7th/cmp-nvim-lsp" }, -- Required
|
||||
{ "L3MON4D3/LuaSnip" }, -- Required
|
||||
{ "rafamadriz/friendly-snippets" },
|
||||
{ "hrsh7th/cmp-buffer" },
|
||||
{ "hrsh7th/cmp-path" },
|
||||
{ "hrsh7th/cmp-cmdline" },
|
||||
{ "saadparwaiz1/cmp_luasnip" },
|
||||
},
|
||||
config = function()
|
||||
local lsp = require("lsp-zero")
|
||||
|
||||
lsp.on_attach(function(client, bufnr)
|
||||
local opts = { buffer = bufnr, remap = false }
|
||||
|
||||
vim.keymap.set("n", "gr", function() vim.lsp.buf.references() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Goto Reference" }))
|
||||
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Goto Definition" }))
|
||||
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Hover" }))
|
||||
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Workspace Symbol" }))
|
||||
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.setloclist() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Show Diagnostics" }))
|
||||
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, vim.tbl_deep_extend("force", opts, { desc = "Next Diagnostic" }))
|
||||
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, vim.tbl_deep_extend("force", opts, { desc = "Previous Diagnostic" }))
|
||||
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Code Action" }))
|
||||
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, vim.tbl_deep_extend("force", opts, { desc = "LSP References" }))
|
||||
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Rename" }))
|
||||
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Signature Help" }))
|
||||
end)
|
||||
|
||||
require("mason").setup({})
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"eslint",
|
||||
"lua_ls",
|
||||
"jsonls",
|
||||
"html",
|
||||
"tailwindcss",
|
||||
-- "pylsp",
|
||||
"dockerls",
|
||||
"bashls",
|
||||
"gopls",
|
||||
"pyright",
|
||||
},
|
||||
handlers = {
|
||||
lsp.default_setup,
|
||||
lua_ls = function()
|
||||
local lua_opts = lsp.nvim_lua_ls()
|
||||
require("lspconfig").lua_ls.setup(lua_opts)
|
||||
end,
|
||||
},
|
||||
})
|
||||
|
||||
local cmp_action = require("lsp-zero").cmp_action()
|
||||
local cmp = require("cmp")
|
||||
local cmp_select = { behavior = cmp.SelectBehavior.Select }
|
||||
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
|
||||
-- `/` cmdline setup.
|
||||
cmp.setup.cmdline("/", {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = "buffer" },
|
||||
},
|
||||
})
|
||||
|
||||
-- `:` cmdline setup.
|
||||
cmp.setup.cmdline(":", {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "path" },
|
||||
}, {
|
||||
{
|
||||
name = "cmdline",
|
||||
option = {
|
||||
ignore_cmds = { "Man", "!" },
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip", keyword_length = 2 },
|
||||
{ name = "buffer", keyword_length = 3 },
|
||||
{ name = "path" },
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
|
||||
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-f>"] = cmp_action.luasnip_jump_forward(),
|
||||
["<C-b>"] = cmp_action.luasnip_jump_backward(),
|
||||
["<Tab>"] = cmp_action.luasnip_supertab(),
|
||||
["<S-Tab>"] = cmp_action.luasnip_shift_supertab(),
|
||||
}),
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
-- ~/.config/nvim/lua/plugins/lspconfig.lua
|
||||
return {
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile", "BufWritePre" },
|
||||
config = function()
|
||||
local lspconfig = require("lspconfig")
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
-- Example: Python
|
||||
lspconfig.pyright.setup({
|
||||
capabilities = capabilities
|
||||
})
|
||||
|
||||
-- Example: Lua
|
||||
lspconfig.lua_ls.setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = { globals = { "vim" } },
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
|
@ -1,68 +1,61 @@
|
|||
return {
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
-- Completion sources
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-cmdline",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-buffer", -- Source for text in buffer
|
||||
"hrsh7th/cmp-path", -- Source for file system paths
|
||||
{
|
||||
"L3MON4D3/LuaSnip", -- Snippet Engine
|
||||
version = "v2.*",
|
||||
build = "make install_jsregexp", -- Allow lsp-snippet-transformations
|
||||
},
|
||||
"rafamadriz/friendly-snippets", -- Preconfigured snippets for different languages
|
||||
"onsails/lspkind.nvim", -- VS-Code like pictograms
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local lspkind = require("lspkind")
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
-- Snippet engine
|
||||
"L3MON4D3/LuaSnip",
|
||||
require("luasnip.loaders.from_vscode").lazy_load() -- Required for friendly-snippets to work
|
||||
|
||||
-- Optional: VSCode-style icons
|
||||
"onsails/lspkind.nvim",
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
local lspkind = require("lspkind")
|
||||
-- Settings for the appearance of the completion window
|
||||
vim.api.nvim_set_hl(0, "CmpNormal", { bg = "#000000", fg = "#ffffff" })
|
||||
vim.api.nvim_set_hl(0, "CmpSelect", { bg = "#000000", fg = "#b5010f" })
|
||||
vim.api.nvim_set_hl(0, "CmpBorder", { bg = "#000000", fg = "#b5010f" })
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-n>"] = cmp.mapping.select_next_item(),
|
||||
["<C-p>"] = cmp.mapping.select_prev_item(),
|
||||
["<C-p>"] = cmp.mapping.select_prev_item(),
|
||||
["<C-e>"] = cmp.mapping.close(),
|
||||
["<C-space>"] = cmp.mapping.complete(),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "path" },
|
||||
{ name = "buffer" },
|
||||
}),
|
||||
formatting = {
|
||||
format = lspkind.cmp_format({
|
||||
mode = "symbol_text", -- "text", "symbol", or "symbol_text"
|
||||
maxwidth = 50,
|
||||
ellipsis_char = "...",
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
-- Cmdline completion (optional)
|
||||
cmp.setup.cmdline("/", {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = "buffer" }
|
||||
}
|
||||
})
|
||||
|
||||
cmp.setup.cmdline(":", {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "path" }
|
||||
}, {
|
||||
{ name = "cmdline" }
|
||||
})
|
||||
})
|
||||
end,
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-e>"] = cmp.mapping.close(),
|
||||
["<CR>"] = cmp.mapping.confirm({
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
}),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
window = {
|
||||
completion = {
|
||||
border = "rounded",
|
||||
winhighlight = "Normal:CmpNormal,CursorLine:CmpSelect,FloatBorder:CmpBorder",
|
||||
}
|
||||
},
|
||||
})
|
||||
vim.cmd([[
|
||||
set completeopt=menuone,noinsert,noselect
|
||||
highlight! default link CmpItemKind CmpItemMenuDefault
|
||||
]])
|
||||
end,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,17 +13,14 @@ return {
|
|||
},
|
||||
opts = function()
|
||||
local api = require("nvim-tree.api")
|
||||
|
||||
return {
|
||||
view = {
|
||||
width = 35,
|
||||
side = "right",
|
||||
side = "left",
|
||||
preserve_window_proportions = true,
|
||||
},
|
||||
hijack_cursor = true,
|
||||
view = {
|
||||
adaptive_size = true,
|
||||
},
|
||||
hijack_cursor = true,
|
||||
renderer = {
|
||||
highlight_git = true,
|
||||
highlight_opened_files = "name",
|
||||
|
|
|
|||
37
lua/plugins/trouble.lua
Normal file
37
lua/plugins/trouble.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
return {
|
||||
"folke/trouble.nvim",
|
||||
opts = {}, -- for default options, refer to the configuration section for custom setup.
|
||||
cmd = "Trouble",
|
||||
keys = {
|
||||
{
|
||||
"<leader>xx",
|
||||
"<cmd>Trouble diagnostics toggle<cr>",
|
||||
desc = "Diagnostics (Trouble)",
|
||||
},
|
||||
{
|
||||
"<leader>xX",
|
||||
"<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
|
||||
desc = "Buffer Diagnostics (Trouble)",
|
||||
},
|
||||
{
|
||||
"<leader>cs",
|
||||
"<cmd>Trouble symbols toggle focus=false<cr>",
|
||||
desc = "Symbols (Trouble)",
|
||||
},
|
||||
{
|
||||
"<leader>cl",
|
||||
"<cmd>Trouble lsp toggle focus=false win.position=right<cr>",
|
||||
desc = "LSP Definitions / references / ... (Trouble)",
|
||||
},
|
||||
{
|
||||
"<leader>xL",
|
||||
"<cmd>Trouble loclist toggle<cr>",
|
||||
desc = "Location List (Trouble)",
|
||||
},
|
||||
{
|
||||
"<leader>xQ",
|
||||
"<cmd>Trouble qflist toggle<cr>",
|
||||
desc = "Quickfix List (Trouble)",
|
||||
},
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue