feat: fix luasnip integration
This commit is contained in:
parent
5417da9b52
commit
fe3401048a
2 changed files with 24 additions and 13 deletions
|
|
@ -112,21 +112,21 @@ local function setup_problem(contest_id, problem_id, language)
|
||||||
if vim.api.nvim_buf_get_lines(0, 0, -1, true)[1] == "" then
|
if vim.api.nvim_buf_get_lines(0, 0, -1, true)[1] == "" then
|
||||||
local has_luasnip, luasnip = pcall(require, "luasnip")
|
local has_luasnip, luasnip = pcall(require, "luasnip")
|
||||||
if has_luasnip then
|
if has_luasnip then
|
||||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, { state.platform })
|
local languages = require("cp.languages")
|
||||||
vim.api.nvim_win_set_cursor(0, { 1, #state.platform })
|
local file_ext = vim.fn.expand("%:e")
|
||||||
|
local language = languages.filetype_to_language[file_ext] or "cpp"
|
||||||
|
local prefixed_trigger = ("cp.nvim/%s.%s"):format(state.platform, language)
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_lines(0, 0, -1, false, { prefixed_trigger })
|
||||||
|
vim.api.nvim_win_set_cursor(0, { 1, #prefixed_trigger })
|
||||||
vim.cmd.startinsert({ bang = true })
|
vim.cmd.startinsert({ bang = true })
|
||||||
|
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
print(
|
|
||||||
"Debug: platform="
|
|
||||||
.. state.platform
|
|
||||||
.. ", filetype="
|
|
||||||
.. vim.bo.filetype
|
|
||||||
.. ", expandable="
|
|
||||||
.. tostring(luasnip.expandable())
|
|
||||||
)
|
|
||||||
if luasnip.expandable() then
|
if luasnip.expandable() then
|
||||||
luasnip.expand()
|
luasnip.expand()
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_set_lines(0, 0, 1, false, { "" })
|
||||||
|
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
||||||
end
|
end
|
||||||
vim.cmd.stopinsert()
|
vim.cmd.stopinsert()
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -100,16 +100,27 @@ if __name__ == "__main__":
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local user_overrides = {}
|
||||||
|
for _, snippet in ipairs(config.snippets or {}) do
|
||||||
|
user_overrides[snippet.trigger] = snippet
|
||||||
|
end
|
||||||
|
|
||||||
for language, template_set in pairs(template_definitions) do
|
for language, template_set in pairs(template_definitions) do
|
||||||
local snippets = {}
|
local snippets = {}
|
||||||
local filetype = languages.canonical_filetypes[language]
|
local filetype = languages.canonical_filetypes[language]
|
||||||
|
|
||||||
for contest, template in pairs(template_set) do
|
for contest, template in pairs(template_set) do
|
||||||
table.insert(snippets, s(contest, fmt(template, { i(1) })))
|
local prefixed_trigger = ("cp.nvim/%s.%s"):format(contest, language)
|
||||||
|
if not user_overrides[prefixed_trigger] then
|
||||||
|
table.insert(snippets, s(prefixed_trigger, fmt(template, { i(1) })))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, snippet in ipairs(config.snippets or {}) do
|
for trigger, snippet in pairs(user_overrides) do
|
||||||
table.insert(snippets, snippet)
|
local prefix_match = trigger:match("^cp%.nvim/[^.]+%.(.+)$")
|
||||||
|
if prefix_match == language then
|
||||||
|
table.insert(snippets, snippet)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ls.add_snippets(filetype, snippets)
|
ls.add_snippets(filetype, snippets)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue