feat(lua) Add support for file annotations (#31)

This commit is contained in:
danymat
2022-01-09 14:30:49 +01:00
parent d8f0d24cc6
commit 76a80479d7
2 changed files with 18 additions and 2 deletions

View File

@@ -61,6 +61,7 @@ return {
func = { "function", "local_function", "local_variable_declaration", "field", "variable_declaration" },
class = { "local_variable_declaration", "variable_declaration" },
type = { "local_variable_declaration", "variable_declaration" },
file = { "program" },
},
data = {
@@ -119,6 +120,15 @@ return {
},
},
},
file = {
["program"] = {
["0"] = {
extract = function()
return {}
end,
},
},
},
},
-- Custom lua locator that escapes from comments
@@ -133,7 +143,13 @@ return {
annotation_convention = "emmylua",
emmylua = {
{ nil, "- $1", { type = { "class", "func" } } }, -- add this string only on requested types
{ nil, "- $1", { no_results = true } }, -- Shows only when there's no results from the granulator
{ nil, "- $1", { no_results = true, type = { "class", "func" } } }, -- Shows only when there's no results from the granulator
{ nil, "- @module $1", { no_results = true, type = { "file" } } },
{ nil, "- @author $1", { no_results = true, type = { "file" } } },
{ nil, "- @license $1", { no_results = true, type = { "file" } } },
{ nil, "- @license $1", { no_results = true, type = { "file" } } },
{ nil, "", { no_results = true, type = { "file" } } },
{ "parameters", "- @param %s $1|any" },
{ "vararg", "- @vararg $1|any" },
{ "return_statement", "- @return $1|any" },

View File

@@ -2,7 +2,7 @@ local ts_utils = require("nvim-treesitter.ts_utils")
return 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
if node_info.current and 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()