feat(ts) Add support for TSdoc annotation convention (closes #47)
This commit is contained in:
@@ -45,19 +45,39 @@ local function_tree = {
|
||||
{ retrieve = "first", node_type = "return_statement", extract = true, as = i.Return },
|
||||
},
|
||||
},
|
||||
{
|
||||
retrieve = "first",
|
||||
node_type = "type_annotation",
|
||||
subtree = {
|
||||
{ retrieve = "all", node_type = "type_identifier", extract = true, as = i.Return },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
parent = {
|
||||
func = { "function_declaration", "expression_statement", "variable_declaration", "lexical_declaration" },
|
||||
class = { "function_declaration", "expression_statement", "variable_declaration", "class_declaration" },
|
||||
func = {
|
||||
"function_declaration",
|
||||
"function_signature",
|
||||
"expression_statement",
|
||||
"variable_declaration",
|
||||
"lexical_declaration",
|
||||
"method_definition",
|
||||
},
|
||||
class = {
|
||||
"function_declaration",
|
||||
"expression_statement",
|
||||
"variable_declaration",
|
||||
"class_declaration",
|
||||
"export_statement",
|
||||
},
|
||||
type = { "variable_declaration", "lexical_declaration" },
|
||||
file = { "program" },
|
||||
},
|
||||
|
||||
data = {
|
||||
func = {
|
||||
["function_declaration"] = {
|
||||
["function_declaration|method_definition|function_signature"] = {
|
||||
["0"] = {
|
||||
|
||||
extract = function(node)
|
||||
@@ -93,7 +113,7 @@ return {
|
||||
},
|
||||
},
|
||||
class = {
|
||||
["function_declaration|class_declaration|expression_statement|variable_declaration"] = {
|
||||
["function_declaration|class_declaration|expression_statement|variable_declaration|export_statement"] = {
|
||||
["0"] = {
|
||||
|
||||
extract = function(_)
|
||||
@@ -134,5 +154,7 @@ return {
|
||||
},
|
||||
},
|
||||
|
||||
template = template:add_default_annotation("jsdoc"),
|
||||
locator = require("neogen.locators.typescript"),
|
||||
|
||||
template = template:add_default_annotation("jsdoc"):add_annotation("tsdoc"),
|
||||
}
|
||||
|
||||
15
lua/neogen/locators/typescript.lua
Normal file
15
lua/neogen/locators/typescript.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
local ts_utils = require("nvim-treesitter.ts_utils")
|
||||
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 found_node:type() == "class_declaration" then
|
||||
local parent = found_node:parent()
|
||||
if parent and parent:type() == "export_statement" then
|
||||
return parent
|
||||
end
|
||||
end
|
||||
|
||||
return found_node
|
||||
end
|
||||
21
lua/neogen/templates/tsdoc.lua
Normal file
21
lua/neogen/templates/tsdoc.lua
Normal file
@@ -0,0 +1,21 @@
|
||||
local i = require("neogen.types.template").item
|
||||
|
||||
return {
|
||||
{ nil, "/* $1 */", { no_results = true, type = { "func", "class" } } },
|
||||
{ nil, "/* @type $1 */", { no_results = true, type = { "type" } } },
|
||||
|
||||
{ nil, "/**", { no_results = true, type = { "file" } } },
|
||||
{ nil, " * @module $1", { no_results = true, type = { "file" } } },
|
||||
{ nil, " */", { no_results = true, type = { "file" } } },
|
||||
|
||||
{ nil, "/**", { type = { "class", "func" } } },
|
||||
{ i.ClassName, " * $1", { type = { "class" } } },
|
||||
{ i.Parameter, " * @param %s - $1", { type = { "func" } } },
|
||||
{
|
||||
{ i.Parameter },
|
||||
" * @param %s - $1",
|
||||
{ required = i.Tparam, type = { "func" } },
|
||||
},
|
||||
{ i.Return, " * @returns $1", { type = { "func" } } },
|
||||
{ nil, " */", { type = { "class", "func" } } },
|
||||
}
|
||||
Reference in New Issue
Block a user