From bb486455b9f630dd1a83bfe664ec822a4eef90d0 Mon Sep 17 00:00:00 2001 From: danymat Date: Tue, 11 Jan 2022 10:01:43 +0100 Subject: [PATCH] feat: Add csharp support --- README.md | 2 + lua/neogen.lua | 1 + lua/neogen/configurations/csharp.lua | 124 +++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 lua/neogen/configurations/csharp.lua diff --git a/README.md b/README.md index 8cf761c..dddd75a 100644 --- a/README.md +++ b/README.md @@ -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"`) | ``, ``,``| ## Adding Languages diff --git a/lua/neogen.lua b/lua/neogen.lua index 7ed0b5f..adb1e1b 100644 --- a/lua/neogen.lua +++ b/lua/neogen.lua @@ -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") }, }) diff --git a/lua/neogen/configurations/csharp.lua b/lua/neogen/configurations/csharp.lua new file mode 100644 index 0000000..7cf0ce8 --- /dev/null +++ b/lua/neogen/configurations/csharp.lua @@ -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, "/// ", { no_results = true } }, + { nil, "/// $1", { no_results = true } }, + { nil, "/// ", { no_results = true } }, + + { nil, "/// ", {} }, + { nil, "/// $1", {} }, + { "identifier", '/// $1', { type = { "func", "type" } } }, + { "return_statement", "/// $1", { type = { "func", "type" } } }, + { nil, "/// ", {} }, + }, + }, +}