Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ There is a list of supported languages and fields, with their annotation style
| typescript | [JSDoc](https://jsdoc.app) (`"jsdoc"`) <br> [TSDoc](https://tsdoc.org) (`"tsdoc"`) | `func`, `class`, `type`, `file` |
| typescriptreact | [JSDoc](https://jsdoc.app) (`"jsdoc"`) <br> [TSDoc](https://tsdoc.org) (`"tsdoc"`) | `func`, `class`, `type`, `file` |
| vue | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `func`, `class`, `type`, `file` |
| R | [roxygen2](https://roxygen2.r-lib.org) (`"roxygen2"`) | `func` |

## Adding Languages

Expand Down
63 changes: 63 additions & 0 deletions lua/neogen/configurations/R.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
local template = require("neogen.template")
local extractors = require("neogen.utilities.extractors")
local nodes_utils = require("neogen.utilities.nodes")
local i = require("neogen.types.template").item

return {
parent = {
func = { "binary_operator" },
},
data = {
func = {
["binary_operator"] = {
["0"] = {
extract = function(node)
local function_name_node = node:child(0)
local function_name = vim.treesitter.get_node_text(function_name_node, 0)
local res = {}
res["function_name"] = { function_name }

local parameters_tree = {
{
retrieve = "first",
node_type = "function_definition",
subtree = {
{
retrieve = "first",
node_type = "parameters",
subtree = {
{
retrieve = "all",
node_type = "parameter",
subtree = {
{
retrieve = "first",
node_type = "identifier|dots",
extract = true,
as = i.Parameter,
},
},
},
},
},
},
},
}

local parameters_nodes = nodes_utils:matching_nodes_from(node, parameters_tree)
local params_res = extractors:extract_from_matched(parameters_nodes)

for k, v in pairs(params_res) do
if k == "parameters" then
res[k] = v
end
end

return res
end,
},
},
},
},
template = template:add_default_annotation("roxygen2"),
}
63 changes: 63 additions & 0 deletions lua/neogen/configurations/r.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
local template = require("neogen.template")
local extractors = require("neogen.utilities.extractors")
local nodes_utils = require("neogen.utilities.nodes")
local i = require("neogen.types.template").item

return {
parent = {
func = { "binary_operator" },
},
data = {
func = {
["binary_operator"] = {
["0"] = {
extract = function(node)
local function_name_node = node:child(0)
local function_name = vim.treesitter.get_node_text(function_name_node, 0)
local res = {}
res["function_name"] = { function_name }

local parameters_tree = {
{
retrieve = "first",
node_type = "function_definition",
subtree = {
{
retrieve = "first",
node_type = "parameters",
subtree = {
{
retrieve = "all",
node_type = "parameter",
subtree = {
{
retrieve = "first",
node_type = "identifier|dots",
extract = true,
as = i.Parameter,
},
},
},
},
},
},
},
}

local parameters_nodes = nodes_utils:matching_nodes_from(node, parameters_tree)
local params_res = extractors:extract_from_matched(parameters_nodes)

for k, v in pairs(params_res) do
if k == "parameters" then
res[k] = v
end
end

return res
end,
},
},
},
},
template = template:add_default_annotation("roxygen2"),
}
9 changes: 9 additions & 0 deletions lua/neogen/templates/roxygen2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local i = require("neogen.types.template").item

return {
{ nil, "#' @title $1", { no_results = false, type = { "func" } } },
{ nil, "#' @description", { no_results = false, type = { "func" } } },
{ i.Parameter, "#' @param %s" },
{ nil, "#' @return", { type = { "func" }, no_results = false } },
{ nil, "#' @export", { type = { "func" }, no_results = false } }
}