fix(ts) Do not offset function annotations (#111)

This commit is contained in:
danymat
2022-10-20 13:32:37 +02:00
parent e754659d2c
commit b1e56c5263
3 changed files with 20 additions and 3 deletions

View File

@@ -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"),
}

View File

@@ -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

View File

@@ -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