Skip to content

Commit 993f9e2

Browse files
committed
feat: neogen and some snippet stuff.
1 parent c9a56e6 commit 993f9e2

File tree

9 files changed

+185
-30
lines changed

9 files changed

+185
-30
lines changed

_after/plugin/lsp.lua

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
local lsp = require("lsp-zero")
22

3-
local function attach(opts)
4-
5-
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
6-
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
7-
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
8-
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
9-
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
10-
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
11-
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
12-
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
13-
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
14-
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
15-
end
16-
173
lsp.preset("recommended")
184

195
lsp.ensure_installed({
@@ -25,18 +11,6 @@ lsp.ensure_installed({
2511
lsp.nvim_workspace()
2612

2713

28-
local cmp = require('cmp')
29-
local cmp_select = {behavior = cmp.SelectBehavior.Select}
30-
local cmp_mappings = lsp.defaults.cmp_mappings({
31-
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
32-
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
33-
['<C-y>'] = cmp.mapping.confirm({ select = true }),
34-
["<C-Space>"] = cmp.mapping.complete(),
35-
})
36-
37-
cmp_mappings['<Tab>'] = nil
38-
cmp_mappings['<S-Tab>'] = nil
39-
4014
lsp.setup_nvim_cmp({
4115
mapping = cmp_mappings
4216
})

lazy-lock.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
2+
"LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" },
23
"cellular-automaton.nvim": { "branch": "main", "commit": "b7d056dab963b5d3f2c560d92937cb51db61cb5b" },
34
"cloak.nvim": { "branch": "main", "commit": "951b163e55ce7639eb320c450bde9283c4fe968b" },
5+
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
6+
"cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" },
7+
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
8+
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
9+
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
410
"copilot.vim": { "branch": "release", "commit": "5b19fb001d7f31c4c7c5556d7a97b243bd29f45f" },
11+
"fidget.nvim": { "branch": "main", "commit": "a4a7edfea37e557dbff5509ee374ffb57051bba9" },
12+
"friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" },
513
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
14+
"mason-lspconfig.nvim": { "branch": "main", "commit": "56e435e09f8729af2d41973e81a0db440f8fe9c9" },
15+
"mason.nvim": { "branch": "main", "commit": "a09da6ac634926a299dd439da08bdb547a8ca011" },
16+
"neogen": { "branch": "main", "commit": "70127baaff25611deaf1a29d801fc054ad9d2dc1" },
17+
"nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" },
18+
"nvim-lspconfig": { "branch": "master", "commit": "ce0e625df61be77abe1340fbc9afe9ad39b31dd8" },
619
"nvim-treesitter": { "branch": "master", "commit": "e49f1e8ef3e8450a8446cb1f2bbb53c919f60b6d" },
720
"plenary": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },
821
"plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },

