diff options
author | Squibid <me@zacharyscheiman.com> | 2025-05-09 00:15:41 -0500 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2025-05-09 00:15:41 -0500 |
commit | a6007ff694e7b8f5631dbb960db874ec9c86896b (patch) | |
tree | 668acd8acc6e41581200f1eaa89aba669544a984 /lua | |
parent | 7430ebed8eab0364452a6cdcaa209f8a7288e44d (diff) | |
download | nvim-a6007ff694e7b8f5631dbb960db874ec9c86896b.tar.gz nvim-a6007ff694e7b8f5631dbb960db874ec9c86896b.tar.bz2 nvim-a6007ff694e7b8f5631dbb960db874ec9c86896b.zip |
this hasn't worked for a long time, I might choose to re-impl if I have time
Diffstat (limited to 'lua')
-rw-r--r-- | lua/snippets/c.lua | 59 |
1 files changed, 1 insertions, 58 deletions
diff --git a/lua/snippets/c.lua b/lua/snippets/c.lua index 88a503f..ed63c1b 100644 --- a/lua/snippets/c.lua +++ b/lua/snippets/c.lua @@ -1,46 +1,4 @@ -require("core.snippets.shorthands") - ---- create a decleration of a function from it's definition using treesitter ----@param func string ----@return string|nil -local function c_func(func) - local tree = vim.treesitter.get_parser():parse()[1]:root() - - local q = vim.treesitter.query.parse("c", "(function_definition) @f") - local matches = q:iter_matches(tree, 0) - - vim.treesitter.query.parse("c", "(identifier) @i") - local m = q:iter_matches(matches, 0) - print(vim.treesitter.get_node_text(m:child(), 0)) - - if true then - return - end - - for _, match in matches do - for _, node in pairs(match) do - if not node or not node:child(1) or not node:child(1):child() then - -- print(vim.treesitter.get_node_text(node:child(1):child(), 0)) - goto continue - 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) - if i < node:child_count() - 2 then - def = def.." " - end - end - -- Print the function name using node text - return def:gsub("\n", "") - end - ::continue:: - end - end - - return nil -end +require('core.snippets.shorthands') return { -- function snippet @@ -82,19 +40,4 @@ return { i(0), t({ "", "}" }) }), - - -- create decleration based on existing c function - postfix(".d", { - f(function(_, parent) - local r = c_func(parent.snippet.env.POSTFIX_MATCH) - if not r then - return parent.snippet.env.POSTFIX_MATCH - end - local bidx, aidx = r:find(parent.snippet.env.POSTFIX_MATCH) - - return r:sub(1, bidx - 1).. - parent.snippet.env.POSTFIX_MATCH.. - r:sub(aidx + 1)..";" - end, {}) - }) } |