From d8f0d24cc6f83f18a6331e148b02906feb3b7839 Mon Sep 17 00:00:00 2001 From: danymat Date: Sun, 9 Jan 2022 14:15:01 +0100 Subject: [PATCH] feat(ts,js) Add support for `file` annotations (#31) --- README.md | 12 ++++++------ lua/neogen/configurations/javascript.lua | 17 ++++++++++++++++- lua/neogen/configurations/typescript.lua | 18 ++++++++++++++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4542ee2..c4741e5 100644 --- a/README.md +++ b/README.md @@ -182,14 +182,14 @@ There is a list of supported languages and fields, with their annotation style | python | | | `func`, `class`, `file` | | | [Google docstrings](https://google.github.io/styleguide/pyguide.html) (`"google_docstrings"`) | `Args`, `Attributes`, `Returns` | | | [Numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) (`"numpydoc"`)| `Arguments`, `Attributes`, `Returns`| -| javascript | | | `func`, `class` | -| | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `@param`, `@returns`, `@class`, `@classdesc` | -| typescript | | | `func`, `class` | -| | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `@param`, `@returns`, `@class`, `@classdesc`, `@type` | +| javascript | | | `func`, `class`, `file`| +| | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `@param`, `@returns`, `@class`, `@classdesc`, `@module`| +| typescript | | | `func`, `class`, `file`| +| | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `@param`, `@returns`, `@class`, `@classdesc`, `@type`, `@module`| | c | | | `func`, `file`| -| | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@return`, `@brief`| +| | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@return`, `@brief`, `@file`| | cpp | | | `func`, `file` | -| | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@return`, `@tparam`, `@brief`| +| | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@return`, `@tparam`, `@brief`, `@file`| | go | | | | | | [Godoc](https://go.dev/blog/godoc) (`"godoc"`) | | | java | | | `func`, `class` | diff --git a/lua/neogen/configurations/javascript.lua b/lua/neogen/configurations/javascript.lua index 2fc9156..318dcc5 100644 --- a/lua/neogen/configurations/javascript.lua +++ b/lua/neogen/configurations/javascript.lua @@ -19,6 +19,7 @@ return { parent = { func = { "function_declaration", "expression_statement", "variable_declaration", "lexical_declaration" }, class = { "function_declaration", "expression_statement", "variable_declaration", "class_declaration" }, + file = { "program" }, }, data = { @@ -79,6 +80,15 @@ return { }, }, }, + file = { + ["program"] = { + ["0"] = { + extract = function() + return {} + end, + }, + }, + }, }, template = { @@ -86,7 +96,12 @@ return { use_default_comment = false, jsdoc = { - { nil, "/* $1 */", { no_results = true } }, + { nil, "/* $1 */", { no_results = true, type = { "func", "class" } } }, + + { nil, "/**", { no_results = true, type = { "file" } } }, + { nil, " * @module $1", { no_results = true, type = { "file" } } }, + { nil, " */", { no_results = true, type = { "file" } } }, + { nil, "/**" }, { "class_tag", " * @classdesc $1", { before_first_item = { " * ", " * @class" }, type = { "class" } } }, { "parameters", " * @param {any} %s $1" }, diff --git a/lua/neogen/configurations/typescript.lua b/lua/neogen/configurations/typescript.lua index fe8dbf3..3e1fc98 100644 --- a/lua/neogen/configurations/typescript.lua +++ b/lua/neogen/configurations/typescript.lua @@ -33,6 +33,7 @@ return { func = { "function_declaration", "expression_statement", "variable_declaration", "lexical_declaration" }, class = { "function_declaration", "expression_statement", "variable_declaration", "class_declaration" }, type = { "variable_declaration" }, + file = { "program" }, }, data = { @@ -114,14 +115,27 @@ return { }, }, }, + file = { + ["program"] = { + ["0"] = { + extract = function() + return {} + end, + }, + }, + }, }, template = { annotation_convention = "jsdoc", use_default_comment = false, - jsdoc = { - { nil, "/* $1 */", { no_results = true } }, + { nil, "/* $1 */", { no_results = true, type = { "class", "func" } } }, + + { nil, "/**", { no_results = true, type = { "file" } } }, + { nil, " * @module $1", { no_results = true, type = { "file" } } }, + { nil, " */", { no_results = true, type = { "file" } } }, + { nil, "/**" }, { "class_tag", " * @classdesc $1", { before_first_item = { " * ", " * @class" }, type = { "class" } } }, { "parameters", " * @param {any} %s $1" },