Skip to content

Commit

Permalink
migrate lsp setup to match suggestions on this PR ThePrimeagen/init.l…
Browse files Browse the repository at this point in the history
  • Loading branch information
schwja04 committed Jan 7, 2024
1 parent 10f4745 commit 6e6ac09
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 73 deletions.
23 changes: 13 additions & 10 deletions lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
{
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" },
"LuaSnip": { "branch": "master", "commit": "68153ebb03e65d8a437c6240553645c57f17cf99" },
"catppuccin": { "branch": "main", "commit": "5e36ca599f4aa41bdd87fbf2c5aae4397ac55074" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"copilot.vim": { "branch": "release", "commit": "5b19fb001d7f31c4c7c5556d7a97b243bd29f45f" },
"darkplus": { "branch": "master", "commit": "fbcffb4d7d1a4288af7e8e5f93d360b486cc8e40" },
"harpoon": { "branch": "harpoon2", "commit": "6afc142443f8135329f8dd09b77e229f65001c0c" },
"image.nvim": { "branch": "master", "commit": "ec577441edca399c43d77b522870dbd7b9cd38b8" },
"friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" },
"harpoon": { "branch": "harpoon2", "commit": "fe03a9dda0c5a039b9ca284aa12211c2a099c16c" },
"image.nvim": { "branch": "master", "commit": "2090055394d5c8efb5f23143cc2f3d9fac68a61e" },
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
"lsp-zero.nvim": { "branch": "v3.x", "commit": "81c25389c855dd0e0fad4863f7464e1389e45ca3" },
"lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "56e435e09f8729af2d41973e81a0db440f8fe9c9" },
"mason.nvim": { "branch": "main", "commit": "a09da6ac634926a299dd439da08bdb547a8ca011" },
"neo-tree.nvim": { "branch": "v3.x", "commit": "77d9f484b88fd380386b46ed9206e5374d69d9d8" },
"neodev.nvim": { "branch": "main", "commit": "7cb4f7f29c6bf6f1d21a37f6dd6d12ba64266b09" },
"nui.nvim": { "branch": "main", "commit": "80445d015d2b5f9af0d9e8bce63d303bc86eda8a" },
"neodev.nvim": { "branch": "main", "commit": "be8d4d4cab6c13c6a572269c9d6a63774baba9a0" },
"nui.nvim": { "branch": "main", "commit": "35da9ca1de0fc4dda96c2e214d93d363c145f418" },
"nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" },
"nvim-lspconfig": { "branch": "master", "commit": "9bedcfed749755e43fc8bed46f85ce2044fe3b77" },
"nvim-treesitter": { "branch": "master", "commit": "e49f1e8ef3e8450a8446cb1f2bbb53c919f60b6d" },
"nvim-lspconfig": { "branch": "master", "commit": "ce0e625df61be77abe1340fbc9afe9ad39b31dd8" },
"nvim-treesitter": { "branch": "master", "commit": "49f1b9a7efc794be143f7ddcd60ce18e8164a7f8" },
"nvim-treesitter-context": { "branch": "master", "commit": "652ec514d6ba8bc4a3c2de76c855fe668e2c7196" },
"nvim-web-devicons": { "branch": "master", "commit": "cff25ce621e6d15fae0b0bfe38c00be50ce38468" },
"nvim-web-devicons": { "branch": "master", "commit": "db0c864375c198cacc171ff373e76bfce2a85045" },
"plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },
"telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
"undotree": { "branch": "master", "commit": "36ff7abb6b60980338344982ad4cdf03f7961ecd" },
Expand Down
165 changes: 102 additions & 63 deletions lua/plugins/lsp-config.lua
Original file line number Diff line number Diff line change
@@ -1,76 +1,115 @@
local function configure_lsp()
vim.api.nvim_create_autocmd("LspAttach", {
desc = "LSP keybindings",
callback = function(event)
local opts = { buffer = event.buf, remap = false }

vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
vim.keymap.set("n", "<leader>ca", function() vim.lsp.buf.code_action() end, opts)
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
end,
})

local lspconfig = require("lspconfig")
local lsp_capabitilies = require("cmp_nvim_lsp").default_capabilities()


require("mason").setup({})
require("mason-lspconfig").setup({
ensure_installed = {
"ansiblels",
"bashls",
"csharp_ls",
"eslint",
"lua_ls",
"pylsp",
"rust_analyzer",
"tsserver"
},
handlers = {
function(server)
lspconfig[server].setup({
capabilities = lsp_capabitilies,
})
end,
lua_ls = function()
lspconfig.lua_ls.setup({
capabilities = lsp_capabitilies,
settings = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = { "vim" },
},
workplaces = {
vim.env.VIMRUNTIME,
},
},
},
})
end,
}
})


local cmp = require("cmp")
local cmp_select = { behavior = cmp.SelectBehavior.Select }

cmp.setup({
sources = {
{ name = "path" },
{ name = "nvim_lsp" },
{ name = "nvim_lua" },
},
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(),
}),
window = {
documentation = cmp.config.window.bordered(),
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
})
end

return {
{
"VonHeikemen/lsp-zero.nvim",
branch = "v3.x",
"neovim/nvim-lspconfig",
dependencies = {
-- LSP Support
{ "williamboman/mason.nvim", },
{ "williamboman/mason-lspconfig.nvim", },
{ "neovim/nvim-lspconfig", },
{ "hrsh7th/cmp-nvim-lsp", },

-- Autocompletions
{ "hrsh7th/nvim-cmp", },
{ "hrsh7th/cmp-buffer", },
{ "hrsh7th/cmp-path", },
{ "saadparwaiz1/cmp_luasnip", },
{ "hrsh7th/cmp-nvim-lsp", },
{ "hrsh7th/cmp-nvim-lua", },

-- Snippets
{ "L3MON4D3/LuaSnip", },
{ "rafamadriz/friendly-snippets", },
},
lazy_load = false,
config = function()
local lsp_zero = require("lsp-zero")

lsp_zero.preset("recommended")

lsp_zero.on_attach(function(_, bufnr)
local opts = { buffer = bufnr, remap = false }

vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
vim.keymap.set("n", "<leader>ca", function() vim.lsp.buf.code_action() end, opts)
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
end)

lsp_zero.setup()

require("mason").setup({})
require("mason-lspconfig").setup({
ensure_installed = {
"ansiblels",
"bashls",
"csharp_ls",
"eslint",
"lua_ls",
"pylsp",
"rust_analyzer",
"tsserver"
},
handlers = {
lsp_zero.default_setup,
lua_ls = function()
local lua_opts = lsp_zero.nvim_lua_ls()
require("lspconfig").lua_ls.setup(lua_opts)
end,
}
})

local cmp = require("cmp")
local cmp_select = { behavior = cmp.SelectBehavior.Select }

cmp.setup({
sources = {
{ name = "path" },
{ name = "nvim_lsp" },
{ name = "nvim_lua" },
},
formatting = lsp_zero.cmp_format(),
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(),
}),
})
configure_lsp()
end,
},
}

0 comments on commit 6e6ac09

Please sign in to comment.