This commit is contained in:
Chris
2025-12-18 09:18:00 +00:00
parent 4d3aada204
commit 4f8e722f13
2 changed files with 140 additions and 57 deletions

View File

@@ -1,45 +1,128 @@
local ls = require 'luasnip'
local s = ls.snippet
local sn = ls.snippet_node
local fn = ls.function_node
local ms = ls.multi_snippet
local t = ls.text_node
local c = ls.choice_node
local i = ls.insert_node
local f = ls.function_node
local d = ls.dynamic_node
local fmt = require('luasnip.extras.fmt').fmt
local rep = require('luasnip.extras').rep
local extend_decorator = require 'luasnip.util.extend_decorator'
local fmta = extend_decorator.apply(fmt, { delimiters = '#~' })
local utils = require 'snippets.snip_utils'
local tr = utils.tr
local etr = utils.etr
local atr = utils.atr
local ctr = utils.ctr
local bs = utils.bs
return {
s('du', { t 'console.log(', i(0), t ');' }),
s(etr('du ', 'Dump a variable to the console'), fmta('console.log(#~);', { i(0) })),
s(
etr('vue', 'Vue Single File Component skeleton'),
fmta(
[[
<template>
</template>
<script setup>
#~
</script>
<style scoped>
</style>
]],
{ i(0) }
)
),
s('vue', {
t { '<template>', '' },
t { '', '</template>', '', '', '<script setup>', '' },
i(0),
t { '', '</script>', '', '', '<style scoped>', '', '.o-share-page {', '}', '', '</style>' },
bs(atr('t ', 'this'), fmta('this.#~', { i(0) })),
s(etr('return ', 'Add semicolon after return'), fmta('return #~;', { i(0) })),
s(etr('rt ', 'return alias'), fmta('return #~;', { i(0) })),
s(etr('const', 'const declaration'), {
c(1, {
sn(nil, fmta('const #~ = #~;', { i(1, 'variableName'), i(2, 'value') })),
sn(
nil,
fmta(
[[
const #~ = (#~) => {
#~
}
]],
{ i(1), i(2), i(3) }
)
),
}),
}),
s('fun', {
t 'function ',
i(1),
t '(',
i(2),
t ') {',
t { '', ' ' },
i(0),
t { '', '}' },
s(
etr('fn ', 'function block'),
fmta(
[[
function #~(#~) {
#~
}
]],
{ i(1), i(2), i(0) }
)
),
bs(atr('fn ', 'function block'), {
c(1, {
sn(
nil,
fmta(
[[
(#~) => {
#~
}
]],
{ i(1), i(2) }
)
),
sn(
nil,
fmta(
[[
function (#~) {
#~
}
]],
{ i(1), i(2) }
)
),
}),
}),
s('afun', {
t 'async function ',
i(1),
t '(',
i(2),
t ') {',
t { '', ' ' },
i(0),
t { '', '}' },
bs(atr('afn ', 'async function block'), {
c(1, {
sn(
nil,
fmta(
[[
async (#~) => {
#~
}
]],
{ i(1), i(2) }
)
),
sn(
nil,
fmta(
[[
async function (#~) {
#~
}
]],
{ i(1), i(2) }
)
),
}),
s('()', {
t '() => {',
t { '', ' ' },
i(0),
t { '', '}' },
}),
}

View File

@@ -170,7 +170,7 @@ return {
s(etr('return ', 'Add semicolon after return'), fmta('return #~;', { i(0) })),
s(atr(' use ', 'Add use to function'), fmta(' use (#~)', { i(0) })),
s(etr('rt ', 'return alias'), fmta('return #~;', { i(0) })),
bs(etr('fn ', 'Shorthand function block'), {
bs(atr('fn ', 'Shorthand function block'), {
c(1, {
sn(nil, fmta('fn (#~) => #~', { i(1), i(2) })),
sn(
@@ -186,7 +186,7 @@ return {
),
}),
}),
bs(etr('fun ', 'Shorthand function block'), {
bs(atr('fun ', 'Shorthand function block'), {
c(1, {
sn(
nil,
@@ -371,7 +371,7 @@ return {
-------------
s(
etr('bt', 'belongsTo Laravel relationship method'),
c(0, {
c(1, {
sn(
nil,
fmta(
@@ -384,7 +384,7 @@ return {
return $this->belongsTo(#~::class);
}
]],
{ rep(1), i(0), i(1) }
{ rep(1), i(2), i(1) }
)
),
sn(
@@ -399,14 +399,14 @@ return {
return $this->belongsTo(#~::class, #~);
}
]],
{ rep(1), i(2), i(1), i(0) }
{ rep(1), i(2), i(1), i(3) }
)
),
})
),
s(
etr('hm', 'hasMany Laravel relationship method'),
c(0, {
c(1, {
sn(
nil,
fmta(
@@ -419,7 +419,7 @@ return {
return $this->hasOne(#~::class);
}
]],
{ rep(1), i(0), i(1) }
{ rep(1), i(2), i(1) }
)
),
sn(
@@ -434,14 +434,14 @@ return {
return $this->hasOne(#~::class, #~);
}
]],
{ rep(1), i(2), i(1), i(0) }
{ rep(1), i(2), i(1), i(3) }
)
),
})
),
s(
etr('ho', 'hasOne Laravel relationship method'),
c(0, {
c(1, {
sn(
nil,
fmta(
@@ -454,7 +454,7 @@ return {
return $this->hasOne(#~::class);
}
]],
{ rep(1), i(0), i(1) }
{ rep(1), i(2), i(1) }
)
),
sn(
@@ -469,14 +469,14 @@ return {
return $this->hasOne(#~::class, #~);
}
]],
{ rep(1), i(2), i(1), i(0) }
{ rep(1), i(2), i(1), i(3) }
)
),
})
),
s(
etr('bm', 'belongsToMany Laravel relationship method'),
c(0, {
c(1, {
sn(
nil,
fmta(
@@ -489,7 +489,7 @@ return {
return $this->belongsToMany(#~::class, #~);
}
]],
{ rep(1), i(2), i(1), i(0) }
{ rep(1), i(2), i(1), i(3) }
)
),
sn(
@@ -504,16 +504,16 @@ return {
return $this->belongsToMany(#~::class, #~, #~);
}
]],
{ rep(1), i(2), i(1), i(3), i(0) }
{ rep(1), i(2), i(1), i(3), i(4) }
)
),
})
),
s(
atr('->wr', 'Eloquent where method'),
c(0, {
sn(nil, fmta("->where('#~', #~)", { i(1), i(0) })),
sn(nil, fmta('->where(fn ($query) => #~)', { i(0) })),
c(1, {
sn(nil, fmta("->where('#~', #~)", { i(1), i(2) })),
sn(nil, fmta('->where(fn ($query) => #~)', { i(1) })),
sn(
nil,
fmta(
@@ -522,7 +522,7 @@ return {
#~
})
]],
{ i(0) }
{ i(1) }
)
),
sn(
@@ -533,7 +533,7 @@ return {
#~
})
]],
{ i(1), i(0) }
{ i(1), i(2) }
)
),
})
@@ -541,8 +541,8 @@ return {
s(atr('->wi', 'Eloquent where in method'), fmta("->whereIn('#~', #~)", { i(1), i(0) })),
s(atr('->wn', 'Eloquent where not in method'), fmta("->whereNotIn('#~', #~)", { i(1), i(0) })),
s(
atr('->wh', 'Eloquent where has method'),
c(0, {
atr('->wha', 'Eloquent where has method'),
c(1, {
sn(nil, fmta("->whereHas('#~')", { i(1) })),
sn(nil, fmta("->whereHas('#~', fn ($query) => #~)", { i(1), i(0) })),
sn(
@@ -553,7 +553,7 @@ return {
#~
})
]],
{ i(1), i(0) }
{ i(1), i(1) }
)
),
sn(
@@ -564,14 +564,14 @@ return {
#~
})
]],
{ i(1), i(2), i(0) }
{ i(1), i(2), i(3) }
)
),
})
),
s(
atr('->we', 'Eloquent where exists method'),
c(0, {
c(1, {
sn(nil, fmta('->whereExists(fn ($query) => #~)', { i(0) })),
sn(
nil,
@@ -581,7 +581,7 @@ return {
#~
})
]],
{ i(0) }
{ i(1) }
)
),
sn(
@@ -592,7 +592,7 @@ return {
#~
})
]],
{ i(1), i(0) }
{ i(1), i(2) }
)
),
})