Skip to content

Commit

Permalink
feat: Add kotlin support (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
danymat committed Feb 11, 2022
1 parent e59d16d commit 26a8899
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
75 changes: 75 additions & 0 deletions lua/neogen/configurations/kotlin.lua
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion lua/neogen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
1 change: 1 addition & 0 deletions lua/neogen/templates/javadoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, " */" },
Expand Down
1 change: 1 addition & 0 deletions lua/neogen/templates/kdoc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return require("neogen.templates.javadoc")

0 comments on commit 26a8899

Please sign in to comment.