update snippets
This commit is contained in:
@ -6,21 +6,12 @@ require('core.snippets.shorthands')
|
|||||||
local function c_func(func)
|
local function c_func(func)
|
||||||
local tree = vim.treesitter.get_parser():parse()[1]:root()
|
local tree = vim.treesitter.get_parser():parse()[1]:root()
|
||||||
|
|
||||||
local q = vim.treesitter.query.parse("c", [[
|
local q = vim.treesitter.query.parse("c", "(function_definition) @f")
|
||||||
(function_definition
|
|
||||||
declarator: (function_declarator
|
|
||||||
(identifier) @function_name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
]])
|
|
||||||
local matches = q:iter_matches(tree, 0)
|
local matches = q:iter_matches(tree, 0)
|
||||||
|
|
||||||
for _, match in matches do
|
for _, match in matches do
|
||||||
for _, node in pairs(match) do
|
for _, node in pairs(match) do
|
||||||
if vim.treesitter.get_node_text(node, 0) == func then
|
if vim.treesitter.get_node_text(node:child(1):child(), 0) == func then
|
||||||
while node:type() ~= "function_definition" do
|
|
||||||
node = node:parent()
|
|
||||||
end
|
|
||||||
local def = ""
|
local def = ""
|
||||||
for i = 0, node:child_count() - 2 do
|
for i = 0, node:child_count() - 2 do
|
||||||
def = def..vim.treesitter.get_node_text(node:child(i), 0)
|
def = def..vim.treesitter.get_node_text(node:child(i), 0)
|
||||||
|
@ -93,7 +93,7 @@ return {
|
|||||||
-- if the function isn't abstract include a body
|
-- if the function isn't abstract include a body
|
||||||
return sn(nil, {
|
return sn(nil, {
|
||||||
t({ " {", "\t" }),
|
t({ " {", "\t" }),
|
||||||
i(0),
|
i(1),
|
||||||
t({ "", "}" })
|
t({ "", "}" })
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -107,13 +107,20 @@ return {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
-- class snippet
|
-- class snippet
|
||||||
s("class", {
|
s({ trig = [[class\|interface]], trigEngine = "vim" }, {
|
||||||
access_modifiers(1),
|
access_modifiers(1),
|
||||||
modifiers(2),
|
modifiers(2),
|
||||||
c(3, {
|
d(3, function(_, snip)
|
||||||
t("class "),
|
local opts = { t("class "), t("interface ") }
|
||||||
t("interface ")
|
if snip.trigger == "interface" then
|
||||||
}),
|
-- flip interface and class
|
||||||
|
opts[1], opts[2] = opts[2], opts[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
return sn(nil, {
|
||||||
|
c(1, opts)
|
||||||
|
})
|
||||||
|
end, {}),
|
||||||
c(4, {
|
c(4, {
|
||||||
f(file_name, {}),
|
f(file_name, {}),
|
||||||
i(0, "MyClass")
|
i(0, "MyClass")
|
||||||
|
Reference in New Issue
Block a user