Add basic support for javascript
At the moment, it recognizes simple functions, their params and their direct return statements.
This commit is contained in:
@@ -91,6 +91,9 @@ There is a list of supported languages and fields, with their annotation style
|
|||||||
| python | | |
|
| python | | |
|
||||||
| | Google docstrings (`"google_docstrings"`) | `Args`, `Attributes`, `Returns` |
|
| | Google docstrings (`"google_docstrings"`) | `Args`, `Attributes`, `Returns` |
|
||||||
| | Numpydoc (`"numpydoc"`)| `Arguments`, `Attributes`, `Returns`|
|
| | Numpydoc (`"numpydoc"`)| `Arguments`, `Attributes`, `Returns`|
|
||||||
|
| javascript | | |
|
||||||
|
| | JSDoc (`"jsdoc"`) | `@param`, `@returns` |
|
||||||
|
|
||||||
|
|
||||||
## Adding Languages
|
## Adding Languages
|
||||||
|
|
||||||
|
|||||||
@@ -67,10 +67,13 @@ neogen.setup = function(opts)
|
|||||||
languages = {
|
languages = {
|
||||||
lua = require("neogen.configurations.lua"),
|
lua = require("neogen.configurations.lua"),
|
||||||
python = require("neogen.configurations.python"),
|
python = require("neogen.configurations.python"),
|
||||||
|
javascript = require("neogen.configurations.javascript")
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if neogen.configuration.enabled == true then
|
||||||
neogen.generate_command()
|
neogen.generate_command()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return neogen
|
return neogen
|
||||||
|
|||||||
40
lua/neogen/configurations/javascript.lua
Normal file
40
lua/neogen/configurations/javascript.lua
Normal 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, " */" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user