Skip to content

Commit 6e6ac09

Browse files
committed
migrate lsp setup to match suggestions on this PR ThePrimeagen/init.lua#94
1 parent 10f4745 commit 6e6ac09

File tree

2 files changed

+115
-73
lines changed

2 files changed

+115
-73
lines changed

lazy-lock.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
{
22
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
3-
"LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" },
3+
"LuaSnip": { "branch": "master", "commit": "68153ebb03e65d8a437c6240553645c57f17cf99" },
44
"catppuccin": { "branch": "main", "commit": "5e36ca599f4aa41bdd87fbf2c5aae4397ac55074" },
5+
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
56
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
7+
"cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" },
8+
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
9+
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
610
"copilot.vim": { "branch": "release", "commit": "5b19fb001d7f31c4c7c5556d7a97b243bd29f45f" },
7-
"darkplus": { "branch": "master", "commit": "fbcffb4d7d1a4288af7e8e5f93d360b486cc8e40" },
8-
"harpoon": { "branch": "harpoon2", "commit": "6afc142443f8135329f8dd09b77e229f65001c0c" },
9-
"image.nvim": { "branch": "master", "commit": "ec577441edca399c43d77b522870dbd7b9cd38b8" },
11+
"friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" },
12+
"harpoon": { "branch": "harpoon2", "commit": "fe03a9dda0c5a039b9ca284aa12211c2a099c16c" },
13+
"image.nvim": { "branch": "master", "commit": "2090055394d5c8efb5f23143cc2f3d9fac68a61e" },
1014
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
11-
"lsp-zero.nvim": { "branch": "v3.x", "commit": "81c25389c855dd0e0fad4863f7464e1389e45ca3" },
1215
"lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" },
1316
"mason-lspconfig.nvim": { "branch": "main", "commit": "56e435e09f8729af2d41973e81a0db440f8fe9c9" },
1417
"mason.nvim": { "branch": "main", "commit": "a09da6ac634926a299dd439da08bdb547a8ca011" },
1518
"neo-tree.nvim": { "branch": "v3.x", "commit": "77d9f484b88fd380386b46ed9206e5374d69d9d8" },
16-
"neodev.nvim": { "branch": "main", "commit": "7cb4f7f29c6bf6f1d21a37f6dd6d12ba64266b09" },
17-
"nui.nvim": { "branch": "main", "commit": "80445d015d2b5f9af0d9e8bce63d303bc86eda8a" },
19+
"neodev.nvim": { "branch": "main", "commit": "be8d4d4cab6c13c6a572269c9d6a63774baba9a0" },
20+
"nui.nvim": { "branch": "main", "commit": "35da9ca1de0fc4dda96c2e214d93d363c145f418" },
1821
"nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" },
19-
"nvim-lspconfig": { "branch": "master", "commit": "9bedcfed749755e43fc8bed46f85ce2044fe3b77" },
20-
"nvim-treesitter": { "branch": "master", "commit": "e49f1e8ef3e8450a8446cb1f2bbb53c919f60b6d" },
22+
"nvim-lspconfig": { "branch": "master", "commit": "ce0e625df61be77abe1340fbc9afe9ad39b31dd8" },
23+
"nvim-treesitter": { "branch": "master", "commit": "49f1b9a7efc794be143f7ddcd60ce18e8164a7f8" },
2124
"nvim-treesitter-context": { "branch": "master", "commit": "652ec514d6ba8bc4a3c2de76c855fe668e2c7196" },
22-
"nvim-web-devicons": { "branch": "master", "commit": "cff25ce621e6d15fae0b0bfe38c00be50ce38468" },
25+
"nvim-web-devicons": { "branch": "master", "commit": "db0c864375c198cacc171ff373e76bfce2a85045" },
2326
"plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },
2427
"telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
2528
"undotree": { "branch": "master", "commit": "36ff7abb6b60980338344982ad4cdf03f7961ecd" },

lua/plugins/lsp-config.lua

