diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 3375f00..75d62de 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -117,6 +117,7 @@ local function setup_problem(contest_id, problem_id, language) vim.cmd.startinsert({ bang = true }) vim.schedule(function() + print("Debug: platform=" .. state.platform .. ", filetype=" .. vim.bo.filetype .. ", expandable=" .. tostring(luasnip.expandable())) if luasnip.expandable() then luasnip.expand() end diff --git a/lua/cp/languages.lua b/lua/cp/languages.lua index e811211..c319cc3 100644 --- a/lua/cp/languages.lua +++ b/lua/cp/languages.lua @@ -13,7 +13,10 @@ M.filetype_to_language = { py3 = M.PYTHON, } ----@type string[] -M.all = { M.CPP, M.PYTHON } +---@type table +M.canonical_filetypes = { + [M.CPP] = "cpp", + [M.PYTHON] = "python", +} return M \ No newline at end of file diff --git a/lua/cp/snippets.lua b/lua/cp/snippets.lua index 8158a9a..1a3675c 100644 --- a/lua/cp/snippets.lua +++ b/lua/cp/snippets.lua @@ -15,17 +15,108 @@ function M.setup(config) local language_to_filetype = {} for ext, lang in pairs(filetype_to_language) do - language_to_filetype[lang] = ext + if not language_to_filetype[lang] then + language_to_filetype[lang] = ext + end end + local template_definitions = { + cpp = { + codeforces = [[#include - for language, filetype in pairs(language_to_filetype) do +using namespace std; + +void solve() {{ + {} +}} + +int main() {{ + std::cin.tie(nullptr)->sync_with_stdio(false); + + int tc = 1; + std::cin >> tc; + + for (int t = 0; t < tc; ++t) {{ + solve(); + }} + + return 0; +}}]], + + atcoder = [[#include + +using namespace std; + +void solve() {{ + {} +}} + +int main() {{ + std::cin.tie(nullptr)->sync_with_stdio(false); + +#ifdef LOCAL + int tc; + std::cin >> tc; + + for (int t = 0; t < tc; ++t) {{ + solve(); + }} +#else + solve(); +#endif + + return 0; +}}]], + + cses = [[#include + +using namespace std; + +int main() {{ + std::cin.tie(nullptr)->sync_with_stdio(false); + + {} + + return 0; +}}]], + }, + + python = { + codeforces = [[def solve(): + {} + +if __name__ == "__main__": + tc = int(input()) + for _ in range(tc): + solve()]], + + atcoder = [[def solve(): + {} + +if __name__ == "__main__": + solve()]], + + cses = [[{}]], + }, + } + + + for language, template_set in pairs(template_definitions) do local snippets = {} + local filetype = languages.canonical_filetypes[language] + + print("Processing language: " .. language .. " -> filetype: " .. filetype) + + for contest, template in pairs(template_set) do + print("Adding built-in snippet: " .. contest .. " for language: " .. language) + table.insert(snippets, s(contest, fmt(template, { i(1) }))) + end for _, snippet in ipairs(config.snippets or {}) do table.insert(snippets, snippet) end + print("Registering " .. #snippets .. " snippets for filetype: " .. filetype) ls.add_snippets(filetype, snippets) end end diff --git a/plugin/cp.lua b/plugin/cp.lua index a252fbf..f96db7f 100644 --- a/plugin/cp.lua +++ b/plugin/cp.lua @@ -14,7 +14,7 @@ end, { desc = "Competitive programming helper", complete = function(ArgLead, CmdLine, _) local languages_module = require("cp.languages") - local languages = languages_module.all + local languages = vim.tbl_keys(languages_module.canonical_filetypes) if ArgLead:match("^--lang=") then local lang_completions = {}