diff --git a/lua/neogen/configurations/go.lua b/lua/neogen/configurations/go.lua index 6d633b6..ebd2ec9 100644 --- a/lua/neogen/configurations/go.lua +++ b/lua/neogen/configurations/go.lua @@ -1,17 +1,46 @@ local template = require("neogen.template") +local extractors = require("neogen.utilities.extractors") +local nodes_utils = require("neogen.utilities.nodes") return { parent = { - func = { "function_declaration" }, - type = { "package_clause", "const_declaration", "var_declaration" }, + func = { "function_declaration", "method_declaration" }, + type = { "package_clause", "const_declaration", "var_declaration", "type_declaration" }, }, data = { func = { ["function_declaration"] = { ["0"] = { - extract = function() - return {} + extract = function(node) + local tree = { + { + retrieve = "first", + node_type = "identifier", + extract = "true", + as = "func_name", + }, + } + local nodes = nodes_utils:matching_nodes_from(node, tree) + local res = extractors:extract_from_matched(nodes) + return res + end, + }, + }, + ["method_declaration"] = { + ["0"] = { + extract = function(node) + local tree = { + { + retrieve = "first", + node_type = "field_identifier", + extract = "true", + as = "func_name", + }, + } + local nodes = nodes_utils:matching_nodes_from(node, tree) + local res = extractors:extract_from_matched(nodes) + return res end, }, }, @@ -24,6 +53,29 @@ return { end, }, }, + ["type_declaration"] = { + ["0"] = { + extract = function(node) + local tree = { + { + retrieve = "all", + node_type = "type_spec", + subtree = { + { + retrieve = "first", + node_type = "type_identifier", + extract = true, + as = "type_name", + }, + }, + }, + } + local nodes = nodes_utils:matching_nodes_from(node, tree) + local res = extractors:extract_from_matched(nodes) + return res + end, + }, + }, }, }, diff --git a/lua/neogen/init.lua b/lua/neogen/init.lua index 52eebc8..4af42c8 100644 --- a/lua/neogen/init.lua +++ b/lua/neogen/init.lua @@ -216,6 +216,8 @@ end --- --- Note: We will only document `major` and `minor` versions, not `patch` ones. --- +--- ## 2.4.0~ +--- - Improve godoc template (#75) --- ## 2.3.0~ --- - Added bundled support with snippet engines ! --- Check out |snippet-integration| for basic setup @@ -234,7 +236,7 @@ end --- with multiple annotation conventions. ---@tag neogen-changelog ---@toc_entry Changes in neogen plugin -neogen.version = "2.3.0" +neogen.version = "2.4.0" --minidoc_afterlines_end return neogen diff --git a/lua/neogen/templates/godoc.lua b/lua/neogen/templates/godoc.lua index ad9b3fb..8175a2e 100644 --- a/lua/neogen/templates/godoc.lua +++ b/lua/neogen/templates/godoc.lua @@ -1,3 +1,5 @@ return { { nil, " $1", { no_results = true } }, + { "func_name", " %s $1", { type = { "func" }}}, + { "type_name", " %s $1", { type = { "type" }}}, }