feat: Add csharp support

This commit is contained in:
danymat
2022-01-11 10:01:43 +01:00
parent 0cb45647db
commit bb486455b9
3 changed files with 127 additions and 0 deletions

View File

@@ -197,6 +197,8 @@ There is a list of supported languages and fields, with their annotation style
| rust | | | `func`, `file`, `class` |
| | [Rustdoc](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) (`"rustdoc"`) | |
| | [Alternative](https://stackoverflow.com/questions/30009650/how-do-you-document-function-arguments) (`"alternative"`) | |
| csharp | | | `func`, `file`, `class`|
| | [Xmldoc](https://docs.microsoft.com/fr-fr/dotnet/csharp/language-reference/xmldoc/) (`"xmldoc"`) | `<summary>`, `<param>`,`<returns>`|
## Adding Languages

View File

@@ -151,6 +151,7 @@ neogen.setup = function(opts)
go = require("neogen.configurations.go"),
java = require("neogen.configurations.java"),
rust = require("neogen.configurations.rust"),
cs = require("neogen.configurations.csharp")
},
})

View File

@@ -0,0 +1,124 @@
return {
parent = {
func = {
"method_declaration",
"constructor_declaration",
"operator_declaration",
"delegate_declaration",
"conversion_operator_declaration",
},
class = { "class_declaration" },
type = { "field_declaration", "property_declaration", "event_field_declaration", "indexer_declaration" },
},
data = {
func = {
["method_declaration|constructor_declaration|operator_declaration|delegate_declaration|conversion_operator_declaration"] = {
["0"] = {
extract = function(node)
local tree = {
{
retrieve = "first",
node_type = "parameter_list",
subtree = {
{
retrieve = "all",
node_type = "parameter",
subtree = {
{ position = 2, extract = true },
},
},
},
},
{
retrieve = "first",
node_type = "block",
subtree = {
{
retrieve = "first",
recursive = true,
node_type = "return_statement",
extract = true,
},
},
},
}
local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree)
local res = neogen.utilities.extractors:extract_from_matched(nodes)
res.identifier = res["_"]
return res
end,
},
},
},
class = {
["class_declaration"] = {
["0"] = {
extract = function()
return {}
end,
},
},
},
type = {
["field_declaration|property_declaration|event_field_declaration"] = {
["0"] = {
extract = function()
return {}
end,
},
},
["indexer_declaration"] = {
["0"] = {
extract = function(node)
local tree = {
{
retrieve = "first",
node_type = "bracketed_parameter_list",
subtree = {
{
retrieve = "all",
node_type = "parameter",
subtree = {
{ retrieve = "first", node_type = "identifier", extract = true },
},
},
},
},
{
retrieve = "first",
node_type = "accessor_list",
subtree = {
{
retrieve = "all",
node_type = "return_statement",
recursive = true,
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 = {
use_default_comment = false,
annotation_convention = "xmldoc",
xmldoc = {
{ nil, "/// <summary>", { no_results = true } },
{ nil, "/// $1", { no_results = true } },
{ nil, "/// </summary>", { no_results = true } },
{ nil, "/// <summary>", {} },
{ nil, "/// $1", {} },
{ "identifier", '/// <param name="%s">$1</param>', { type = { "func", "type" } } },
{ "return_statement", "/// <returns>$1</returns>", { type = { "func", "type" } } },
{ nil, "/// </summary>", {} },
},
},
}