Add documentation

Added docs in multiple places, refactored some functions and changed
places.
This commit is contained in:
Daniel Mathiot
2021-08-21 07:31:57 +02:00
parent c4f3725af7
commit f42e14f633
6 changed files with 50 additions and 40 deletions

View File

@@ -1,3 +1,5 @@
local ts_utils = require("nvim-treesitter.ts_utils")
return {
-- Search for these nodes
parent = { "function", "local_function", "local_variable_declaration", "field", "variable_declaration"},
@@ -5,7 +7,9 @@ return {
-- Traverse down these nodes and extract the information as necessary
data = {
["function|local_function"] = {
-- Get second child from the parent node
["2"] = {
-- It has to be of type "parameters"
match = "parameters",
extract = function(node)
@@ -24,13 +28,13 @@ return {
match = "function_definition",
extract = function(node)
local regular_params = neogen.utility:extract_children_from("identifier", {
local regular_params = neogen.utility:extract_children_from({
[1] = "extract",
})(node)
}, "identifier")(node)
local varargs = neogen.utility:extract_children_from("spread", {
local varargs = neogen.utility:extract_children_from({
[1] = "extract",
})(node)
}, "spread")(node)
return {
parameters = regular_params,
@@ -42,16 +46,7 @@ return {
},
-- Custom lua locator that escapes from comments
locator = function(node_info, nodes_to_match)
-- We're dealing with a lua comment and we need to escape its grasp
if node_info.current:type() == "source" then
local start_row, _, _, _ = ts_utils.get_node_range(node_info.current)
vim.api.nvim_win_set_cursor(0, { start_row, 0 })
node_info.current = ts_utils.get_node_at_cursor()
end
return neogen.default_locator(node_info, nodes_to_match)
end,
locator = require('neogen.locators.lua'),
-- Use default granulator and generator
granulator = nil,