wip luasnip framework

master
spike 2 years ago
parent a068850c79
commit 9e5678036c

@ -1,37 +0,0 @@
priority -55
global !p
from vimsnippets import foldmarker, make_box, get_comment_format
endglobal
################
# ANSI Color Codes #
################
# The table starts with the original 16 colors (0-15).
# The proceeding 216 colors (16-231) or formed by a 3bpc RGB value offset by
# 16, packed into a single value.
# The final 24 colors (232-256) are grayscale
# starting from a shade slighly lighter than black, ranging up to shade slightly
# darker than white.
# Some emulators interpret these steps as linear
# increments from (256 / 24) on all three channels, although some emulators may
# explicitly define these values.
snippet ansi_fg "Foreground ANSI 256 Color Code" i
\033[38;5;${1:00}m
endsnippet
snippet ansi_bg "Background ANSI 256 Color Code" i
\033[48;5;${1:00}m
endsnippet
snippet ansi_reset "Reset ANSI 256 Color Code" i
\033[0m
endsnippet

@ -17,6 +17,9 @@ M.ui = {
theme = "monekai",
theme_toggle = { "monekai", "gruvbox_light" },
hl_override = {
Comment = {
fg = "light_grey"
},
CursorLine = {
bg = "one_bg3"
},
@ -109,9 +112,16 @@ M.ui = {
fg = "purple"
},
LuaSnipChoice = {
fg = "sun",
fg = "yellow",
bg = "one_bg3",
},
LuaSnipInsert = {
fg = "teal",
-- bg = "one_bg3",
},
NvimDapVirtualText = {
fg = '#f99540'
}
},
-- hl_override = {

@ -9,10 +9,16 @@ local types = require("luasnip.util.types")
local options = {
history = true,
updateevents = "TextChanged,TextChangedI",
enable_autosnippets = true,
ext_opts = {
[types.choiceNode] = {
passive = {
virt_text = { { "", "LuaSnipChoice" } },
virt_text = { { " ", "LuaSnipChoice" } },
}
},
[types.insertNode] = {
passive = {
virt_text = { { " ", "LuaSnipInsert" } },
}
}
},

@ -10,6 +10,7 @@ local config = {
keywords = {
["_TODO"] = { color = "warning"},
["LEARN"] = { color = "hint" },
["WIP"] = { color = "default"},
},
colors = {
info = {"#2563EB"},

@ -50,7 +50,7 @@ return {
local mode_sep1 = "%#" .. modes[m][2] .. "Sep" .. "#" .. sep_r
if is_dapmode() then
local dap_mode = "%#St_DapMode#DEBUG" .. "%#St_DapModeSep#"
local dap_mode = "%#St_DapMode#DAP" .. "%#St_DapModeSep#"
return current_mode .. mode_sep1 .. "%#St_DapModeSep2#" .. sep_r .. dap_mode .. sep_r
end

@ -16,6 +16,12 @@ local config = {
end,
desc = '[dap] conditional breakpoint',
},
X = {
rhs = function()
require('dap').clear_breakpoints()
end,
desc = '[dap] clear all breakpoints'
},
c = {
rhs = function()
require('dap').continue()
@ -86,16 +92,43 @@ local config = {
M.layer:exit()
end,
desc = '[dap] exit dap mode'
}
},
-- WIP: use which-key for key mappings help
-- ["?"] = {
-- rhs = function()
-- local wk = require("which-key")
-- wk.show("?", "n")
-- end
-- }
}
}
}
M.config = config
-- WIP: use which-key for key mappings help
-- local function wk_reg_keys()
-- local wk = require("which-key")
-- local wk_dapmode = {
-- name = "dap", -- section name
-- }
-- local wk_opts = {
-- mode = "n",
-- prefix = "?",
-- -- noremap = true,
-- }
-- for key, data in pairs(config.mappings.n) do
-- wk_dapmode[key] = { data.desc }
-- end
-- wk.register(wk_dapmode, wk_opts)
-- end
function M.start()
if M.layer == nil then
M.layer = libmodal.layer.new(config.mappings)
end
-- wk_reg_keys()
M.layer:enter()
end

@ -2,13 +2,13 @@ M = {}
M.shown = true
-- toggle diagnostics with show/hide
M.toggle_diagnostics = function ()
M.toggle = function ()
if M.shown then
M.shown = false
return vim.diagnostic.hide()
end
vim.diagnostic.show()
M.shown = true
vim.diagnostic.show()
end
-- my customized attach

@ -0,0 +1,33 @@
---@diagnostic disable: unused-local
local ls = require("luasnip")
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
local fmt = require("luasnip.extras.fmt").fmt
local rep = require("luasnip.extras").rep
-- local isn = ls.indent_snippet_node
-- local d = ls.dynamic_node
-- local r = ls.restore_node
-- local events = require("luasnip.util.events")
-- local ai = require("luasnip.nodes.absolute_indexer")
-- local extras = require("luasnip.extras")
-- local m = extras.m
-- local l = extras.l
-- local rep = extras.rep
-- local postfix = require("luasnip.extras.postfix").postfix
--
-- add_snippet helper
local add_snippet = require("spike.snips").add_snippet
--HACK: remove after testing snippets or it resets all imported snippets
-- require("luasnip.session.snippet_collection").clear_snippets "lua"
add_snippet {
lua = {
}
}

@ -0,0 +1,17 @@
local ok, ls = pcall(require, "luasnip")
if not ok then return end
-- luasnip helpers
local M = {}
---shortcut for ls.add_snippet(ft, {defs})
---@param args table arguments in the form {ft, snippet_defs}
M.add_snippet = function(args)
for ft,sn_defs in pairs(args) do
ls.add_snippets(ft, sn_defs, {override_priority=2000})
end
end
return M

@ -0,0 +1,20 @@
---@diagnostic disable: undefined-global
return {
-- s("sniptest", {
-- t"hello snippet"
-- })
--
-- choice nodes
s("choice", fmt("{} my {}",{
c(2, {t("hello"), t("hi")}),
c(1, {t"bob", t"alice"})
})
),
-- function node
s("pwd", f(function()
return vim.fn.getcwd()
end))
}

@ -0,0 +1,7 @@
---@diagnostic disable: unused-local, undefined-global
return {
-- s("testgo", {
-- t"Hello go snippet"
-- })
}

@ -0,0 +1,34 @@
---@diagnostic disable: undefined-global
return {
s("testluasnip", {
t"Hello lua snippet"
}),
-- repeat nodes
-- TODO: split dot and pull last name
s("req", fmt("local {} = require('{}')", {
i(1, "default"),
rep(1)
}) ),
s("ifreq", fmt([[
local ok, {} = pcall(require, "{}")
if not ok then
vim.notify("missing module {}", vim.log.levels.WARN)
return
end
{}
]], {
i(1),
rep(1),
rep(1),
i(0)
})
),
}
Loading…
Cancel
Save