lua/theprimeagen/init.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ autocmd({"BufWritePre"}, {
4747
command = [[%s/\s\+$//e]],
4848
})
4949

50+
autocmd('LspAttach', {
51+
group = ThePrimeagenGroup,
52+
callback = function(e)
53+
local opts = { buffer = e.buf }
54+
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
55+
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
56+
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
57+
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
58+
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
59+
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
60+
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
61+
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
62+
end
63+
})
64+
5065
vim.g.netrw_browse_split = 0
5166
vim.g.netrw_banner = 0
5267
vim.g.netrw_winsize = 25

lua/theprimeagen/lazy/lsp.lua

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
return {
2+
"neovim/nvim-lspconfig",
3+
dependencies = {
4+
"williamboman/mason.nvim",
5+
"williamboman/mason-lspconfig.nvim",
6+
"hrsh7th/cmp-nvim-lsp",
7+
"hrsh7th/cmp-buffer",
8+
"hrsh7th/cmp-path",
9+
"hrsh7th/cmp-cmdline",
10+
"hrsh7th/nvim-cmp",
11+
"L3MON4D3/LuaSnip",
12+
"saadparwaiz1/cmp_luasnip",
13+
"j-hui/fidget.nvim",
14+
},
15+
16+
config = function()
17+
local cmp = require('cmp')
18+
local cmp_lsp = require("cmp_nvim_lsp")
19+
local capabilities = vim.tbl_deep_extend(
20+
"force",
21+
{},
22+
vim.lsp.protocol.make_client_capabilities(),
23+
cmp_lsp.default_capabilities())
24+
25+
require("fidget").setup({})
26+
require("mason").setup()
27+
require("mason-lspconfig").setup({
28+
ensure_installed = {
29+
"lua_ls",
30+
"rust_analyzer",
31+
"tsserver",
32+
},
33+
handlers = {
34+
function(server_name) -- default handler (optional)
35+
36+
require("lspconfig")[server_name].setup {
37+
capabilities = capabilities
38+
}
39+
end,
40+
41+
["lua_ls"] = function()
42+
local lspconfig = require("lspconfig")
43+
lspconfig.lua_ls.setup {
44+
capabilities = capabilities,
45+
settings = {
46+
Lua = {
47+
diagnostics = {
48+
globals = { "vim" }
49+
}
50+
}
51+
}
52+
}
53+
end,
54+
}
55+
})
56+
57+
local cmp_select = { behavior = cmp.SelectBehavior.Select }
58+
59+
cmp.setup({
60+
snippet = {
61+
expand = function(args)
62+
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
63+
end,
64+
},
65+
mapping = cmp.mapping.preset.insert({
66+
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
67+
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
68+
['<C-y>'] = cmp.mapping.confirm({ select = true }),
69+
["<C-Space>"] = cmp.mapping.complete(),
70+
}),
71+
sources = cmp.config.sources({
72+
{ name = 'nvim_lsp' },
73+
{ name = 'luasnip' }, -- For luasnip users.
74+
}, {
75+
{ name = 'buffer' },
76+
})
77+
})
78+
79+
vim.diagnostic.config({
80+
update_in_insert = true,
81+
float = {
82+
focusable = false,
83+
style = "minimal",
84+
border = "rounded",
85+
source = "always",
86+
header = "",
87+
prefix = "",
88+
},
89+
})
90+
end
91+
}

lua/theprimeagen/lazy/neogen.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
return {
2+
"danymat/neogen",
3+
dependencies = {
4+
"nvim-treesitter/nvim-treesitter",
5+
"L3MON4D3/LuaSnip",
6+
},
7+
config = function()
8+
local neogen = require("neogen")
9+
10+
neogen.setup({
11+
snippet_engine = "luasnip"
12+
})
13+
14+
vim.keymap.set("n", "<leader>nf", function()
15+
neogen.generate({ type = "func" })
16+
end)
17+
18+
vim.keymap.set("n", "<leader>nt", function()
19+
neogen.generate({ type = "type" })
20+
end)
21+
22+
vim.keymap.set("n", "<leader>nd", function()
23+
neogen.generate({ type = "typedef" })
24+
end)
25+
end,
26+
-- Uncomment next line if you want to follow only stable versions
27+
-- version = "*"
28+
}
29+

lua/theprimeagen/lazy/snippets.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
return {
3+
{
4+
"L3MON4D3/LuaSnip",
5+
-- follow latest release.
6+
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
7+
-- install jsregexp (optional!).
8+
build = "make install_jsregexp",
9+
10+
dependencies = { "rafamadriz/friendly-snippets" },
11+
12+
config = function()
13+
local ls = require("luasnip")
14+
ls.filetype_extend("javascript", { "jsdoc" })
15+
16+
--- TODO: What is expand?
17+
vim.keymap.set({"i"}, "<C-K>", function() ls.expand() end, {silent = true})
18+
19+
vim.keymap.set({"i", "s"}, "<leader>;", function() ls.jump(1) end, {silent = true})
20+
vim.keymap.set({"i", "s"}, "<leader>,", function() ls.jump(-1) end, {silent = true})
21+
22+
vim.keymap.set({"i", "s"}, "<C-E>", function()
23+
if ls.choice_active() then
24+
ls.change_choice(1)
25+
end
26+
end, {silent = true})
27+
end,
28+
}
29+
}
30+

lua/theprimeagen/lazy/treesitter.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ return {
44
config = function()
55
require("nvim-treesitter.configs").setup({
66
-- A list of parser names, or "all"
7-
ensure_installed = { "vimdoc", "javascript", "typescript", "c", "lua", "rust" },
7+
ensure_installed = {
8+
"vimdoc", "javascript", "typescript", "c", "lua", "rust",
9+
"jsdoc",
10+
},
811

912
-- Install parsers synchronously (only applied to `ensure_installed`)
1013
sync_install = false,

lua/theprimeagen/lazy/trouble.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ return {
1010
require("trouble").toggle()
1111
end)
1212

13-
vim.keymap.set("n", "<leader>tn", function()
13+
vim.keymap.set("n", "[d", function()
1414
require("trouble").next({skip_groups = true, jump = true});
1515
end)
1616

17-
vim.keymap.set("n", "<leader>tp", function()
17+
vim.keymap.set("n", "]d", function()
1818
require("trouble").previous({skip_groups = true, jump = true});
1919
end)
2020

lua/theprimeagen/lazy/zenmode.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
return {
33
"folke/zen-mode.nvim",
4-
config = function()
4+
config = function()
55
vim.keymap.set("n", "<leader>zz", function()
66
require("zen-mode").setup {
77
window = {

0 commit comments

Comments
 (0)