better snippets, language management
This commit is contained in:
parent
67406d2af0
commit
20b058f034
4 changed files with 26 additions and 108 deletions
|
|
@ -10,109 +10,20 @@ function M.setup(config)
|
|||
|
||||
local s, i, fmt = ls.snippet, ls.insert_node, require("luasnip.extras.fmt").fmt
|
||||
|
||||
local filetype_to_language = {
|
||||
cc = "cpp",
|
||||
c = "cpp",
|
||||
py = "python",
|
||||
py3 = "python",
|
||||
}
|
||||
local languages = require("cp.languages")
|
||||
local filetype_to_language = languages.filetype_to_language
|
||||
|
||||
local language_to_filetype = {}
|
||||
for ext, lang in pairs(filetype_to_language) do
|
||||
language_to_filetype[lang] = ext
|
||||
end
|
||||
|
||||
local template_definitions = {
|
||||
cpp = {
|
||||
codeforces = [[#include <bits/stdc++.h>
|
||||
|
||||
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 <bits/stdc++.h>
|
||||
|
||||
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 <bits/stdc++.h>
|
||||
|
||||
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, filetype in pairs(language_to_filetype) do
|
||||
local snippets = {}
|
||||
|
||||
for contest, template in pairs(template_definitions[language] or {}) do
|
||||
table.insert(snippets, s(contest, fmt(template, { i(1) })))
|
||||
end
|
||||
|
||||
for _, snippet in ipairs(config.snippets or {}) do
|
||||
if snippet.filetype == filetype then
|
||||
table.insert(snippets, snippet)
|
||||
end
|
||||
table.insert(snippets, snippet)
|
||||
end
|
||||
|
||||
ls.add_snippets(filetype, snippets)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue