1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local exec_lua = n.exec_lua
local eq = t.eq
local eval = n.eval
local clear = n.clear
describe('vim.inspect_pos', function()
before_each(function()
clear()
end)
it('it returns items', function()
local buf, ns1, ns2 = exec_lua(function()
local buf = vim.api.nvim_create_buf(true, false)
_G.buf1 = vim.api.nvim_create_buf(true, false)
local ns1 = vim.api.nvim_create_namespace('ns1')
local ns2 = vim.api.nvim_create_namespace('')
vim.api.nvim_set_current_buf(buf)
vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'local a = 123' })
vim.api.nvim_buf_set_lines(_G.buf1, 0, -1, false, { '--commentline' })
vim.bo[buf].filetype = 'lua'
vim.bo[_G.buf1].filetype = 'lua'
vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = 'Normal' })
vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = 'Normal', end_col = 10 })
vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = 'Normal', end_col = 11 })
vim.cmd('syntax on')
return buf, ns1, ns2
end)
eq('', eval('v:errmsg'))
-- Only visible highlights with `filter.extmarks == true`
eq({
buffer = buf,
col = 10,
row = 0,
extmarks = {
{
col = 10,
end_col = 11,
end_row = 0,
id = 1,
ns = '',
ns_id = ns2,
opts = {
end_row = 0,
end_col = 11,
hl_eol = false,
hl_group = 'Normal',
hl_group_link = 'Normal',
ns_id = ns2,
priority = 4096,
right_gravity = true,
end_right_gravity = false,
},
row = 0,
},
},
treesitter = {},
semantic_tokens = {},
syntax = { { hl_group = 'luaNumber', hl_group_link = 'Constant' } },
}, exec_lua('return vim.inspect_pos(0, 0, 10)'))
-- All extmarks with `filters.extmarks == 'all'`
eq({
buffer = buf,
col = 10,
row = 0,
extmarks = {
{
col = 10,
end_col = 10,
end_row = 0,
id = 1,
ns = 'ns1',
ns_id = ns1,
opts = {
hl_eol = false,
hl_group = 'Normal',
hl_group_link = 'Normal',
ns_id = ns1,
priority = 4096,
right_gravity = true,
},
row = 0,
},
{
col = 10,
end_col = 11,
end_row = 0,
id = 1,
ns = '',
ns_id = ns2,
opts = {
end_row = 0,
end_col = 11,
hl_eol = false,
hl_group = 'Normal',
hl_group_link = 'Normal',
ns_id = ns2,
priority = 4096,
right_gravity = true,
end_right_gravity = false,
},
row = 0,
},
{
col = 10,
end_col = 10,
end_row = 0,
id = 2,
ns = 'ns1',
ns_id = ns1,
opts = {
end_row = 0,
end_col = 10,
hl_eol = false,
hl_group = 'Normal',
hl_group_link = 'Normal',
ns_id = ns1,
priority = 4096,
right_gravity = true,
end_right_gravity = false,
},
row = 0,
},
},
treesitter = {},
semantic_tokens = {},
syntax = { { hl_group = 'luaNumber', hl_group_link = 'Constant' } },
}, exec_lua('return vim.inspect_pos(0, 0, 10, { extmarks = "all" })'))
-- Syntax from other buffer.
eq({
{ hl_group = 'luaComment', hl_group_link = 'Comment' },
}, exec_lua('return vim.inspect_pos(_G.buf1, 0, 10).syntax'))
end)
end)
describe('vim.show_pos', function()
before_each(function()
clear()
end)
it('it does not error', function()
exec_lua(function()
local buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_set_current_buf(buf)
vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'local a = 123' })
vim.bo[buf].filetype = 'lua'
vim.cmd('syntax on')
return { buf, vim.show_pos(0, 0, 10) }
end)
eq('', eval('v:errmsg'))
end)
end)
|