Add basic support for javascript

At the moment, it recognizes simple functions, their params and their
direct return statements.
This commit is contained in:
Daniel Mathiot
2021-08-24 11:43:45 +02:00
parent 77515a574d
commit 98329fcf77
3 changed files with 48 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ If you're not satisfied with the default configuration for a language, you can c
```lua
require('neogen').setup {
enabled = true,
enabled = true,
languages = {
lua = {
template = {
@@ -91,6 +91,9 @@ There is a list of supported languages and fields, with their annotation style
| python | | |
| | Google docstrings (`"google_docstrings"`) | `Args`, `Attributes`, `Returns` |
| | Numpydoc (`"numpydoc"`)| `Arguments`, `Attributes`, `Returns`|
| javascript | | |
| | JSDoc (`"jsdoc"`) | `@param`, `@returns` |
## Adding Languages

View File

@@ -67,10 +67,13 @@ neogen.setup = function(opts)
languages = {
lua = require("neogen.configurations.lua"),
python = require("neogen.configurations.python"),
javascript = require("neogen.configurations.javascript")
},
})
neogen.generate_command()
if neogen.configuration.enabled == true then
neogen.generate_command()
end
end
return neogen

View File

@@ -0,0 +1,40 @@
return {
parent = { "function_declaration" },
data = {
["function_declaration"] = {
["0"] = {
extract = function (node)
local results = {}
local tree = {
{ retrieve = "first", node_type = "formal_parameters", subtree = {
{ retrieve = "all", node_type = "identifier", extract = true }
} },
{ retrieve = "first", node_type = "statement_block", subtree = {
{ retrieve = "first", 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)
results.parameters = res.identifier
results.return_statement = res.return_statement
return results
end
}
}
},
template = {
annotation_convention = "jsdoc",
use_default_comment = false,
jsdoc = {
{ nil, "/**" },
{ "parameters", " * @param {any} %s " },
{ "return_statement", " * @returns {any} " },
{ nil, " */" }
}
}
}