From ff5f7de75017f02448b879cfdaf09bd4599e5efd Mon Sep 17 00:00:00 2001 From: danymat Date: Sun, 9 Jan 2022 13:20:12 +0100 Subject: [PATCH] feat:(c/cpp) Add new type: `file` (#31) --- README.md | 6 +++--- lua/neogen/configurations/c.lua | 24 ++++++++++++++++++------ lua/neogen/locators/default.lua | 8 ++++++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 972703b..f9fab1d 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ You can provide some options for the generate, like so: ```lua require('neogen').generate({ - type = "func" -- the annotation type to generate. Currently supported: func, class, type + type = "func" -- the annotation type to generate. Currently supported: func, class, type, file }) ``` @@ -186,9 +186,9 @@ There is a list of supported languages and fields, with their annotation style | | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `@param`, `@returns`, `@class`, `@classdesc` | | typescript | | | `func`, `class` | | | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `@param`, `@returns`, `@class`, `@classdesc`, `@type` | -| c | | | `func` | +| c | | | `func`, `file`| | | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@return`, `@brief`| -| cpp | | | `func` | +| cpp | | | `func`, `file` | | | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@return`, `@tparam`, `@brief`| | go | | | | | | [Godoc](https://go.dev/blog/godoc) (`"godoc"`) | | diff --git a/lua/neogen/configurations/c.lua b/lua/neogen/configurations/c.lua index e995e4a..82413b3 100644 --- a/lua/neogen/configurations/c.lua +++ b/lua/neogen/configurations/c.lua @@ -113,6 +113,7 @@ return { "field_declaration", "template_declaration", }, + file = { "translation_unit" }, }, data = { @@ -123,6 +124,15 @@ return { }, }, }, + file = { + ["translation_unit"] = { + ["0"] = { + extract = function() + return {} + end, + }, + }, + }, }, locator = function(node_info, nodes_to_match) @@ -151,13 +161,15 @@ return { use_default_comment = false, doxygen = { - { nil, "/**", { no_results = true } }, - { nil, " * @brief $1", { no_results = true } }, - { nil, " */", { no_results = true } }, + { nil, "/**", { no_results = true, type = { "func", "file" } } }, + { nil, " * @file", { no_results = true, type = { "file" } } }, + { nil, " * @brief $1", { no_results = true, type = { "func", "file" } } }, + { nil, " */", { no_results = true, type = { "func", "file" } } }, + { nil, "", { no_results = true, type = { "file" } } }, - { nil, "/**" }, - { nil, " * @brief $1" }, - { nil, " *" }, + { nil, "/**", type = { "func" } }, + { nil, " * @brief $1", type = { "func" } }, + { nil, " *", type = { "func" } }, { "tparam", " * @tparam %s $1" }, { "parameters", " * @param %s $1" }, { "return_statement", " * @return $1" }, diff --git a/lua/neogen/locators/default.lua b/lua/neogen/locators/default.lua index dcb99c9..9ad553f 100644 --- a/lua/neogen/locators/default.lua +++ b/lua/neogen/locators/default.lua @@ -1,8 +1,12 @@ +--- @class node_info +--- @field current userdata the current node from cursor +--- @field root userdata the root node + --- The default locator tries to find one of the nodes to match in the current node --- If it does not find one, will fetch the parents until he finds one ---- @param node_info table a node informations +--- @param node_info node_info a node informations --- @param nodes_to_match table a list of parent nodes to match ---- @return node_info.current node one of the nodes to match directly above the given node +--- @return userdata node one of the nodes to match directly above the given node neogen.default_locator = function(node_info, nodes_to_match) -- If we find one of the wanted nodes in current one, return the current node if vim.tbl_contains(nodes_to_match, node_info.current:type()) then