Lines changed: 102 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,115 @@
1+
local function configure_lsp()
2+
vim.api.nvim_create_autocmd("LspAttach", {
3+
desc = "LSP keybindings",
4+
callback = function(event)
5+
local opts = { buffer = event.buf, remap = false }
6+
7+
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
8+
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
9+
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
10+
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
11+
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
12+
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
13+
vim.keymap.set("n", "<leader>ca", function() vim.lsp.buf.code_action() end, opts)
14+
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
15+
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
16+
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
17+
end,
18+
})
19+
20+
local lspconfig = require("lspconfig")
21+
local lsp_capabitilies = require("cmp_nvim_lsp").default_capabilities()
22+
23+
24+
require("mason").setup({})
25+
require("mason-lspconfig").setup({
26+
ensure_installed = {
27+
"ansiblels",
28+
"bashls",
29+
"csharp_ls",
30+
"eslint",
31+
"lua_ls",
32+
"pylsp",
33+
"rust_analyzer",
34+
"tsserver"
35+
},
36+
handlers = {
37+
function(server)
38+
lspconfig[server].setup({
39+
capabilities = lsp_capabitilies,
40+
})
41+
end,
42+
lua_ls = function()
43+
lspconfig.lua_ls.setup({
44+
capabilities = lsp_capabitilies,
45+
settings = {
46+
Lua = {
47+
runtime = {
48+
version = "LuaJIT",
49+
},
50+
diagnostics = {
51+
globals = { "vim" },
52+
},
53+
workplaces = {
54+
vim.env.VIMRUNTIME,
55+
},
56+
},
57+
},
58+
})
59+
end,
60+
}
61+
})
62+
63+
64+
local cmp = require("cmp")
65+
local cmp_select = { behavior = cmp.SelectBehavior.Select }
66+
67+
cmp.setup({
68+
sources = {
69+
{ name = "path" },
70+
{ name = "nvim_lsp" },
71+
{ name = "nvim_lua" },
72+
},
73+
mapping = cmp.mapping.preset.insert({
74+
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
75+
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
76+
["<C-y>"] = cmp.mapping.confirm({ select = true }),
77+
["<C-Space>"] = cmp.mapping.complete(),
78+
}),
79+
window = {
80+
documentation = cmp.config.window.bordered(),
81+
},
82+
snippet = {
83+
expand = function(args)
84+
require("luasnip").lsp_expand(args.body)
85+
end,
86+
},
87+
})
88+
end
89+
190
return {
291
{
3-
"VonHeikemen/lsp-zero.nvim",
4-
branch = "v3.x",
92+
"neovim/nvim-lspconfig",
593
dependencies = {
94+
-- LSP Support
695
{ "williamboman/mason.nvim", },
796
{ "williamboman/mason-lspconfig.nvim", },
8-
{ "neovim/nvim-lspconfig", },
9-
{ "hrsh7th/cmp-nvim-lsp", },
97+
98+
-- Autocompletions
1099
{ "hrsh7th/nvim-cmp", },
100+
{ "hrsh7th/cmp-buffer", },
101+
{ "hrsh7th/cmp-path", },
102+
{ "saadparwaiz1/cmp_luasnip", },
103+
{ "hrsh7th/cmp-nvim-lsp", },
104+
{ "hrsh7th/cmp-nvim-lua", },
105+
106+
-- Snippets
11107
{ "L3MON4D3/LuaSnip", },
108+
{ "rafamadriz/friendly-snippets", },
12109
},
13110
lazy_load = false,
14111
config = function()
15-
local lsp_zero = require("lsp-zero")
16-
17-
lsp_zero.preset("recommended")
18-
19-
lsp_zero.on_attach(function(_, bufnr)
20-
local opts = { buffer = bufnr, remap = false }
21-
22-
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
23-
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
24-
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
25-
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
26-
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
27-
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
28-
vim.keymap.set("n", "<leader>ca", function() vim.lsp.buf.code_action() end, opts)
29-
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
30-
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
31-
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
32-
end)
33-
34-
lsp_zero.setup()
35-
36-
require("mason").setup({})
37-
require("mason-lspconfig").setup({
38-
ensure_installed = {
39-
"ansiblels",
40-
"bashls",
41-
"csharp_ls",
42-
"eslint",
43-
"lua_ls",
44-
"pylsp",
45-
"rust_analyzer",
46-
"tsserver"
47-
},
48-
handlers = {
49-
lsp_zero.default_setup,
50-
lua_ls = function()
51-
local lua_opts = lsp_zero.nvim_lua_ls()
52-
require("lspconfig").lua_ls.setup(lua_opts)
53-
end,
54-
}
55-
})
56-
57-
local cmp = require("cmp")
58-
local cmp_select = { behavior = cmp.SelectBehavior.Select }
59-
60-
cmp.setup({
61-
sources = {
62-
{ name = "path" },
63-
{ name = "nvim_lsp" },
64-
{ name = "nvim_lua" },
65-
},
66-
formatting = lsp_zero.cmp_format(),
67-
mapping = cmp.mapping.preset.insert({
68-
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
69-
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
70-
["<C-y>"] = cmp.mapping.confirm({ select = true }),
71-
["<C-Space>"] = cmp.mapping.complete(),
72-
}),
73-
})
112+
configure_lsp()
74113
end,
75114
},
76115
}

0 commit comments

Comments
 (0)