mirror of https://github.com/neovim/neovim.git
Compare commits
9 Commits
575e01968c
...
e6569183b0
Author | SHA1 | Date |
---|---|---|
vanaigr | e6569183b0 | |
zeertzjq | 435dee74bb | |
zeertzjq | 694756252b | |
zeertzjq | e81eb34aa1 | |
zeertzjq | a1568f5df0 | |
zeertzjq | f1f5fb911b | |
vanaigr | e22707f249 | |
vanaigr | f642475767 | |
vanaigr | aa36e84474 |
|
@ -8208,6 +8208,10 @@ synconcealed({lnum}, {col}) *synconcealed()*
|
|||
synconcealed(lnum, 5) [1, 'X', 2]
|
||||
synconcealed(lnum, 6) [0, '', 0]
|
||||
|
||||
Note: Doesn't consider |matchadd()| highlighting items,
|
||||
since syntax and matching highlighting are two different
|
||||
mechanisms |syntax-vs-match|.
|
||||
|
||||
synstack({lnum}, {col}) *synstack()*
|
||||
Return a |List|, which is the stack of syntax items at the
|
||||
position {lnum} and {col} in the current window. {lnum} is
|
||||
|
|
|
@ -1375,6 +1375,19 @@ Finally, these constructs are unique to Perl:
|
|||
==============================================================================
|
||||
10. Highlighting matches *match-highlight*
|
||||
|
||||
*syntax-vs-match*
|
||||
Note that the match highlight mechanism is independent
|
||||
of |syntax-highlighting|, which is (usually) a buffer-local
|
||||
highlighting, while matching is window-local, both methods
|
||||
can be freely mixed. Match highlighting functions give you
|
||||
a bit more flexibility in when and how to apply, but are
|
||||
typically only used for temporary highlighting, without strict
|
||||
rules. Both methods can be used to conceal text.
|
||||
|
||||
Thus the matching functions like |matchadd()| won't consider
|
||||
syntax rules and functions like |synconcealed()| and the
|
||||
other way around.
|
||||
|
||||
*:mat* *:match*
|
||||
:mat[ch] {group} /{pattern}/
|
||||
Define a pattern to highlight in the current window. It will
|
||||
|
|
|
@ -3825,7 +3825,9 @@ Whether or not it is actually concealed depends on the value of the
|
|||
'conceallevel' option. The 'concealcursor' option is used to decide whether
|
||||
concealable items in the current line are displayed unconcealed to be able to
|
||||
edit the line.
|
||||
Another way to conceal text is with |matchadd()|.
|
||||
|
||||
Another way to conceal text is with |matchadd()|, but internally this works a
|
||||
bit differently |syntax-vs-match|.
|
||||
|
||||
concealends *:syn-concealends*
|
||||
|
||||
|
@ -3833,7 +3835,9 @@ When the "concealends" argument is given, the start and end matches of
|
|||
the region, but not the contents of the region, are marked as concealable.
|
||||
Whether or not they are actually concealed depends on the setting on the
|
||||
'conceallevel' option. The ends of a region can only be concealed separately
|
||||
in this way when they have their own highlighting via "matchgroup"
|
||||
in this way when they have their own highlighting via "matchgroup". The
|
||||
|synconcealed()| function can be used to retrieve information about conealed
|
||||
items.
|
||||
|
||||
cchar *:syn-cchar*
|
||||
*E844*
|
||||
|
|
|
@ -65,6 +65,8 @@ An instance `TSNode` of a treesitter node supports the following methods.
|
|||
|
||||
TSNode:parent() *TSNode:parent()*
|
||||
Get the node's immediate parent.
|
||||
Prefer |TSNode:child_containing_descendant()|
|
||||
for iterating over the node's ancestors.
|
||||
|
||||
TSNode:next_sibling() *TSNode:next_sibling()*
|
||||
Get the node's next sibling.
|
||||
|
@ -101,6 +103,9 @@ TSNode:named_child({index}) *TSNode:named_child()*
|
|||
Get the node's named child at the given {index}, where zero represents the
|
||||
first named child.
|
||||
|
||||
TSNode:child_containing_descendant({descendant}) *TSNode:child_containing_descendant()*
|
||||
Get the node's child that contains {descendant}.
|
||||
|
||||
TSNode:start() *TSNode:start()*
|
||||
Get the node's start position. Return three values: the row, column and
|
||||
total byte count (all zero-based).
|
||||
|
|
|
@ -948,7 +948,7 @@ Syntax and highlighting: *syntax-functions* *highlighting-functions*
|
|||
synIDattr() get a specific attribute of a syntax ID
|
||||
synIDtrans() get translated syntax ID
|
||||
synstack() get list of syntax IDs at a specific position
|
||||
synconcealed() get info about concealing
|
||||
synconcealed() get info about (syntax) concealing
|
||||
diff_hlID() get highlight ID for diff mode at a position
|
||||
matchadd() define a pattern to highlight (a "match")
|
||||
matchaddpos() define a list of positions to highlight
|
||||
|
|
|
@ -9752,6 +9752,10 @@ function vim.fn.synIDtrans(synID) end
|
|||
--- synconcealed(lnum, 5) [1, 'X', 2]
|
||||
--- synconcealed(lnum, 6) [0, '', 0]
|
||||
---
|
||||
--- Note: Doesn't consider |matchadd()| highlighting items,
|
||||
--- since syntax and matching highlighting are two different
|
||||
--- mechanisms |syntax-vs-match|.
|
||||
---
|
||||
--- @param lnum integer
|
||||
--- @param col integer
|
||||
--- @return {[1]: integer, [2]: string, [3]: integer}
|
||||
|
|
|
@ -20,6 +20,7 @@ error('Cannot require a meta file')
|
|||
---@field descendant_for_range fun(self: TSNode, start_row: integer, start_col: integer, end_row: integer, end_col: integer): TSNode?
|
||||
---@field named_descendant_for_range fun(self: TSNode, start_row: integer, start_col: integer, end_row: integer, end_col: integer): TSNode?
|
||||
---@field parent fun(self: TSNode): TSNode?
|
||||
---@field child_containing_descendant fun(self: TSNode, descendant: TSNode): TSNode?
|
||||
---@field next_sibling fun(self: TSNode): TSNode?
|
||||
---@field prev_sibling fun(self: TSNode): TSNode?
|
||||
---@field next_named_sibling fun(self: TSNode): TSNode?
|
||||
|
|
|
@ -462,12 +462,12 @@ local predicate_handlers = {
|
|||
ancestor_types[type] = true
|
||||
end
|
||||
|
||||
local cur = node:parent()
|
||||
local cur = node:tree():root()
|
||||
while cur do
|
||||
if ancestor_types[cur:type()] then
|
||||
return true
|
||||
end
|
||||
cur = cur:parent()
|
||||
cur = cur:child_containing_descendant(node)
|
||||
end
|
||||
end
|
||||
return false
|
||||
|
|
|
@ -47,8 +47,8 @@ typedef struct {
|
|||
#define VALID_VIRTCOL 0x04 // w_virtcol (file col) is valid
|
||||
#define VALID_CHEIGHT 0x08 // w_cline_height and w_cline_folded valid
|
||||
#define VALID_CROW 0x10 // w_cline_row is valid
|
||||
#define VALID_BOTLINE 0x20 // w_botine and w_empty_rows are valid
|
||||
#define VALID_BOTLINE_AP 0x40 // w_botine is approximated
|
||||
#define VALID_BOTLINE 0x20 // w_botline and w_empty_rows are valid
|
||||
#define VALID_BOTLINE_AP 0x40 // w_botline is approximated
|
||||
#define VALID_TOPLINE 0x80 // w_topline is valid (for cursor position)
|
||||
|
||||
// flags for b_flags
|
||||
|
|
|
@ -11621,6 +11621,10 @@ M.funcs = {
|
|||
synconcealed(lnum, 4) [1, 'X', 2]
|
||||
synconcealed(lnum, 5) [1, 'X', 2]
|
||||
synconcealed(lnum, 6) [0, '', 0]
|
||||
|
||||
Note: Doesn't consider |matchadd()| highlighting items,
|
||||
since syntax and matching highlighting are two different
|
||||
mechanisms |syntax-vs-match|.
|
||||
]=],
|
||||
name = 'synconcealed',
|
||||
params = { { 'lnum', 'integer' }, { 'col', 'integer' } },
|
||||
|
|
|
@ -725,6 +725,7 @@ static struct luaL_Reg node_meta[] = {
|
|||
{ "descendant_for_range", node_descendant_for_range },
|
||||
{ "named_descendant_for_range", node_named_descendant_for_range },
|
||||
{ "parent", node_parent },
|
||||
{ "child_containing_descendant", node_child_containing_descendant },
|
||||
{ "iter_children", node_iter_children },
|
||||
{ "next_sibling", node_next_sibling },
|
||||
{ "prev_sibling", node_prev_sibling },
|
||||
|
@ -1052,6 +1053,15 @@ static int node_parent(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int node_child_containing_descendant(lua_State *L)
|
||||
{
|
||||
TSNode node = node_check(L, 1);
|
||||
TSNode descendant = node_check(L, 2);
|
||||
TSNode child = ts_node_child_containing_descendant(node, descendant);
|
||||
push_node(L, child, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int node_next_sibling(lua_State *L)
|
||||
{
|
||||
TSNode node = node_check(L, 1);
|
||||
|
|
|
@ -2467,6 +2467,7 @@ void win_init_empty(win_T *wp)
|
|||
wp->w_topline = 1;
|
||||
wp->w_topfill = 0;
|
||||
wp->w_botline = 2;
|
||||
wp->w_valid = 0;
|
||||
wp->w_s = &wp->w_buffer->b_s;
|
||||
}
|
||||
|
||||
|
|
|
@ -143,4 +143,27 @@ describe('treesitter node API', function()
|
|||
eq(28, lua_eval('root:byte_length()'))
|
||||
eq(3, lua_eval('child:byte_length()'))
|
||||
end)
|
||||
|
||||
it('child_containing_descendant() works', function()
|
||||
insert([[
|
||||
int main() {
|
||||
int x = 3;
|
||||
}]])
|
||||
|
||||
exec_lua([[
|
||||
tree = vim.treesitter.get_parser(0, "c"):parse()[1]
|
||||
root = tree:root()
|
||||
main = root:child(0)
|
||||
body = main:child(2)
|
||||
statement = body:child(1)
|
||||
declarator = statement:child(1)
|
||||
value = declarator:child(1)
|
||||
]])
|
||||
|
||||
eq(lua_eval('main:type()'), lua_eval('root:child_containing_descendant(value):type()'))
|
||||
eq(lua_eval('body:type()'), lua_eval('main:child_containing_descendant(value):type()'))
|
||||
eq(lua_eval('statement:type()'), lua_eval('body:child_containing_descendant(value):type()'))
|
||||
eq(lua_eval('declarator:type()'), lua_eval('statement:child_containing_descendant(value):type()'))
|
||||
eq(vim.NIL, lua_eval('declarator:child_containing_descendant(value)'))
|
||||
end)
|
||||
end)
|
||||
|
|
|
@ -11,6 +11,22 @@ local is_os = t.is_os
|
|||
local api = n.api
|
||||
local fn = n.fn
|
||||
|
||||
local get_query_result_code = [[
|
||||
function get_query_result(query_text)
|
||||
cquery = vim.treesitter.query.parse("c", query_text)
|
||||
parser = vim.treesitter.get_parser(0, "c")
|
||||
tree = parser:parse()[1]
|
||||
res = {}
|
||||
for cid, node in cquery:iter_captures(tree:root(), 0) do
|
||||
-- can't transmit node over RPC. just check the name, range, and text
|
||||
local text = vim.treesitter.get_node_text(node, 0)
|
||||
local range = {node:range()}
|
||||
table.insert(res, { cquery.captures[cid], node:type(), range, text })
|
||||
end
|
||||
return res
|
||||
end
|
||||
]]
|
||||
|
||||
describe('treesitter query API', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
|
@ -295,21 +311,7 @@ void ui_refresh(void)
|
|||
return 0;
|
||||
}
|
||||
]])
|
||||
exec_lua([[
|
||||
function get_query_result(query_text)
|
||||
cquery = vim.treesitter.query.parse("c", query_text)
|
||||
parser = vim.treesitter.get_parser(0, "c")
|
||||
tree = parser:parse()[1]
|
||||
res = {}
|
||||
for cid, node in cquery:iter_captures(tree:root(), 0) do
|
||||
-- can't transmit node over RPC. just check the name, range, and text
|
||||
local text = vim.treesitter.get_node_text(node, 0)
|
||||
local range = {node:range()}
|
||||
table.insert(res, { cquery.captures[cid], node:type(), range, text })
|
||||
end
|
||||
return res
|
||||
end
|
||||
]])
|
||||
exec_lua(get_query_result_code)
|
||||
|
||||
local res0 = exec_lua(
|
||||
[[return get_query_result(...)]],
|
||||
|
@ -337,6 +339,27 @@ void ui_refresh(void)
|
|||
}, res1)
|
||||
end)
|
||||
|
||||
it('supports builtin predicate has-ancestor?', function()
|
||||
insert([[
|
||||
int x = 123;
|
||||
struct S { int x; };
|
||||
int main() { int x = 124; }]]
|
||||
)
|
||||
exec_lua(get_query_result_code)
|
||||
|
||||
local result = exec_lua(
|
||||
[[return get_query_result(...)]],
|
||||
[[((number_literal) @literal (#has-ancestor? @literal "function_definition"))]]
|
||||
)
|
||||
eq({ { 'literal', 'number_literal', { 2, 21, 2, 24 }, '124' } }, result)
|
||||
|
||||
result = exec_lua(
|
||||
[[return get_query_result(...)]],
|
||||
[[((number_literal) @literal (#has-ancestor? @literal "struct_specifier"))]]
|
||||
)
|
||||
eq({}, result)
|
||||
end)
|
||||
|
||||
it('allows loading query with escaped quotes and capture them `#{lua,vim}-match`?', function()
|
||||
insert('char* astring = "Hello World!";')
|
||||
|
||||
|
|
|
@ -4105,4 +4105,16 @@ func Test_SwapExists_set_other_buf_modified()
|
|||
bwipe!
|
||||
endfunc
|
||||
|
||||
func Test_BufEnter_botline()
|
||||
set hidden
|
||||
call writefile(range(10), 'Xxx1', 'D')
|
||||
call writefile(range(20), 'Xxx2', 'D')
|
||||
edit Xxx1
|
||||
edit Xxx2
|
||||
au BufEnter Xxx1 call assert_true(line('w$') > 1)
|
||||
edit Xxx1
|
||||
au! BufEnter Xxx1
|
||||
set hidden&vim
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
|
Loading…
Reference in New Issue