From 26a8899f366c27ab1096f4a42ee03d695d5d2fd8 Mon Sep 17 00:00:00 2001 From: danymat Date: Fri, 11 Feb 2022 12:31:42 +0100 Subject: [PATCH] feat: Add kotlin support (#34) --- lua/neogen/configurations/kotlin.lua | 75 ++++++++++++++++++++++++++++ lua/neogen/init.lua | 6 ++- lua/neogen/templates/javadoc.lua | 1 + lua/neogen/templates/kdoc.lua | 1 + 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 lua/neogen/configurations/kotlin.lua create mode 100644 lua/neogen/templates/kdoc.lua diff --git a/lua/neogen/configurations/kotlin.lua b/lua/neogen/configurations/kotlin.lua new file mode 100644 index 0000000..f376bf7 --- /dev/null +++ b/lua/neogen/configurations/kotlin.lua @@ -0,0 +1,75 @@ +local _template = require("neogen.template") +local i = require("neogen.types.template").item +local extractors = require("neogen.utilities.extractors") +local nodes_utils = require("neogen.utilities.nodes") + +---@type neogen.Configuration +local template = {} + +template.parent = { + class = { "class_declaration" }, + func = { "function_declaration" }, +} + +template.data = { + func = { + ["function_declaration"] = { + ["0"] = { + extract = function(node) + local tree = { + { + node_type = "parameter", + retrieve = "all", + subtree = { + { + node_type = "simple_identifier", + as = i.Parameter, + retrieve = "first", + extract = true, + }, + }, + }, + } + local nodes = nodes_utils:matching_nodes_from(node, tree) + local res = extractors:extract_from_matched(nodes) + return res + end, + }, + }, + }, + class = { + ["class_declaration"] = { + ["0"] = { + extract = function(node) + local tree = { + { + node_type = "primary_constructor", + retrieve = "first", + subtree = { + { + node_type = "class_parameter", + retrieve = "all", + subtree = { + { + node_type = "simple_identifier", + retrieve = "first", + extract = true, + as = i.ClassAttribute, + }, + }, + }, + }, + }, + } + local nodes = nodes_utils:matching_nodes_from(node, tree) + local res = extractors:extract_from_matched(nodes) + return res + end, + }, + }, + }, +} + +template.template = _template:add_default_annotation("kdoc") + +return template diff --git a/lua/neogen/init.lua b/lua/neogen/init.lua index aeeba6d..fd97414 100644 --- a/lua/neogen/init.lua +++ b/lua/neogen/init.lua @@ -202,6 +202,10 @@ end ---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section) ---@text # Changelog~ --- +--- Note: We will only document major and minor versions. +--- +--- ## 2.1.0~ +--- - Add basic support for `kotlin` (`kdoc`). --- ## 2.0.0~ --- - We made the template API private, only for initial template configuration. --- If you want to make a change to a template, please see: @@ -211,7 +215,7 @@ end --- with multiple annotation conventions. ---@tag neogen-changelog ---@toc_entry Changes in neogen plugin -neogen.version = "2.0.0" +neogen.version = "2.1.0" --minidoc_afterlines_end return neogen diff --git a/lua/neogen/templates/javadoc.lua b/lua/neogen/templates/javadoc.lua index b85dabc..3fe3791 100644 --- a/lua/neogen/templates/javadoc.lua +++ b/lua/neogen/templates/javadoc.lua @@ -9,6 +9,7 @@ return { { nil, " * $1" }, { nil, " *" }, { i.Parameter, " * @param %s $1" }, + { i.ClassAttribute, "* @property %s $1" }, { i.Return, " * @return $1" }, { i.Throw, " * @throws $1" }, { nil, " */" }, diff --git a/lua/neogen/templates/kdoc.lua b/lua/neogen/templates/kdoc.lua new file mode 100644 index 0000000..3d072c3 --- /dev/null +++ b/lua/neogen/templates/kdoc.lua @@ -0,0 +1 @@ +return require("neogen.templates.javadoc")