From b1e56c5263f3155f6368a0a173b06d84257c2c7d Mon Sep 17 00:00:00 2001 From: danymat Date: Thu, 20 Oct 2022 13:32:37 +0200 Subject: [PATCH] fix(ts) Do not offset function annotations (#111) --- lua/neogen/configurations/typescript.lua | 19 ++++++++++++++++++- lua/neogen/init.lua | 2 +- lua/neogen/locators/typescript.lua | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lua/neogen/configurations/typescript.lua b/lua/neogen/configurations/typescript.lua index 34f08b1..896575b 100644 --- a/lua/neogen/configurations/typescript.lua +++ b/lua/neogen/configurations/typescript.lua @@ -177,5 +177,22 @@ return { locator = require("neogen.locators.typescript"), - template = template:add_default_annotation("jsdoc"):add_default_annotation("tsdoc"), + template = template + :config({ + append = { position = "after", child_name = "comment", fallback = "block", disabled = { "file" } }, + position = function(node, type) + if vim.tbl_contains({ "func", "class" }, type) then + local parent = node:parent() + + -- Verify if the parent is an export_statement (prevents offset of generated annotation) + if parent and parent:type() == "export_statement" then + local row, col = vim.treesitter.get_node_range(parent) + return row, col + end + return 0, 0 + end + end, + }) + :add_default_annotation("jsdoc") + :add_default_annotation("tsdoc"), } diff --git a/lua/neogen/init.lua b/lua/neogen/init.lua index 6b206cd..3734f56 100644 --- a/lua/neogen/init.lua +++ b/lua/neogen/init.lua @@ -285,7 +285,7 @@ end --- with multiple annotation conventions. ---@tag neogen-changelog ---@toc_entry Changes in neogen plugin -neogen.version = "2.10.0" +neogen.version = "2.10.1" --minidoc_afterlines_end return neogen diff --git a/lua/neogen/locators/typescript.lua b/lua/neogen/locators/typescript.lua index 2f551e6..5e22eea 100644 --- a/lua/neogen/locators/typescript.lua +++ b/lua/neogen/locators/typescript.lua @@ -3,7 +3,7 @@ local default_locator = require("neogen.locators.default") return function(node_info, nodes_to_match) local found_node = default_locator(node_info, nodes_to_match) - if found_node and vim.tbl_contains({ "class_declaration", "function_declaration" }, found_node:type()) then + if found_node and vim.tbl_contains({ "class_declaration" }, found_node:type()) then local parent = found_node:parent() if parent and parent:type() == "export_statement" then return parent