feat: Add support for ruby (yard, rdoc)

This commit is contained in:
danymat
2022-02-08 14:12:22 +01:00
parent 7a2e69b660
commit e9b2812ed1
4 changed files with 99 additions and 0 deletions

View File

@@ -197,6 +197,7 @@ There is a list of supported languages and fields, with their annotation style
| lua | [Emmylua](https://emmylua.github.io/) (`"emmylua"`)<br> [Ldoc](https://stevedonovan.github.io/ldoc/manual/doc.md.html) (`"ldoc"`) | `func`, `class`, `type`, `file` | | lua | [Emmylua](https://emmylua.github.io/) (`"emmylua"`)<br> [Ldoc](https://stevedonovan.github.io/ldoc/manual/doc.md.html) (`"ldoc"`) | `func`, `class`, `type`, `file` |
| php | [Php-doc](https://docs.phpdoc.org/3.0/guide/references/phpdoc/index.html) (`"phpdoc"`) | `func`, `type`, `class` | | php | [Php-doc](https://docs.phpdoc.org/3.0/guide/references/phpdoc/index.html) (`"phpdoc"`) | `func`, `type`, `class` |
| python | [Google docstrings](https://google.github.io/styleguide/pyguide.html) (`"google_docstrings"`) <br> [Numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) (`"numpydoc"`) <br> [reST](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html) (`"reST"`) | `func`, `class`, `type`, `file` | | python | [Google docstrings](https://google.github.io/styleguide/pyguide.html) (`"google_docstrings"`) <br> [Numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) (`"numpydoc"`) <br> [reST](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html) (`"reST"`) | `func`, `class`, `type`, `file` |
| ruby | [YARD](https://yardoc.org/index.html) (`"yard"`) <br> [Rdoc](https://github.com/ruby/rdoc) (`"rdoc"`) | `func`, `type`, `class` |
| rust | [RustDoc](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) (`"rustdoc"`) <br> [Alternative](https://stackoverflow.com/questions/30009650/how-do-you-document-function-arguments) (`"alternative"`) | `func`, `file`, `class` | | rust | [RustDoc](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) (`"rustdoc"`) <br> [Alternative](https://stackoverflow.com/questions/30009650/how-do-you-document-function-arguments) (`"alternative"`) | `func`, `file`, `class` |
| typescript | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `func`, `class`, `type`, `file` | | typescript | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `func`, `class`, `type`, `file` |
| tsx | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `func`, `class`, `type`, `file` | | tsx | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `func`, `class`, `type`, `file` |

View File

@@ -0,0 +1,77 @@
local _template = require("neogen.utilities.template")
local i = require("neogen.types.template").item
local nodes_utils = require("neogen.utilities.nodes")
local extractors = require("neogen.utilities.extractors")
local template = {}
template.parent = {
func = { "method" },
class = { "class" },
type = { "call" },
}
local identifier = {
retrieve = "first",
node_type = "identifier",
as = i.Parameter,
extract = true,
}
template.data = {
func = {
["method"] = {
["0"] = {
extract = function(node)
local tree = {
{
retrieve = "first",
node_type = "method_parameters",
subtree = {
{
retrieve = "all",
node_type = "optional_parameter",
subtree = {
identifier,
},
},
identifier,
},
},
{
retrieve = "all",
node_type = "return",
as = i.Return,
extract = true,
},
}
local nodes = nodes_utils:matching_nodes_from(node, tree)
local res = extractors:extract_from_matched(nodes)
return res
end,
},
},
},
class = {
["class"] = {
["0"] = {
extract = function()
return {}
end,
},
},
},
type = {
["call"] = {
["0"] = {
extract = function()
return {}
end,
},
},
},
}
template.template = _template:add_default_annotation("yard"):add_annotation("rdoc")
return template

View File

@@ -0,0 +1,11 @@
return {
{ nil, "##", { type = { "class", "func" } } },
{ nil, "# $1", { type = { "class", "func" } } },
{ nil, "", { type = { "class", "func" } } },
{ nil, "# $1", { type = { "type" } } },
{ nil, "#1", { no_results = true, type = { "class", "func" } } },
{ nil, "# $1", { no_results = true, type = { "class", "func" } } },
{ nil, "", { no_results = true, type = { "class", "func" } } },
{ nil, "# $1", { no_results = true, type = { "type" } } },
}

View File

@@ -0,0 +1,10 @@
local i = require("neogen.types.template").item
return {
{ nil, "# $1", { no_results = true, type = { "class", "func" } } },
{ nil, "# $1", { no_results = true, type = { "type" } } },
{ nil, "# $1" },
{ i.Parameter, "# @param %s [$1] $1", {} },
{ i.Return, "# @return [$1] $1", {} },
}