1
0

FEAT: Adding trouble and started luasnippets

TODO: Fix compe to show snippets available in insert mode
This commit is contained in:
Nigel Barink 2024-03-30 16:47:37 +01:00
parent 58158ed5ef
commit a2b76f8aef
Signed by: Nigel
GPG Key ID: 6893A31C2D84A9D2
5 changed files with 57 additions and 3 deletions

View File

@ -1,5 +1,5 @@
{
"LuaSnip": { "branch": "master", "commit": "a7a4b4682c4b3e2ba82b82a4e6e5f5a0e79dec32" },
"LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
@ -22,6 +22,7 @@
"telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" },
"telescope.nvim": { "branch": "master", "commit": "b22e6f6896cd64b109bd0807a24098d225d5fb49" },
"tokyonight.nvim": { "branch": "main", "commit": "71597b108aea89362fc99d7a5e78bba2f9870bf6" },
"trouble.nvim": { "branch": "main", "commit": "b9cf677f20bb2faa2dacfa870b084e568dca9572" },
"undotree": { "branch": "master", "commit": "aa93a7e5890dbbebbc064cd22260721a6db1a196" },
"vim-fugitive": { "branch": "master", "commit": "2377e16e6641418565b934990cf49068855987c6" }
}

View File

@ -9,7 +9,11 @@ return
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"hrsh7th/nvim-cmp",
'L3MON4D3/LuaSnip',
{
'L3MON4D3/LuaSnip',
dependencies = 'hrsh7th/nvim-cmp',
version = "v2.*",
},
{'mfussenegger/nvim-jdtls', dependencies = {'nvim-dap'}},
},
config = function()
@ -34,7 +38,7 @@ return
sources = cmp.config.sources({
{ name = 'path' },
{ name = 'nvim_lsp', keyword_length = 1 },
{ name = 'luasnip', keyword_length = 3},
{ name = 'luasnip', option = { show_autosnippets = true}},
}, {
{ name = 'buffer', keyword_length = 2 },
}),
@ -83,6 +87,23 @@ return
}
}
})
local ls = require("luasnip")
ls.config.set_config({
history = true,
updateevents = "TextChanged, TextChangedI",
enable_autosnippets = true,
})
vim.keymap.set({"i", "s"}, "<C-K>", function() ls.expand() end, {silent = true})
vim.keymap.set({"i", "s"}, "<C-L>", function() ls.jump(1) end, {silent = true })
vim.keymap.set({"i", "s"}, "<C-J>", function() ls.jump(-1) end, {silent = true})
vim.keymap.set({"i", "s"}, "<C-E>", function()
if ls.choice_active() then
ls.change_choice(1)
end
end, {silent = true})
require("luasnip.loaders.from_lua").load({paths= "C:\\Users\\nigel\\AppData\\Local\\nvim\\lua\\snippets"})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
@ -109,3 +130,4 @@ return
end
}

View File

@ -0,0 +1,5 @@
return {
"folke/trouble.nvim",
config = function ()
end
}

15
lua/snippets/all.lua Normal file
View File

@ -0,0 +1,15 @@
local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
-- https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md
return {
s("novel", {
t("It was a dark and stormy night on")
}),
s("no", {
t("hello world!")
}),
}

11
lua/snippets/lua.lua Normal file
View File

@ -0,0 +1,11 @@
local ls = require("luasnip")
local s = ls.snippet
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt
-- https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md
return {
s("req", fmt("local {} = require('{}')", { i(1, "default"), require("luasnip.extras").rep(1)}))
}