feat: add symbol ranges for treesitter and markdown (#52)

This adds support for the end_lnum and end_col fields to the treesitter
and markdown backends. Now all backends store both the start and the end
of a symbol. At the moment this is only being used for detecting exact
position matching, so the lualine component and highlighting when
`highlight_closest = false`.

This change also made the C, C++, and Julia treesitter backends a bit
more correct and robust.
This commit is contained in:
Steven Arcangeli 2022-02-03 17:21:25 -08:00
parent 32edfc147d
commit 91350456c1
33 changed files with 379 additions and 67 deletions

View file

@ -12,6 +12,7 @@ M.is_supported = function(bufnr)
end
M.fetch_symbols_sync = function(timeout)
local extensions = require("aerial.backends.treesitter.extensions")
local bufnr = 0
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
local items = {}
@ -46,6 +47,8 @@ M.fetch_symbols_sync = function(timeout)
inside_code_block = not inside_code_block
end
end
-- This sets the proper end_lnum and end_col
extensions.markdown.postprocess_symbols(bufnr, items)
backends.set_symbols(bufnr, items)
end

View file

@ -1,30 +1,56 @@
local ts_utils = require("nvim-treesitter.ts_utils")
local utils = require("nvim-treesitter.utils")
-- This file is used by the markdown backend as well.
-- We pcall(require) so it doesn't error when nvim-treesitter isn't installed.
local _, ts_utils = pcall(require, "nvim-treesitter.ts_utils")
local _, utils = pcall(require, "nvim-treesitter.utils")
local M = {}
local function default_get_parent(stack, match, node)
for i = #stack, 1, -1 do
local last_node = stack[i].node
if ts_utils.is_parent(last_node, node) then
return stack[i].item, last_node, i
else
table.remove(stack, i)
local default_methods = {
get_parent = function(stack, match, node)
for i = #stack, 1, -1 do
local last_node = stack[i].node
if ts_utils.is_parent(last_node, node) then
return stack[i].item, last_node, i
else
table.remove(stack, i)
end
end
end
return nil, nil, 0
end
local function default_postprocess(bufnr, item, match) end
return nil, nil, 0
end,
postprocess = function(bufnr, item, match) end,
postprocess_symbols = function(bufnr, items) end,
}
setmetatable(M, {
__index = function()
return {
get_parent = default_get_parent,
postprocess = default_postprocess,
}
return default_methods
end,
})
local function get_line_len(bufnr, lnum)
return vim.api.nvim_strwidth(vim.api.nvim_buf_get_lines(bufnr, lnum - 1, lnum, true)[1])
end
local function set_end_range(bufnr, items, last_line)
if not items then
return
end
if not last_line then
last_line = vim.api.nvim_buf_line_count(bufnr)
end
local prev = nil
for _, item in ipairs(items) do
if prev then
prev.end_lnum = item.lnum - 1
prev.end_col = get_line_len(bufnr, prev.end_lnum)
set_end_range(bufnr, prev.children, prev.end_lnum)
end
prev = item
end
prev.end_lnum = last_line
prev.end_col = get_line_len(bufnr, last_line)
set_end_range(bufnr, prev.children, last_line)
end
M.markdown = {
get_parent = function(stack, match, node)
local level_node = (utils.get_at_path(match, "level") or {}).node
@ -44,10 +70,12 @@ M.markdown = {
item.name = string.gsub(item.name, "^%s*", "")
return true
end,
postprocess_symbols = function(bufnr, items)
set_end_range(bufnr, items)
end,
}
M.rust = {
get_parent = default_get_parent,
postprocess = function(bufnr, item, match)
if item.kind == "Class" then
local trait_node = (utils.get_at_path(match, "trait") or {}).node
@ -63,7 +91,6 @@ M.rust = {
}
M.ruby = {
get_parent = default_get_parent,
postprocess = function(bufnr, item, match)
local method = (utils.get_at_path(match, "method") or {}).node
if method then
@ -76,7 +103,6 @@ M.ruby = {
}
M.lua = {
get_parent = default_get_parent,
postprocess = function(bufnr, item, match)
local method = (utils.get_at_path(match, "method") or {}).node
if method then
@ -89,7 +115,6 @@ M.lua = {
}
M.javascript = {
get_parent = default_get_parent,
postprocess = function(bufnr, item, match)
local method = (utils.get_at_path(match, "method") or {}).node
local modifier = (utils.get_at_path(match, "modifier") or {}).node
@ -105,4 +130,38 @@ M.javascript = {
end,
}
local function c_postprocess(bufnr, item, match)
local root = (utils.get_at_path(match, "root") or {}).node
if root then
while
root
and not vim.tbl_contains(
{ "identifier", "field_identifier", "qualified_identifier" },
root:type()
)
do
-- Search the declarator downwards until you hit the identifier
root = root:field("declarator")[1]
end
item.name = ts_utils.get_node_text(root, bufnr)[1] or "<parse error>"
end
end
M.c = {
postprocess = c_postprocess,
}
M.cpp = {
postprocess = c_postprocess,
}
M.rst = {
postprocess_symbols = function(bufnr, items)
set_end_range(bufnr, items)
end,
}
for _, lang in pairs(M) do
setmetatable(lang, { __index = default_methods })
end
return M

View file

@ -4,6 +4,12 @@ local language_kind_map = require("aerial.backends.treesitter.language_kind_map"
local util = require("aerial.backends.util")
local M = {}
-- Custom capture groups:
-- type: Used to determine the SymbolKind (via language_kind_map)
-- name (optional): The text of this node will be used in the display
-- start (optional): The location of the start of this symbol (default @type)
-- end (optional): The location of the end of this symbol (default @start)
M.is_supported = function(bufnr)
local ok, parsers = pcall(require, "nvim-treesitter.parsers")
if not ok then
@ -48,9 +54,10 @@ M.fetch_symbols_sync = function(timeout)
for match in query.iter_group_results(bufnr, "aerial", syntax_tree:root(), lang) do
local name_node = (utils.get_at_path(match, "name") or {}).node
local type_node = (utils.get_at_path(match, "type") or {}).node
-- The location capture name is optional. We default to the
-- The location capture groups are optional. We default to the
-- location of the @type capture
local loc_node = (utils.get_at_path(match, "location") or {}).node or type_node
local start_node = (utils.get_at_path(match, "start") or {}).node or type_node
local end_node = (utils.get_at_path(match, "end") or {}).node or start_node
local parent_item, parent_node, level = ext.get_parent(stack, match, type_node)
-- Sometimes our queries will match the same node twice.
-- Detect that (type_node == parent_node), and skip dupes.
@ -67,7 +74,8 @@ M.fetch_symbols_sync = function(timeout)
if not include_kind[kind] then
goto continue
end
local row, col = loc_node:start()
local row, col = start_node:start()
local end_row, end_col = end_node:end_()
local name
if name_node then
name = ts_utils.get_node_text(name_node, bufnr)[1] or "<parse error>"
@ -80,7 +88,9 @@ M.fetch_symbols_sync = function(timeout)
level = level,
parent = parent_item,
lnum = row + 1,
end_lnum = end_row + 1,
col = col,
end_col = end_col,
}
ext.postprocess(bufnr, item, match)
if item.parent then
@ -95,6 +105,7 @@ M.fetch_symbols_sync = function(timeout)
::continue::
end
ext.postprocess_symbols(bufnr, items)
backends.set_symbols(bufnr, items)
end

View file

@ -4,13 +4,13 @@ return {
},
c = {
enum_specifier = "Enum",
function_declarator = "Function",
function_definition = "Function",
struct_specifier = "Struct",
},
cpp = {
class_specifier = "Class",
enum_specifier = "Enum",
function_declarator = "Function",
function_definition = "Function",
struct_specifier = "Struct",
},
c_sharp = {
@ -25,8 +25,7 @@ return {
class_definition = "Class",
constructor_signature = "Constructor",
function_signature = "Function",
getter_signature = "Function",
setter_signature = "Function",
method_signature = "Method",
enum_declaration = "Enum",
},
go = {

View file

@ -236,9 +236,6 @@ M.get_position_in_win = function(bufnr, winid)
local exact_symbol = symbol
while
exact_symbol
-- TODO: end_lnum/end_col isn't supported by all backends yet
and exact_symbol.end_lnum
and exact_symbol.end_col
and (
exact_symbol.lnum > lnum
or exact_symbol.end_lnum < lnum

View file

@ -1,6 +1,11 @@
(type_definition
type: [(enum_specifier) (struct_specifier)] @type
declarator: (type_identifier) @name) @location
declarator: (type_identifier) @name) @start
(function_declarator
declarator: (identifier) @name) @type
(
(declaration) @root @start
.
(function_definition) @type @end
)
(function_definition) @type @root

View file

@ -1,5 +1,4 @@
(function_declarator
declarator: [(identifier) (field_identifier) (qualified_identifier)] @name) @type
(function_definition) @root @type
(struct_specifier
name: (type_identifier) @name

View file

@ -4,14 +4,26 @@
(constructor_signature
name: (identifier) @name) @type
(function_signature
name: (identifier) @name) @type
(
(method_signature
[(function_signature
name: (identifier) @name)
(getter_signature
name: (identifier) @name)
(setter_signature
name: (identifier) @name)
]
) @type
.
(function_body) @end
)
(getter_signature
name: (identifier) @name) @type
(setter_signature
name: (identifier) @name) @type
(
(function_signature
name: (identifier) @name) @type
.
(function_body) @end
)
(enum_declaration
name: (identifier) @name) @type

View file

@ -4,7 +4,7 @@
(type_declaration
(type_spec
name: (type_identifier) @name
type: (struct_type) @type)) @location
type: (struct_type) @type)) @start
(method_declaration
name: (field_identifier) @name

View file

@ -1,4 +1,4 @@
(pair
key: (string
(string_content) @name)
value: (object) @type) @location
value: (object) @type) @start

View file

@ -6,7 +6,7 @@
(assignment_expression
. (call_expression
(identifier) @name) @type) @location
(identifier) @name) @type) @start
(abstract_definition
name: (identifier) @name) @type

View file

@ -6,23 +6,23 @@
(variable_list
name: [(identifier) (dot_index_expression)] @name)
(expression_list
value: (function_definition) @type))) @location
value: (function_definition) @type))) @start
(assignment_statement
(variable_list
name: [(identifier) (dot_index_expression)] @name)
(expression_list
value: (function_definition) @type)) @location
value: (function_definition) @type)) @start
(field
name: (identifier) @name
value: (function_definition) @type) @location
value: (function_definition) @type) @start
(function_call
name: (identifier) @method @name (#any-of? @method "describe" "it" "before_each" "after_each" "setup" "teardown")
arguments: (arguments
(string)? @name
(function_definition) @type)
) @location
) @start
(function_definition) @type

View file

@ -69,8 +69,9 @@ M.assert_tree_equals = function(received, expected, path)
for i, child in ipairs(received) do
local exp_child = expected[i]
local lines = { "Symbol mismatch: {" }
for _, field in ipairs({ "kind", "name", "level", "lnum", "col" }) do
local s_field = string.rep(" ", 5 - string.len(field)) .. field
local fields = { "kind", "name", "level", "lnum", "col", "end_lnum", "end_col" }
for _, field in ipairs(fields) do
local s_field = string.rep(" ", 8 - string.len(field)) .. field
local line = string.format("%s = %s", s_field, exp_child[field])
if child[field] ~= exp_child[field] then
line = line .. string.format(" [%s]", child[field])
@ -79,7 +80,6 @@ M.assert_tree_equals = function(received, expected, path)
end
table.insert(lines, "}")
local err_msg = table.concat(lines, "\n")
local fields = { "kind", "name", "level", "lnum", "col" }
for _, field in ipairs(fields) do
assert.equals(exp_child[field], child[field], err_msg)
end

View file

@ -9,6 +9,8 @@ describe("treesitter bash", function()
level = 0,
lnum = 3,
col = 0,
end_lnum = 5,
end_col = 1,
},
})
end)

View file

@ -8,35 +8,45 @@ describe("treesitter c", function()
name = "fn_1",
level = 0,
lnum = 3,
col = 5,
col = 0,
end_lnum = 3,
end_col = 22,
},
{
kind = "Function",
name = "fn_2",
level = 0,
lnum = 5,
col = 6,
col = 0,
end_lnum = 5,
end_col = 34,
},
{
kind = "Function",
name = "fn_3",
level = 0,
lnum = 7,
col = 5,
col = 0,
end_lnum = 7,
end_col = 14,
},
{
kind = "Function",
name = "fn_4",
level = 0,
lnum = 9,
col = 6,
col = 0,
end_lnum = 9,
end_col = 26,
},
{
kind = "Function",
name = "fn_5",
level = 0,
lnum = 11,
col = 7,
col = 0,
end_lnum = 11,
end_col = 27,
},
{
kind = "Enum",
@ -44,6 +54,8 @@ describe("treesitter c", function()
level = 0,
lnum = 13,
col = 0,
end_lnum = 15,
end_col = 8,
},
{
kind = "Struct",
@ -51,6 +63,8 @@ describe("treesitter c", function()
level = 0,
lnum = 17,
col = 0,
end_lnum = 19,
end_col = 7,
},
})
end)

View file

@ -8,7 +8,9 @@ describe("treesitter cpp", function()
name = "fn_1",
level = 0,
lnum = 1,
col = 5,
col = 0,
end_lnum = 1,
end_col = 14,
},
{
kind = "Struct",
@ -16,6 +18,8 @@ describe("treesitter cpp", function()
level = 0,
lnum = 3,
col = 0,
end_lnum = 3,
end_col = 14,
},
{
kind = "Struct",
@ -23,6 +27,8 @@ describe("treesitter cpp", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 6,
end_col = 1,
},
{
kind = "Enum",
@ -30,6 +36,8 @@ describe("treesitter cpp", function()
level = 0,
lnum = 8,
col = 0,
end_lnum = 8,
end_col = 12,
},
{
kind = "Class",
@ -37,13 +45,17 @@ describe("treesitter cpp", function()
level = 0,
lnum = 10,
col = 0,
end_lnum = 13,
end_col = 1,
children = {
{
kind = "Function",
name = "meth_1",
level = 1,
lnum = 12,
col = 7,
col = 2,
end_lnum = 12,
end_col = 18,
},
},
},
@ -52,21 +64,27 @@ describe("treesitter cpp", function()
name = "A::bar",
level = 0,
lnum = 15,
col = 5,
col = 0,
end_lnum = 15,
end_col = 16,
},
{
kind = "Function",
name = "fn_2",
level = 0,
lnum = 17,
col = 5,
col = 0,
end_lnum = 17,
end_col = 14,
},
{
kind = "Function",
name = "fn_3",
level = 0,
lnum = 19,
col = 6,
col = 0,
end_lnum = 19,
end_col = 15,
},
})
end)

View file

@ -9,6 +9,8 @@ describe("treesitter csharp", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 4,
end_col = 1,
children = {
{
kind = "Constructor",
@ -16,6 +18,8 @@ describe("treesitter csharp", function()
level = 1,
lnum = 2,
col = 2,
end_lnum = 2,
end_col = 18,
},
{
kind = "Method",
@ -23,6 +27,8 @@ describe("treesitter csharp", function()
level = 1,
lnum = 3,
col = 2,
end_lnum = 3,
end_col = 25,
},
},
},
@ -32,6 +38,8 @@ describe("treesitter csharp", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 5,
end_col = 20,
},
{
kind = "Struct",
@ -39,6 +47,8 @@ describe("treesitter csharp", function()
level = 0,
lnum = 6,
col = 0,
end_lnum = 6,
end_col = 22,
},
})
end)

View file

@ -9,6 +9,8 @@ describe("treesitter dart", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 11,
end_col = 1,
children = {
{
kind = "Constructor",
@ -16,27 +18,35 @@ describe("treesitter dart", function()
level = 1,
lnum = 2,
col = 2,
end_lnum = 2,
end_col = 11,
},
{
kind = "Function",
kind = "Method",
name = "meth_1",
level = 1,
lnum = 4,
col = 2,
end_lnum = 4,
end_col = 19,
},
{
kind = "Function",
kind = "Method",
name = "prop",
level = 1,
lnum = 6,
col = 2,
end_lnum = 8,
end_col = 3,
},
{
kind = "Function",
kind = "Method",
name = "prop",
level = 1,
lnum = 10,
col = 2,
end_lnum = 10,
end_col = 31,
},
},
},
@ -46,6 +56,8 @@ describe("treesitter dart", function()
level = 0,
lnum = 13,
col = 0,
end_lnum = 13,
end_col = 21,
},
{
kind = "Enum",
@ -53,6 +65,8 @@ describe("treesitter dart", function()
level = 0,
lnum = 15,
col = 0,
end_lnum = 17,
end_col = 1,
},
})
end)

View file

@ -9,6 +9,8 @@ describe("treesitter go", function()
level = 0,
lnum = 3,
col = 0,
end_lnum = 3,
end_col = 14,
},
{
kind = "Struct",
@ -16,6 +18,8 @@ describe("treesitter go", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 5,
end_col = 18,
},
{
kind = "Method",
@ -23,6 +27,8 @@ describe("treesitter go", function()
level = 0,
lnum = 7,
col = 0,
end_lnum = 7,
end_col = 23,
},
})
end)

View file

@ -9,6 +9,8 @@ describe("treesitter java", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 3,
end_col = 1,
children = {
{
kind = "Method",
@ -16,6 +18,8 @@ describe("treesitter java", function()
level = 1,
lnum = 2,
col = 2,
end_lnum = 2,
end_col = 16,
},
},
},
@ -25,6 +29,8 @@ describe("treesitter java", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 7,
end_col = 1,
children = {
{
kind = "Method",
@ -32,6 +38,8 @@ describe("treesitter java", function()
level = 1,
lnum = 6,
col = 2,
end_lnum = 6,
end_col = 19,
},
},
},
@ -41,6 +49,8 @@ describe("treesitter java", function()
level = 0,
lnum = 9,
col = 0,
end_lnum = 9,
end_col = 13,
},
})
end)

View file

@ -9,6 +9,8 @@ describe("treesitter js", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 3,
end_col = 1,
children = {
{
kind = "Method",
@ -16,6 +18,8 @@ describe("treesitter js", function()
level = 1,
lnum = 2,
col = 2,
end_lnum = 2,
end_col = 13,
},
},
},
@ -25,6 +29,8 @@ describe("treesitter js", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 5,
end_col = 18,
},
{
kind = "Function",
@ -32,6 +38,8 @@ describe("treesitter js", function()
level = 0,
lnum = 7,
col = 0,
end_lnum = 19,
end_col = 2,
children = {
{
kind = "Function",
@ -39,6 +47,8 @@ describe("treesitter js", function()
level = 1,
lnum = 8,
col = 2,
end_lnum = 8,
end_col = 20,
},
{
kind = "Function",
@ -46,6 +56,8 @@ describe("treesitter js", function()
level = 1,
lnum = 9,
col = 2,
end_lnum = 9,
end_col = 21,
},
{
kind = "Function",
@ -53,6 +65,8 @@ describe("treesitter js", function()
level = 1,
lnum = 10,
col = 2,
end_lnum = 10,
end_col = 21,
},
{
kind = "Function",
@ -60,6 +74,8 @@ describe("treesitter js", function()
level = 1,
lnum = 11,
col = 2,
end_lnum = 11,
end_col = 22,
},
{
kind = "Function",
@ -67,6 +83,8 @@ describe("treesitter js", function()
level = 1,
lnum = 12,
col = 2,
end_lnum = 12,
end_col = 44,
},
{
kind = "Function",
@ -74,6 +92,8 @@ describe("treesitter js", function()
level = 1,
lnum = 13,
col = 2,
end_lnum = 13,
end_col = 38,
},
{
kind = "Function",
@ -81,6 +101,8 @@ describe("treesitter js", function()
level = 1,
lnum = 14,
col = 2,
end_lnum = 14,
end_col = 39,
},
{
kind = "Function",
@ -88,6 +110,8 @@ describe("treesitter js", function()
level = 1,
lnum = 15,
col = 2,
end_lnum = 15,
end_col = 29,
},
{
kind = "Function",
@ -95,6 +119,8 @@ describe("treesitter js", function()
level = 1,
lnum = 16,
col = 2,
end_lnum = 18,
end_col = 4,
children = {
{
kind = "Function",
@ -102,6 +128,8 @@ describe("treesitter js", function()
level = 2,
lnum = 17,
col = 4,
end_lnum = 17,
end_col = 50,
},
},
},

View file

@ -9,6 +9,8 @@ describe("treesitter json", function()
level = 0,
lnum = 3,
col = 2,
end_lnum = 3,
end_col = 12,
},
{
kind = "Class",
@ -16,6 +18,8 @@ describe("treesitter json", function()
level = 0,
lnum = 4,
col = 2,
end_lnum = 8,
end_col = 3,
children = {
{
kind = "Class",
@ -23,6 +27,8 @@ describe("treesitter json", function()
level = 1,
lnum = 5,
col = 4,
end_lnum = 7,
end_col = 5,
},
},
},

View file

@ -9,6 +9,8 @@ describe("treesitter julia", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 20,
end_col = 3,
children = {
{
kind = "Constant",
@ -16,6 +18,8 @@ describe("treesitter julia", function()
level = 1,
lnum = 3,
col = 0,
end_lnum = 3,
end_col = 24,
},
{
kind = "Function",
@ -23,6 +27,8 @@ describe("treesitter julia", function()
level = 1,
lnum = 5,
col = 0,
end_lnum = 6,
end_col = 3,
},
{
kind = "Function",
@ -30,6 +36,8 @@ describe("treesitter julia", function()
level = 1,
lnum = 8,
col = 0,
end_lnum = 8,
end_col = 18,
},
{
kind = "Interface",
@ -37,6 +45,8 @@ describe("treesitter julia", function()
level = 1,
lnum = 10,
col = 0,
end_lnum = 10,
end_col = 24,
},
{
kind = "Class",
@ -44,6 +54,8 @@ describe("treesitter julia", function()
level = 1,
lnum = 12,
col = 0,
end_lnum = 15,
end_col = 3,
children = {
{
kind = "Function",
@ -51,6 +63,8 @@ describe("treesitter julia", function()
level = 2,
lnum = 13,
col = 4,
end_lnum = 13,
end_col = 22,
},
{
kind = "Function",
@ -58,6 +72,8 @@ describe("treesitter julia", function()
level = 2,
lnum = 14,
col = 4,
end_lnum = 14,
end_col = 22,
},
},
},
@ -67,6 +83,8 @@ describe("treesitter julia", function()
level = 1,
lnum = 17,
col = 0,
end_lnum = 18,
end_col = 3,
},
},
},

View file

@ -9,6 +9,8 @@ describe("treesitter lua", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 3,
end_col = 3,
},
{
kind = "Function",
@ -16,6 +18,8 @@ describe("treesitter lua", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 7,
end_col = 3,
},
{
kind = "Function",
@ -23,6 +27,8 @@ describe("treesitter lua", function()
level = 0,
lnum = 9,
col = 0,
end_lnum = 11,
end_col = 3,
},
{
kind = "Function",
@ -30,6 +36,8 @@ describe("treesitter lua", function()
level = 0,
lnum = 13,
col = 0,
end_lnum = 18,
end_col = 3,
children = {
{
kind = "Function",
@ -37,6 +45,8 @@ describe("treesitter lua", function()
level = 1,
lnum = 14,
col = 7,
end_lnum = 16,
end_col = 5,
},
},
},
@ -46,6 +56,8 @@ describe("treesitter lua", function()
level = 0,
lnum = 21,
col = 2,
end_lnum = 23,
end_col = 5,
},
{
kind = "Function",
@ -53,6 +65,8 @@ describe("treesitter lua", function()
level = 0,
lnum = 26,
col = 0,
end_lnum = 26,
end_col = 23,
},
{
kind = "Function",
@ -60,6 +74,8 @@ describe("treesitter lua", function()
level = 0,
lnum = 27,
col = 0,
end_lnum = 27,
end_col = 21,
},
{
kind = "Function",
@ -67,6 +83,8 @@ describe("treesitter lua", function()
level = 0,
lnum = 29,
col = 0,
end_lnum = 33,
end_col = 4,
children = {
{
kind = "Function",
@ -74,6 +92,8 @@ describe("treesitter lua", function()
level = 1,
lnum = 30,
col = 2,
end_lnum = 30,
end_col = 29,
},
{
kind = "Function",
@ -81,6 +101,8 @@ describe("treesitter lua", function()
level = 1,
lnum = 31,
col = 2,
end_lnum = 31,
end_col = 28,
},
{
kind = "Function",
@ -88,6 +110,8 @@ describe("treesitter lua", function()
level = 1,
lnum = 32,
col = 2,
end_lnum = 32,
end_col = 42,
},
},
},

View file

@ -8,6 +8,8 @@ describe("markdown", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 4,
end_col = 0,
children = {
{
kind = "Interface",
@ -15,6 +17,8 @@ describe("markdown", function()
level = 1,
lnum = 3,
col = 0,
end_lnum = 4,
end_col = 0,
},
},
},
@ -24,6 +28,8 @@ describe("markdown", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 15,
end_col = 8,
children = {
{
kind = "Interface",
@ -31,6 +37,8 @@ describe("markdown", function()
level = 2,
lnum = 7,
col = 0,
end_lnum = 15,
end_col = 8,
children = {
{
kind = "Interface",
@ -38,6 +46,8 @@ describe("markdown", function()
level = 3,
lnum = 13,
col = 0,
end_lnum = 15,
end_col = 8,
},
},
},

View file

@ -11,3 +11,5 @@
```
#### Title 5
contents

View file

@ -9,6 +9,8 @@ describe("treesitter python", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 2,
end_col = 8,
},
{
kind = "Class",
@ -16,6 +18,8 @@ describe("treesitter python", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 7,
end_col = 12,
children = {
{
kind = "Function",
@ -23,6 +27,8 @@ describe("treesitter python", function()
level = 1,
lnum = 6,
col = 4,
end_lnum = 7,
end_col = 12,
},
},
},

View file

@ -9,6 +9,8 @@ describe("treesitter rst", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 3,
end_col = 0,
},
{
kind = "Interface",
@ -16,6 +18,8 @@ describe("treesitter rst", function()
level = 0,
lnum = 4,
col = 0,
end_lnum = 6,
end_col = 8,
},
})
end)

View file

@ -3,3 +3,4 @@ Title 1
Title 2
-------
contents

View file

@ -9,6 +9,8 @@ describe("treesitter ruby", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 7,
end_col = 3,
children = {
{
kind = "Class",
@ -16,6 +18,8 @@ describe("treesitter ruby", function()
level = 1,
lnum = 2,
col = 2,
end_lnum = 4,
end_col = 5,
children = {
{
kind = "Method",
@ -23,6 +27,8 @@ describe("treesitter ruby", function()
level = 2,
lnum = 3,
col = 4,
end_lnum = 3,
end_col = 20,
},
},
},
@ -32,6 +38,8 @@ describe("treesitter ruby", function()
level = 1,
lnum = 6,
col = 2,
end_lnum = 6,
end_col = 18,
},
},
},
@ -41,6 +49,8 @@ describe("treesitter ruby", function()
level = 0,
lnum = 9,
col = 0,
end_lnum = 16,
end_col = 3,
children = {
{
kind = "Method",
@ -48,6 +58,8 @@ describe("treesitter ruby", function()
level = 1,
lnum = 10,
col = 2,
end_lnum = 11,
end_col = 5,
},
{
kind = "Method",
@ -55,6 +67,8 @@ describe("treesitter ruby", function()
level = 1,
lnum = 12,
col = 2,
end_lnum = 13,
end_col = 5,
},
{
kind = "Method",
@ -62,6 +76,8 @@ describe("treesitter ruby", function()
level = 1,
lnum = 14,
col = 2,
end_lnum = 15,
end_col = 5,
},
},
},

View file

@ -9,6 +9,8 @@ describe("treesitter rust", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 22,
end_col = 1,
children = {
{
kind = "Enum",
@ -16,6 +18,8 @@ describe("treesitter rust", function()
level = 1,
lnum = 2,
col = 4,
end_lnum = 2,
end_col = 18,
},
{
kind = "Function",
@ -23,6 +27,8 @@ describe("treesitter rust", function()
level = 1,
lnum = 4,
col = 4,
end_lnum = 4,
end_col = 16,
},
{
kind = "Struct",
@ -30,6 +36,8 @@ describe("treesitter rust", function()
level = 1,
lnum = 6,
col = 4,
end_lnum = 6,
end_col = 22,
},
{
kind = "Interface",
@ -37,6 +45,8 @@ describe("treesitter rust", function()
level = 1,
lnum = 8,
col = 4,
end_lnum = 10,
end_col = 5,
children = {
{
kind = "Function",
@ -44,6 +54,8 @@ describe("treesitter rust", function()
level = 2,
lnum = 9,
col = 8,
end_lnum = 9,
end_col = 21,
},
},
},
@ -53,6 +65,8 @@ describe("treesitter rust", function()
level = 1,
lnum = 12,
col = 4,
end_lnum = 14,
end_col = 5,
children = {
{
kind = "Function",
@ -60,6 +74,8 @@ describe("treesitter rust", function()
level = 2,
lnum = 13,
col = 8,
end_lnum = 13,
end_col = 24,
},
},
},
@ -69,6 +85,8 @@ describe("treesitter rust", function()
level = 1,
lnum = 16,
col = 4,
end_lnum = 20,
end_col = 5,
children = {
{
kind = "Function",
@ -76,6 +94,8 @@ describe("treesitter rust", function()
level = 2,
lnum = 17,
col = 8,
end_lnum = 19,
end_col = 9,
},
},
},
@ -85,6 +105,8 @@ describe("treesitter rust", function()
level = 1,
lnum = 21,
col = 4,
end_lnum = 21,
end_col = 43,
},
},
},

View file

@ -9,6 +9,8 @@ describe("treesitter ts", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 1,
end_col = 19,
},
{
kind = "Function",
@ -16,6 +18,8 @@ describe("treesitter ts", function()
level = 0,
lnum = 3,
col = 0,
end_lnum = 3,
end_col = 22,
},
{
kind = "Interface",
@ -23,6 +27,8 @@ describe("treesitter ts", function()
level = 0,
lnum = 5,
col = 0,
end_lnum = 5,
end_col = 21,
},
{
kind = "Class",
@ -30,6 +36,8 @@ describe("treesitter ts", function()
level = 0,
lnum = 7,
col = 0,
end_lnum = 9,
end_col = 1,
children = {
{
kind = "Method",
@ -37,6 +45,8 @@ describe("treesitter ts", function()
level = 1,
lnum = 8,
col = 2,
end_lnum = 8,
end_col = 14,
},
},
},
@ -46,6 +56,8 @@ describe("treesitter ts", function()
level = 0,
lnum = 11,
col = 0,
end_lnum = 11,
end_col = 17,
},
})
end)

View file

@ -9,6 +9,8 @@ describe("treesitter vim", function()
level = 0,
lnum = 1,
col = 0,
end_lnum = 2,
end_col = 11,
},
{
kind = "Function",
@ -16,6 +18,8 @@ describe("treesitter vim", function()
level = 0,
lnum = 4,
col = 0,
end_lnum = 5,
end_col = 11,
},
})
end)