From c06907ef6d49ec9316636fa8e7ed19817d491326 Mon Sep 17 00:00:00 2001 From: danymat Date: Tue, 11 Jan 2022 11:57:35 +0100 Subject: [PATCH] feat(c/cpp) Update configurations --- lua/neogen.lua | 4 +-- lua/neogen/configurations/c.lua | 55 ++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/lua/neogen.lua b/lua/neogen.lua index 44ade1c..0c3e780 100644 --- a/lua/neogen.lua +++ b/lua/neogen.lua @@ -162,8 +162,8 @@ neogen.setup = function(opts) python = require("neogen.configurations.python"), javascript = require("neogen.configurations.javascript"), typescript = require("neogen.configurations.typescript"), - c = require("neogen.configurations.c"), - cpp = require("neogen.configurations.c"), + c = require("neogen.configurations.c").c_config, + cpp = require("neogen.configurations.c").cpp_config, go = require("neogen.configurations.go"), java = require("neogen.configurations.java"), rust = require("neogen.configurations.rust"), diff --git a/lua/neogen/configurations/c.lua b/lua/neogen/configurations/c.lua index ad58cf1..67653cf 100644 --- a/lua/neogen/configurations/c.lua +++ b/lua/neogen/configurations/c.lua @@ -107,7 +107,7 @@ local c_function_extractor = function(node) } end -return { +local c_config = { parent = { func = { "function_declaration", @@ -175,9 +175,9 @@ return { { nil, " */", { no_results = true, type = { "func", "file" } } }, { nil, "", { no_results = true, type = { "file" } } }, - { nil, "/**", type = { "func" } }, - { nil, " * @brief $1", type = { "func" } }, - { nil, " *", type = { "func" } }, + { nil, "/**", { type = { "func" } } }, + { nil, " * @brief $1", { type = { "func" } } }, + { nil, " *", { type = { "func" } } }, { "tparam", " * @tparam %s $1" }, { "parameters", " * @param %s $1" }, { "return_statement", " * @return $1" }, @@ -185,3 +185,50 @@ return { }, }, } + +local cpp_config = { + parent = { + class = { "class_specifier" }, + }, + data = { + class = { + ["class_specifier"] = { + ["0"] = { + extract = function(node) + local tree = { + { retrieve = "first", node_type = "type_identifier", extract = true }, + } + local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree) + local res = neogen.utilities.extractors:extract_from_matched(nodes) + return res + end, + }, + }, + }, + }, + template = { + + doxygen = { + { nil, "/**", { no_results = true, type = { "func", "file", "class" } } }, + { nil, " * @file", { no_results = true, type = { "file" } } }, + { nil, " * @brief $1", { no_results = true, type = { "func", "file", "class" } } }, + { nil, " */", { no_results = true, type = { "func", "file", "class" } } }, + { nil, "", { no_results = true, type = { "file" } } }, + + { nil, "/**", { type = { "func", "class" } } }, + { "type_identifier", " * @class %s", { type = { "class" } } }, + { nil, " * @brief $1", { type = { "func", "class" } } }, + { nil, " *", { type = { "func", "class" } } }, + { "tparam", " * @tparam %s $1" }, + { "parameters", " * @param %s $1" }, + { "return_statement", " * @return $1" }, + { nil, " */", { type = { "func", "class" } } }, + }, + }, +} +cpp_config = vim.tbl_deep_extend("force", c_config, cpp_config) + +return { + c_config = c_config, + cpp_config = cpp_config, +}