setup lsp and cmp stuff

This commit is contained in:
Adithya 2024-06-13 17:11:08 +05:30
parent 24ecde98cf
commit 7a61a2bcf4
Signed by: adtya
GPG key ID: B8857BFBA2C47B9C
4 changed files with 194 additions and 2 deletions

View file

@ -1,17 +1,26 @@
{
"LuaSnip": { "branch": "master", "commit": "50fcf17db7c75af80e6b6109acfbfb4504768780" },
"bufferline.nvim": { "branch": "main", "commit": "99337f63f0a3c3ab9519f3d1da7618ca4f91cffe" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"dashboard-nvim": { "branch": "master", "commit": "5346d023afc4bfc7ff63d05c70bcdb0784bb657a" },
"dracula.nvim": { "branch": "main", "commit": "8d8bddb8814c3e7e62d80dda65a9876f97eb699c" },
"dressing.nvim": { "branch": "master", "commit": "e3714c8049b2243e792492c4149e4cc395c68eb9" },
"fidget.nvim": { "branch": "main", "commit": "ef99df04a1c53a453602421bc0f756997edc8289" },
"friendly-snippets": { "branch": "main", "commit": "700c4a25caacbb4648c9a27972c2fe203948e0c2" },
"gitsigns.nvim": { "branch": "main", "commit": "4a143f13e122ab91abdc88f89eefbe70a4858a56" },
"indent-blankline.nvim": { "branch": "master", "commit": "d98f537c3492e87b6dc6c2e3f66ac517528f406f" },
"lazy.nvim": { "branch": "main", "commit": "eb4957442e3182f051b0ae11da32e06d22c190e3" },
"lazygit.nvim": { "branch": "main", "commit": "ad3e1ea592f9d13e86e0d4e850224d9d78069508" },
"lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "8db12610bcb7ce67013cfdfaba4dd47a23c6e851" },
"mason.nvim": { "branch": "main", "commit": "0950b15060067f752fde13a779a994f59516ce3d" },
"neo-tree.nvim": { "branch": "v3.x", "commit": "29f7c215332ba95e470811c380ddbce2cebe2af4" },
"noice.nvim": { "branch": "main", "commit": "e5cb20c6e14305d24025ecb77d7d4dd9d61f1a64" },
"nui.nvim": { "branch": "main", "commit": "322978c734866996274467de084a95e4f9b5e0b1" },
"nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" },
"nvim-cmp": { "branch": "main", "commit": "a110e12d0b58eefcf5b771f533fc2cf3050680ac" },
"nvim-lspconfig": { "branch": "master", "commit": "4d38bece98300e3e5cd24a9aa0d0ebfea4951c16" },
"nvim-treesitter": { "branch": "master", "commit": "9a7ad2ff7a7ea81016aca2fc89c9b2c1a5365421" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" },
"nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" },

90
lua/plugins/cmp.lua Normal file
View file

@ -0,0 +1,90 @@
local Plugin = { "hrsh7th/nvim-cmp" }
Plugin.dependencies = {
-- Completion sources
{ "hrsh7th/cmp-buffer" },
{ "hrsh7th/cmp-path" },
{ "saadparwaiz1/cmp_luasnip" },
{ "hrsh7th/cmp-nvim-lsp" },
-- Snippets
{ "L3MON4D3/LuaSnip" },
{ "rafamadriz/friendly-snippets" },
}
Plugin.event = "InsertEnter"
function Plugin.config()
local cmp = require("cmp")
local luasnip = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load()
local select_opts = { behavior = cmp.SelectBehavior.Select }
-- See :help cmp-config
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
sources = {
{ name = "path" },
{ name = "nvim_lsp" },
{ name = "buffer", keyword_length = 3 },
{ name = "luasnip", keyword_length = 2 },
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
-- See :help cmp-mapping
mapping = {
["<Up>"] = cmp.mapping.select_prev_item(select_opts),
["<Down>"] = cmp.mapping.select_next_item(select_opts),
["<C-p>"] = cmp.mapping.select_prev_item(select_opts),
["<C-n>"] = cmp.mapping.select_next_item(select_opts),
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.abort(),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
["<CR>"] = cmp.mapping.confirm({ select = false }),
["<C-f>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { "i", "s" }),
["<C-b>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<Tab>"] = cmp.mapping(function(fallback)
local col = vim.fn.col(".") - 1
if cmp.visible() then
cmp.select_next_item(select_opts)
elseif col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then
fallback()
else
cmp.complete()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping.select_prev_item(select_opts),
},
})
end
return Plugin

83
lua/plugins/lsp.lua Normal file
View file

@ -0,0 +1,83 @@
local Plugin = { "neovim/nvim-lspconfig" }
Plugin.dependencies = {
"hrsh7th/cmp-nvim-lsp",
"williamboman/mason-lspconfig.nvim",
}
local user = {}
Plugin.event = { "BufReadPre", "BufNewFile" }
Plugin.cmd = { "LspInfo", "LspInstall", "LspUnInstall" }
function Plugin.init()
-- See :help vim.diagnostic.config()
vim.diagnostic.config({
virtual_text = true,
severity_sort = true,
float = {
border = "rounded",
source = "always",
},
})
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" })
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" })
end
function Plugin.config()
local lspconfig = require("lspconfig")
local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities()
local group = vim.api.nvim_create_augroup("lsp_cmds", { clear = true })
vim.api.nvim_create_autocmd("LspAttach", {
group = group,
desc = "LSP actions",
callback = user.on_attach,
})
-- See :help mason-lspconfig-settings
require("mason-lspconfig").setup({
handlers = {
-- See :help mason-lspconfig-dynamic-server-setup
function(server)
-- See :help lspconfig-setup
lspconfig[server].setup({
capabilities = lsp_capabilities,
})
end,
["lua_ls"] = function()
-- if you install the language server for lua it will
-- load the config from lua/plugins/lsp/lua_ls.lua
require("plugins.lsp.lua_ls")
end,
},
})
end
function user.on_attach(event)
local bufmap = function(mode, lhs, rhs)
local opts = { buffer = event.buf }
vim.keymap.set(mode, lhs, rhs, opts)
end
-- You can search each function in the help page.
-- For example :help vim.lsp.buf.hover()
bufmap("n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>")
bufmap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<cr>")
bufmap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>")
bufmap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<cr>")
bufmap("n", "go", "<cmd>lua vim.lsp.buf.type_definition()<cr>")
bufmap("n", "gr", "<cmd>lua vim.lsp.buf.references()<cr>")
bufmap("n", "gs", "<cmd>lua vim.lsp.buf.signature_help()<cr>")
bufmap("n", "<F2>", "<cmd>lua vim.lsp.buf.rename()<cr>")
bufmap({ "n", "x" }, "<F3>", "<cmd>lua vim.lsp.buf.format({async = true})<cr>")
bufmap("n", "<F4>", "<cmd>lua vim.lsp.buf.code_action()<cr>")
bufmap("n", "gl", "<cmd>lua vim.diagnostic.open_float()<cr>")
bufmap("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<cr>")
bufmap("n", "]d", "<cmd>lua vim.diagnostic.goto_next()<cr>")
end
return Plugin

10
lua/plugins/mason.lua Normal file
View file

@ -0,0 +1,10 @@
local Plugin = { "williamboman/mason.nvim" }
Plugin.lazy = false
-- See :help mason-settings
Plugin.opts = {
ui = { border = "rounded" },
}
return Plugin