aboutsummaryrefslogtreecommitdiff
path: root/lua/user/luasnip.lua
blob: 12352e887137b165476b3ca46f9af9a76bcd3b0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
if vim.g.snippets ~= "luasnip" or not pcall(require, "luasnip") then
  return
end
--local luasnip = require("luasnip")
local ls = require "luasnip" --
local types = require "luasnip.util.types" --
local options = {
  history = true,
  updateevents = "TextChanged,TextChangedI",
  -- Autosnippets:
  enable_autosnippets = true, --
  ext_opts = { --
    [types.choiceNode] = { --
      active = { --
        virt_text = { { " « ", "NonTest" } }, --
      }, --
    }, --
  }, --
}
-- <c-k> is my expansion key
-- this will expand the current item or jump to the next item within the snippet.
vim.keymap.set({ "i", "s" }, "<c-.>", function()
  if ls.expand_or_jumpable() then
    ls.expand_or_jump()
  end
end, { silent = true })

-- <c-j> is my jump backwards key.
-- this always moves to the previous item within the snippet
vim.keymap.set({ "i", "s" }, "<c-,>", function()
  if ls.jumpable(-1) then
    ls.jump(-1)
  end
end, { silent = true })

-- <c-l> is selecting within a list of options.
-- This is useful for choice nodes (introduced in the forthcoming episode 2)
vim.keymap.set("i", "<c-l>", function()
  if ls.choice_active() then
    ls.change_choice(1)
  end
end)

vim.keymap.set("i", "<c-c>", require "luasnip.extras.select_choice")

-- shorcut to source my luasnips file again, which will reload my snippets
vim.keymap.set("n", "<leader><leader>s", "<cmd>source ~/.config/nvim/lua/plugins/luasnip.lua<CR>")

-- ls.parser.parse_snippet(<text>, <VS**** style snippet>)
ls.snippets = {
  all = {
    -- Available in any filetype
    ls.parser.parse_snippet("expand", "-- this is what was expanded!"),
  },
  lua = {
    -- Lua specific snippets go here.
  },
}




--luasnip.config.set_config(options)
--require("luasnip.loaders.from_vscode").lazy_load()
--require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.luasnippets_path or "" }
--
--vim.api.nvim_create_autocmd("InsertLeave", {
--  callback = function()
--    if
--      require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()]
--      and not require("luasnip").session.jump_active
--    then
--      require("luasnip").unlink_current()
--    end
--  end,
--})