remaster
This commit is contained in:
parent
1b949bdb01
commit
a90ea1f671
18 changed files with 1361 additions and 1210 deletions
297
snippets/cs.lua
297
snippets/cs.lua
|
|
@ -1,178 +1,157 @@
|
|||
local ls = require 'luasnip'
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
local f = ls.function_node
|
||||
local c = ls.choice_node
|
||||
local d = ls.dynamic_node
|
||||
local r = ls.restore_node
|
||||
local fmt = require('luasnip.extras.fmt').fmt
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
|
||||
-- Configure snippet options
|
||||
local snippet_opts = {
|
||||
condition = function()
|
||||
return not ls.in_snippet()
|
||||
end,
|
||||
show_condition = function()
|
||||
return not ls.in_snippet()
|
||||
end
|
||||
}
|
||||
|
||||
return {
|
||||
-- Complete main setup
|
||||
s("main", fmt([[
|
||||
using System;
|
||||
|
||||
s(
|
||||
'cww',
|
||||
fmt('Console.WriteLine({});{}', {
|
||||
i(1, ''),
|
||||
i(0),
|
||||
})
|
||||
),
|
||||
namespace {};
|
||||
|
||||
s(
|
||||
'cw',
|
||||
fmt('Console.Write({});{}', {
|
||||
i(1, ''),
|
||||
i(0),
|
||||
})
|
||||
),
|
||||
class Program
|
||||
{{
|
||||
static void Main(string[] args)
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
}}
|
||||
]], { i(1, "MyApp"), i(2, 'Console.WriteLine("Hello, World!");') }), snippet_opts),
|
||||
|
||||
s(
|
||||
'do',
|
||||
fmt(
|
||||
[[
|
||||
do
|
||||
{{
|
||||
{}}} while ({});
|
||||
{}]],
|
||||
{
|
||||
i(2),
|
||||
i(1),
|
||||
i(0),
|
||||
}
|
||||
)
|
||||
),
|
||||
-- Namespace
|
||||
s("namespace", fmt([[
|
||||
namespace {};
|
||||
|
||||
s(
|
||||
'while',
|
||||
fmt(
|
||||
[[
|
||||
while ({})
|
||||
{{
|
||||
{}}}
|
||||
{}]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(0),
|
||||
}
|
||||
)
|
||||
),
|
||||
{}
|
||||
]], { i(1, "MyNamespace"), i(2) }), snippet_opts),
|
||||
|
||||
s(
|
||||
'fo',
|
||||
fmt(
|
||||
[[
|
||||
for (int {} = 0; {} < {}; {}++)
|
||||
{{
|
||||
{}}}
|
||||
{}]],
|
||||
{
|
||||
i(2, 'i'),
|
||||
f(function(args)
|
||||
return args[1][1]
|
||||
end, { 2 }),
|
||||
i(1, '1'),
|
||||
f(function(args)
|
||||
return args[1][1]
|
||||
end, { 2 }),
|
||||
i(3),
|
||||
i(0),
|
||||
}
|
||||
)
|
||||
),
|
||||
-- Class
|
||||
s("class", fmt([[
|
||||
public class {}
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "MyClass"), i(2) }), snippet_opts),
|
||||
|
||||
s(
|
||||
'forr',
|
||||
fmt(
|
||||
[[
|
||||
for (int {} = {} - 1; {} >= 0; {}--)
|
||||
{{
|
||||
{}}}
|
||||
{}]],
|
||||
{
|
||||
i(2, 'i'),
|
||||
i(1, 'length'),
|
||||
f(function(args)
|
||||
return args[1][1]
|
||||
end, { 2 }),
|
||||
f(function(args)
|
||||
return args[1][1]
|
||||
end, { 2 }),
|
||||
i(3),
|
||||
i(0),
|
||||
}
|
||||
)
|
||||
),
|
||||
-- Method
|
||||
s("method", fmt([[
|
||||
public {} {}({})
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "void"), i(2, "MyMethod"), i(3), i(4) }), snippet_opts),
|
||||
|
||||
s('cc', t 'Console.Clear();'),
|
||||
-- Property
|
||||
s("prop", fmt([[
|
||||
public {} {} {{ get; set; }}
|
||||
]], { i(1, "string"), i(2, "MyProperty") }), snippet_opts),
|
||||
|
||||
s('crk', t 'Console.ReadKey(true);'),
|
||||
-- Auto property with init
|
||||
s("propi", fmt([[
|
||||
public {} {} {{ get; init; }}
|
||||
]], { i(1, "string"), i(2, "MyProperty") }), snippet_opts),
|
||||
|
||||
s('crl', t 'Console.ReadLine();'),
|
||||
-- Constructor
|
||||
s("ctor", fmt([[
|
||||
public {}({})
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "ClassName"), i(2), i(3) }), snippet_opts),
|
||||
|
||||
s(
|
||||
'foreach',
|
||||
fmt(
|
||||
[[
|
||||
foreach ({})
|
||||
{{
|
||||
{}}}{}]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(0),
|
||||
}
|
||||
)
|
||||
),
|
||||
-- Interface
|
||||
s("interface", fmt([[
|
||||
public interface {}
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "IMyInterface"), i(2) }), snippet_opts),
|
||||
|
||||
s(
|
||||
'cla',
|
||||
fmt(
|
||||
[[
|
||||
class {}
|
||||
{{
|
||||
{}}}
|
||||
]],
|
||||
{
|
||||
i(1, 'ClassName'),
|
||||
i(0),
|
||||
}
|
||||
)
|
||||
),
|
||||
-- For loop
|
||||
s("for", fmt([[
|
||||
for (int {} = 0; {} < {}; {}++)
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "i"), i(1), i(2, "10"), i(1), i(3) }), snippet_opts),
|
||||
|
||||
s(
|
||||
'inter',
|
||||
fmt(
|
||||
[[
|
||||
interface {}
|
||||
{{
|
||||
{}}}
|
||||
]],
|
||||
{
|
||||
i(1, 'IInterfaceName'),
|
||||
i(0),
|
||||
}
|
||||
)
|
||||
),
|
||||
-- Foreach loop
|
||||
s("foreach", fmt([[
|
||||
foreach ({} {} in {})
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "var"), i(2, "item"), i(3, "collection"), i(4) }), snippet_opts),
|
||||
|
||||
s(
|
||||
'enu',
|
||||
fmt(
|
||||
[[
|
||||
enum {}
|
||||
{{
|
||||
{}}}
|
||||
]],
|
||||
{
|
||||
i(1, 'EnumName'),
|
||||
i(0),
|
||||
}
|
||||
)
|
||||
),
|
||||
-- If statement
|
||||
s("if", fmt([[
|
||||
if ({})
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "condition"), i(2) }), snippet_opts),
|
||||
|
||||
s('comment', {
|
||||
t { '/*', '' },
|
||||
i(1),
|
||||
t { '', '*/' },
|
||||
}),
|
||||
}
|
||||
-- Console.WriteLine
|
||||
s("cw", fmt([[
|
||||
Console.WriteLine({});
|
||||
]], { i(1, '"Hello"') }), snippet_opts),
|
||||
|
||||
-- Console.Write
|
||||
s("cwn", fmt([[
|
||||
Console.Write({});
|
||||
]], { i(1, '"Hello"') }), snippet_opts),
|
||||
|
||||
-- Try-catch
|
||||
s("try", fmt([[
|
||||
try
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
catch ({})
|
||||
{{
|
||||
{}
|
||||
}}
|
||||
]], { i(1), i(2, "Exception ex"), i(3, "throw;") }), snippet_opts),
|
||||
|
||||
-- Variable declaration
|
||||
s("var", fmt([[
|
||||
var {} = {};
|
||||
]], { i(1, "name"), i(2, "value") }), snippet_opts),
|
||||
|
||||
-- String variable
|
||||
s("string", fmt([[
|
||||
string {} = {};
|
||||
]], { i(1, "name"), i(2, '""') }), snippet_opts),
|
||||
|
||||
-- Record
|
||||
s("record", fmt([[
|
||||
public record {}({});
|
||||
]], { i(1, "MyRecord"), i(2, "string Name") }), snippet_opts),
|
||||
|
||||
-- List declaration
|
||||
s("list", fmt([[
|
||||
List<{}> {} = [{}];
|
||||
]], { i(1, "string"), i(2, "list"), i(3) }), snippet_opts),
|
||||
|
||||
-- Dictionary declaration
|
||||
s("dict", fmt([[
|
||||
Dictionary<{}, {}> {} = [];
|
||||
]], { i(1, "string"), i(2, "string"), i(3, "dict") }), snippet_opts),
|
||||
|
||||
-- Array declaration
|
||||
s("array", fmt([[
|
||||
{}[] {} = [{}];
|
||||
]], { i(1, "string"), i(2, "array"), i(3) }), snippet_opts),
|
||||
}
|
||||
126
snippets/go.lua
Normal file
126
snippets/go.lua
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
|
||||
-- Configure snippet options
|
||||
local snippet_opts = {
|
||||
condition = function()
|
||||
return not ls.in_snippet()
|
||||
end,
|
||||
show_condition = function()
|
||||
return not ls.in_snippet()
|
||||
end
|
||||
}
|
||||
|
||||
return {
|
||||
-- Complete main setup
|
||||
s("main", fmt([[
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, 'fmt.Println("Hello, World!")') }), snippet_opts),
|
||||
|
||||
-- Package declaration
|
||||
s("pkg", fmt([[
|
||||
package {}
|
||||
]], { i(1, "main") }), snippet_opts),
|
||||
|
||||
-- Function
|
||||
s("func", fmt([[
|
||||
func {}({}) {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "name"), i(2), i(3) }), snippet_opts),
|
||||
|
||||
-- Function with return
|
||||
s("funcr", fmt([[
|
||||
func {}() {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "name"), i(2, "string"), i(3, 'return ""') }), snippet_opts),
|
||||
|
||||
-- If error
|
||||
s("iferr", fmt([[
|
||||
if err != nil {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "return err") }), snippet_opts),
|
||||
|
||||
-- For loop
|
||||
s("for", fmt([[
|
||||
for {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "i := 0; i < 10; i++"), i(2) }), snippet_opts),
|
||||
|
||||
-- Printf
|
||||
s("pf", fmt([[
|
||||
fmt.Printf("{}\n", {})
|
||||
]], { i(1, "%v"), i(2, "value") }), snippet_opts),
|
||||
|
||||
-- Println
|
||||
s("pl", fmt([[
|
||||
fmt.Println({})
|
||||
]], { i(1, '"Hello"') }), snippet_opts),
|
||||
|
||||
-- Variable declaration
|
||||
s("var", fmt([[
|
||||
var {} {}
|
||||
]], { i(1, "name"), i(2, "string") }), snippet_opts),
|
||||
|
||||
-- Short variable declaration
|
||||
s(":=", fmt([[
|
||||
{} := {}
|
||||
]], { i(1, "name"), i(2, "value") }), snippet_opts),
|
||||
|
||||
-- Struct
|
||||
s("struct", fmt([[
|
||||
type {} struct {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "Name"), i(2, "Field string") }), snippet_opts),
|
||||
|
||||
-- Interface
|
||||
s("interface", fmt([[
|
||||
type {} interface {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "Name"), i(2, "Method()") }), snippet_opts),
|
||||
|
||||
-- Test function
|
||||
s("test", fmt([[
|
||||
func Test{}(t *testing.T) {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "Name"), i(2) }), snippet_opts),
|
||||
|
||||
-- Method
|
||||
s("method", fmt([[
|
||||
func ({} *{}) {}() {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "r"), i(2, "Receiver"), i(3, "Method"), i(4) }), snippet_opts),
|
||||
|
||||
-- Goroutine
|
||||
s("go", fmt([[
|
||||
go func() {{
|
||||
{}
|
||||
}}()
|
||||
]], { i(1) }), snippet_opts),
|
||||
|
||||
-- Channel
|
||||
s("chan", fmt([[
|
||||
{} := make(chan {})
|
||||
]], { i(1, "ch"), i(2, "string") }), snippet_opts),
|
||||
|
||||
-- Defer
|
||||
s("defer", fmt([[
|
||||
defer {}
|
||||
]], { i(1, "cleanup()") }), snippet_opts),
|
||||
}
|
||||
180
snippets/rust.lua
Normal file
180
snippets/rust.lua
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
|
||||
-- Configure snippet options
|
||||
local snippet_opts = {
|
||||
condition = function()
|
||||
return not ls.in_snippet()
|
||||
end,
|
||||
show_condition = function()
|
||||
return not ls.in_snippet()
|
||||
end
|
||||
}
|
||||
|
||||
return {
|
||||
-- Complete main setup
|
||||
s("main", fmt([[
|
||||
fn main() {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, 'println!("Hello, World!");') }), snippet_opts),
|
||||
|
||||
-- Function
|
||||
s("fn", fmt([[
|
||||
fn {}({}) {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "name"), i(2), i(3) }), snippet_opts),
|
||||
|
||||
-- Function with return
|
||||
s("fnr", fmt([[
|
||||
fn {}({}) -> {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "name"), i(2), i(3, "()"), i(4) }), snippet_opts),
|
||||
|
||||
-- Struct
|
||||
s("struct", fmt([[
|
||||
struct {} {{
|
||||
{}: {},
|
||||
}}
|
||||
]], { i(1, "Name"), i(2, "field"), i(3, "String") }), snippet_opts),
|
||||
|
||||
-- Enum
|
||||
s("enum", fmt([[
|
||||
enum {} {{
|
||||
{},
|
||||
}}
|
||||
]], { i(1, "Name"), i(2, "Variant") }), snippet_opts),
|
||||
|
||||
-- Implementation
|
||||
s("impl", fmt([[
|
||||
impl {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "Name"), i(2) }), snippet_opts),
|
||||
|
||||
-- Trait
|
||||
s("trait", fmt([[
|
||||
trait {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "Name"), i(2) }), snippet_opts),
|
||||
|
||||
-- Match statement
|
||||
s("match", fmt([[
|
||||
match {} {{
|
||||
{} => {},
|
||||
_ => {},
|
||||
}}
|
||||
]], { i(1, "value"), i(2, "pattern"), i(3), i(4) }), snippet_opts),
|
||||
|
||||
-- If let
|
||||
s("iflet", fmt([[
|
||||
if let {} = {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "Some(value)"), i(2, "option"), i(3) }), snippet_opts),
|
||||
|
||||
-- For loop
|
||||
s("for", fmt([[
|
||||
for {} in {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "item"), i(2, "iterator"), i(3) }), snippet_opts),
|
||||
|
||||
-- While loop
|
||||
s("while", fmt([[
|
||||
while {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "condition"), i(2) }), snippet_opts),
|
||||
|
||||
-- Loop
|
||||
s("loop", fmt([[
|
||||
loop {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1) }), snippet_opts),
|
||||
|
||||
-- If statement
|
||||
s("if", fmt([[
|
||||
if {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "condition"), i(2) }), snippet_opts),
|
||||
|
||||
-- Variable declaration
|
||||
s("let", fmt([[
|
||||
let {} = {};
|
||||
]], { i(1, "name"), i(2, "value") }), snippet_opts),
|
||||
|
||||
-- Mutable variable
|
||||
s("letm", fmt([[
|
||||
let mut {} = {};
|
||||
]], { i(1, "name"), i(2, "value") }), snippet_opts),
|
||||
|
||||
-- Print
|
||||
s("print", fmt([[
|
||||
println!("{}", {});
|
||||
]], { i(1, "{}"), i(2, "value") }), snippet_opts),
|
||||
|
||||
-- Debug print
|
||||
s("dbg", fmt([[
|
||||
dbg!({});
|
||||
]], { i(1, "value") }), snippet_opts),
|
||||
|
||||
-- Vector
|
||||
s("vec", fmt([[
|
||||
let {} = vec![{}];
|
||||
]], { i(1, "name"), i(2) }), snippet_opts),
|
||||
|
||||
-- HashMap
|
||||
s("hashmap", fmt([[
|
||||
let mut {} = HashMap::new();
|
||||
]], { i(1, "map") }), snippet_opts),
|
||||
|
||||
-- Result match
|
||||
s("result", fmt([[
|
||||
match {} {{
|
||||
Ok({}) => {},
|
||||
Err({}) => {},
|
||||
}}
|
||||
]], { i(1, "result"), i(2, "value"), i(3), i(4, "err"), i(5) }), snippet_opts),
|
||||
|
||||
-- Option match
|
||||
s("option", fmt([[
|
||||
match {} {{
|
||||
Some({}) => {},
|
||||
None => {},
|
||||
}}
|
||||
]], { i(1, "option"), i(2, "value"), i(3), i(4) }), snippet_opts),
|
||||
|
||||
-- Test function
|
||||
s("test", fmt([[
|
||||
#[test]
|
||||
fn test_{}() {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "name"), i(2) }), snippet_opts),
|
||||
|
||||
-- Derive
|
||||
s("derive", fmt([[
|
||||
#[derive({})]
|
||||
]], { i(1, "Debug, Clone") }), snippet_opts),
|
||||
|
||||
-- Module
|
||||
s("mod", fmt([[
|
||||
mod {} {{
|
||||
{}
|
||||
}}
|
||||
]], { i(1, "name"), i(2) }), snippet_opts),
|
||||
|
||||
-- Use statement
|
||||
s("use", fmt([[
|
||||
use {};
|
||||
]], { i(1, "std::collections::HashMap") }), snippet_opts),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue