Add basic support for javascript
At the moment, it recognizes simple functions, their params and their direct return statements.
This commit is contained in:
@@ -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
|
||||
|
||||
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