From 11d463b08cf0896bed9f2752bdcce9f2f30eebc8 Mon Sep 17 00:00:00 2001 From: Daniel Mathiot Date: Tue, 17 Aug 2021 18:40:20 +0200 Subject: [PATCH] Add description on top of annotation --- lua/neogen.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lua/neogen.lua b/lua/neogen.lua index fb6fcd2..f0e0ad4 100644 --- a/lua/neogen.lua +++ b/lua/neogen.lua @@ -3,7 +3,7 @@ local ts_query = require("nvim-treesitter.query") local M = {} -M.generate = function (t, t2) +M.generate = function () local comment = {} local query = [[ (function (parameters) @params) @@ -21,8 +21,10 @@ M.generate = function (t, t2) end local line = ts_utils.get_node_range(function_node) + + -- Parse and iterate over each found query local returned = vim.treesitter.parse_query("lua", query) - for id, node in returned:iter_captures(function_node) do -- For each found query + for id, node in returned:iter_captures(function_node) do -- Try to add params if returned.captures[id] == "params" then @@ -38,7 +40,12 @@ M.generate = function (t, t2) table.insert(comment, "---@return ") end end - + + -- At the end, add description annotation + table.insert(comment, "---") + + if #comment == 0 then return end + -- Write on top of function vim.fn.append(line, comment) vim.fn.cursor(line+1, #comment[1])