luasnip.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. local status, ls = pcall(require, "luasnip")
  2. if not status then
  3. return
  4. end
  5. local status, config = pcall(require, "uConfig")
  6. if not status then
  7. return
  8. end
  9. local status, types = pcall(require, "luasnip.util.types")
  10. if not status then
  11. vim.notify("not found luasnip util types")
  12. return
  13. end
  14. -- custom snippets
  15. require("luasnip.loaders.from_lua").load({
  16. paths = "./lua/cmp/snippets/lua",
  17. })
  18. require("luasnip.loaders.from_vscode").lazy_load({
  19. paths = "./lua/cmp/snippets/vscode",
  20. })
  21. -- https://github.com/rafamadriz/friendly-snippets/
  22. require("luasnip.loaders.from_vscode").lazy_load()
  23. ls.config.set_config({
  24. history = true,
  25. update_events = "TextChanged,TextChangedI",
  26. enable_autosnippets = true,
  27. ext_opts = {
  28. [types.choiceNode] = {
  29. active = {
  30. -- virt_text = { { "choiceNode", "Comment" } },
  31. virt_text = { { "<--", "Error" } },
  32. },
  33. },
  34. },
  35. })
  36. vim.keymap.set({ "i", "s" }, config.keys.snip_jump_next, function()
  37. if ls.expand_or_jumpable() then
  38. ls.expand_or_jump()
  39. end
  40. end)
  41. vim.keymap.set({ "i", "s" }, config.keys.snip_jump_prev, function()
  42. if ls.jumpable(-1) then
  43. ls.jump(-1)
  44. end
  45. end)
  46. vim.keymap.set({ "i", "s" }, config.keys.snip_next_choice, function()
  47. if ls.choice_active() then
  48. ls.change_choice(1)
  49. end
  50. end)
  51. vim.keymap.set({ "i", "s" }, config.keys.snip_prev_choice, function()
  52. if ls.choice_active() then
  53. ls.change_choice(-1)
  54. end
  55. end)