mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-05 21:10:15 -04:00
style: fill in missing code docs wherever applicable
This commit is contained in:
parent
fceb4ed0ec
commit
853b1ab39a
17 changed files with 431 additions and 191 deletions
|
|
@ -15,16 +15,27 @@ M.comment_parsers = {
|
|||
phpdoc = true,
|
||||
}
|
||||
|
||||
---@param root TSNode
|
||||
---@param lnum integer
|
||||
---@return TSNode
|
||||
local function get_first_node_at_line(root, lnum)
|
||||
local col = vim.fn.indent(lnum)
|
||||
return root:descendant_for_range(lnum - 1, col, lnum - 1, col)
|
||||
end
|
||||
|
||||
---@param root TSNode
|
||||
---@param lnum integer
|
||||
---@return TSNode
|
||||
local function get_last_node_at_line(root, lnum)
|
||||
local col = #vim.fn.getline(lnum) - 1
|
||||
return root:descendant_for_range(lnum - 1, col, lnum - 1, col)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param node TSNode
|
||||
---@param delimiter string
|
||||
---@return TSNode|nil child
|
||||
---@return boolean|nil is_end
|
||||
local function find_delimiter(bufnr, node, delimiter)
|
||||
for child, _ in node:iter_children() do
|
||||
if child:type() == delimiter then
|
||||
|
|
@ -77,7 +88,7 @@ function M.get_indent(lnum)
|
|||
end
|
||||
|
||||
-- Get language tree with smallest range around node that's not a comment parser
|
||||
local root, lang_tree
|
||||
local root, lang_tree ---@type TSNode, LanguageTree
|
||||
parser:for_each_tree(function(tstree, tree)
|
||||
if not tstree or M.comment_parsers[tree:lang()] then
|
||||
return
|
||||
|
|
@ -98,7 +109,7 @@ function M.get_indent(lnum)
|
|||
|
||||
local q = get_indents(vim.api.nvim_get_current_buf(), root, lang_tree:lang())
|
||||
local is_empty_line = string.match(vim.fn.getline(lnum), "^%s*$") ~= nil
|
||||
local node
|
||||
local node ---@type TSNode
|
||||
if is_empty_line then
|
||||
local prevlnum = vim.fn.prevnonblank(lnum)
|
||||
node = get_last_node_at_line(root, prevlnum)
|
||||
|
|
@ -171,8 +182,9 @@ function M.get_indent(lnum)
|
|||
-- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum)
|
||||
if q.aligned_indent[node:id()] and srow ~= erow and (srow ~= lnum - 1) then
|
||||
local metadata = q.aligned_indent[node:id()]
|
||||
local o_delim_node, is_last_in_line
|
||||
local o_delim_node, is_last_in_line ---@type TSNode|nil, boolean|nil
|
||||
if metadata.delimiter then
|
||||
---@type string
|
||||
local opening_delimiter = metadata.delimiter and metadata.delimiter:sub(1, 1)
|
||||
o_delim_node, is_last_in_line = find_delimiter(bufnr, node, opening_delimiter)
|
||||
else
|
||||
|
|
@ -198,8 +210,10 @@ function M.get_indent(lnum)
|
|||
return indent
|
||||
end
|
||||
|
||||
---@type table<integer, string>
|
||||
local indent_funcs = {}
|
||||
|
||||
---@param bufnr integer
|
||||
function M.attach(bufnr)
|
||||
indent_funcs[bufnr] = vim.bo.indentexpr
|
||||
vim.bo.indentexpr = "nvim_treesitter#indent()"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue