summaryrefslogtreecommitdiffstats
path: root/lua/snippets
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2024-12-22 14:01:57 -0500
committerSquibid <me@zacharyscheiman.com>2024-12-22 14:01:57 -0500
commit53fa869a7ea29d06ed64f74850f5cefdb8850884 (patch)
treea106674f2e2158eddeba4f4b7871c03273018dca /lua/snippets
parent8ad9f7a9428db825a6278df317fa97a932c4c61c (diff)
downloadnvim-53fa869a7ea29d06ed64f74850f5cefdb8850884.tar.gz
nvim-53fa869a7ea29d06ed64f74850f5cefdb8850884.tar.bz2
nvim-53fa869a7ea29d06ed64f74850f5cefdb8850884.zip
update snippets
Diffstat (limited to '')
-rw-r--r--lua/snippets/c.lua13
-rw-r--r--lua/snippets/java.lua19
2 files changed, 15 insertions, 17 deletions
diff --git a/lua/snippets/c.lua b/lua/snippets/c.lua
index 2d71253..65463dc 100644
--- a/lua/snippets/c.lua
+++ b/lua/snippets/c.lua
@@ -6,21 +6,12 @@ require('core.snippets.shorthands')
local function c_func(func)
local tree = vim.treesitter.get_parser():parse()[1]:root()
- local q = vim.treesitter.query.parse("c", [[
- (function_definition
- declarator: (function_declarator
- (identifier) @function_name
- )
- )
- ]])
+ local q = vim.treesitter.query.parse("c", "(function_definition) @f")
local matches = q:iter_matches(tree, 0)
for _, match in matches do
for _, node in pairs(match) do
- if vim.treesitter.get_node_text(node, 0) == func then
- while node:type() ~= "function_definition" do
- node = node:parent()
- end
+ if vim.treesitter.get_node_text(node:child(1):child(), 0) == func then
local def = ""
for i = 0, node:child_count() - 2 do
def = def..vim.treesitter.get_node_text(node:child(i), 0)
diff --git a/lua/snippets/java.lua b/lua/snippets/java.lua
index 50fef37..ebd1233 100644
--- a/lua/snippets/java.lua
+++ b/lua/snippets/java.lua
@@ -93,7 +93,7 @@ return {
-- if the function isn't abstract include a body
return sn(nil, {
t({ " {", "\t" }),
- i(0),
+ i(1),
t({ "", "}" })
})
end
@@ -107,13 +107,20 @@ return {
}),
-- class snippet
- s("class", {
+ s({ trig = [[class\|interface]], trigEngine = "vim" }, {
access_modifiers(1),
modifiers(2),
- c(3, {
- t("class "),
- t("interface ")
- }),
+ d(3, function(_, snip)
+ local opts = { t("class "), 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, {
f(file_name, {}),
i(0, "MyClass")