mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #17076 from notomo/expose-extmark-more-details
feat(api): expose extmark more details
This commit is contained in:
commit
be22cc1264
@ -115,7 +115,12 @@ static Array extmark_to_array(ExtmarkInfo extmark, bool id, bool add_dict)
|
||||
if (decor->hl_id) {
|
||||
String name = cstr_to_string((const char *)syn_id2name(decor->hl_id));
|
||||
PUT(dict, "hl_group", STRING_OBJ(name));
|
||||
PUT(dict, "hl_eol", BOOLEAN_OBJ(decor->hl_eol));
|
||||
}
|
||||
if (decor->hl_mode) {
|
||||
PUT(dict, "hl_mode", STRING_OBJ(cstr_to_string(hl_mode_str[decor->hl_mode])));
|
||||
}
|
||||
|
||||
if (kv_size(decor->virt_text)) {
|
||||
Array chunks = ARRAY_DICT_INIT;
|
||||
for (size_t i = 0; i < decor->virt_text.size; i++) {
|
||||
@ -129,6 +134,36 @@ static Array extmark_to_array(ExtmarkInfo extmark, bool id, bool add_dict)
|
||||
ADD(chunks, ARRAY_OBJ(chunk));
|
||||
}
|
||||
PUT(dict, "virt_text", ARRAY_OBJ(chunks));
|
||||
PUT(dict, "virt_text_hide", BOOLEAN_OBJ(decor->virt_text_hide));
|
||||
if (decor->virt_text_pos == kVTWinCol) {
|
||||
PUT(dict, "virt_text_win_col", INTEGER_OBJ(decor->col));
|
||||
}
|
||||
PUT(dict, "virt_text_pos",
|
||||
STRING_OBJ(cstr_to_string(virt_text_pos_str[decor->virt_text_pos])));
|
||||
}
|
||||
|
||||
if (kv_size(decor->virt_lines)) {
|
||||
Array all_chunks = ARRAY_DICT_INIT;
|
||||
bool virt_lines_leftcol = false;
|
||||
for (size_t i = 0; i < decor->virt_lines.size; i++) {
|
||||
Array chunks = ARRAY_DICT_INIT;
|
||||
VirtText *vt = &decor->virt_lines.items[i].line;
|
||||
virt_lines_leftcol = decor->virt_lines.items[i].left_col;
|
||||
for (size_t j = 0; j < vt->size; j++) {
|
||||
Array chunk = ARRAY_DICT_INIT;
|
||||
VirtTextChunk *vtc = &vt->items[j];
|
||||
ADD(chunk, STRING_OBJ(cstr_to_string(vtc->text)));
|
||||
if (vtc->hl_id > 0) {
|
||||
ADD(chunk,
|
||||
STRING_OBJ(cstr_to_string((const char *)syn_id2name(vtc->hl_id))));
|
||||
}
|
||||
ADD(chunks, ARRAY_OBJ(chunk));
|
||||
}
|
||||
ADD(all_chunks, ARRAY_OBJ(chunks));
|
||||
}
|
||||
PUT(dict, "virt_lines", ARRAY_OBJ(all_chunks));
|
||||
PUT(dict, "virt_lines_above", BOOLEAN_OBJ(decor->virt_lines_above));
|
||||
PUT(dict, "virt_lines_leftcol", BOOLEAN_OBJ(virt_lines_leftcol));
|
||||
}
|
||||
|
||||
if (decor->hl_id || kv_size(decor->virt_text)) {
|
||||
|
@ -17,6 +17,8 @@ typedef enum {
|
||||
kVTRightAlign,
|
||||
} VirtTextPos;
|
||||
|
||||
EXTERN const char *const virt_text_pos_str[] INIT(= { "eol", "overlay", "win_col", "right_align" });
|
||||
|
||||
typedef enum {
|
||||
kHlModeUnknown,
|
||||
kHlModeReplace,
|
||||
@ -24,6 +26,8 @@ typedef enum {
|
||||
kHlModeBlend,
|
||||
} HlMode;
|
||||
|
||||
EXTERN const char *const hl_mode_str[] INIT(= { "", "replace", "combine", "blend" });
|
||||
|
||||
typedef kvec_t(VirtTextChunk) VirtText;
|
||||
#define VIRTTEXT_EMPTY ((VirtText)KV_INITIAL_VALUE)
|
||||
|
||||
|
@ -1448,6 +1448,49 @@ describe('API/extmarks', function()
|
||||
})
|
||||
eq({ {1, 0, 0, { end_col = 0, end_row = 1 }} }, get_extmarks(ns, 0, -1, {details=true}))
|
||||
end)
|
||||
|
||||
it('can get details', function()
|
||||
set_extmark(ns, marks[1], 0, 0, {
|
||||
end_col = 0,
|
||||
end_row = 1,
|
||||
priority = 0,
|
||||
hl_eol = true,
|
||||
hl_mode = "blend",
|
||||
hl_group = "String",
|
||||
virt_text = { { "text", "Statement" } },
|
||||
virt_text_pos = "right_align",
|
||||
virt_text_hide = true,
|
||||
virt_lines = { { { "lines", "Statement" } }},
|
||||
virt_lines_above = true,
|
||||
virt_lines_leftcol = true,
|
||||
})
|
||||
set_extmark(ns, marks[2], 0, 0, {
|
||||
priority = 0,
|
||||
virt_text = { { "text", "Statement" } },
|
||||
virt_text_win_col = 1,
|
||||
})
|
||||
eq({0, 0, {
|
||||
end_col = 0,
|
||||
end_row = 1,
|
||||
priority = 0,
|
||||
hl_eol = true,
|
||||
hl_mode = "blend",
|
||||
hl_group = "String",
|
||||
virt_text = { { "text", "Statement" } },
|
||||
virt_text_pos = "right_align",
|
||||
virt_text_hide = true,
|
||||
virt_lines = { { { "lines", "Statement" } }},
|
||||
virt_lines_above = true,
|
||||
virt_lines_leftcol = true,
|
||||
} }, get_extmark_by_id(ns, marks[1], { details = true }))
|
||||
eq({0, 0, {
|
||||
priority = 0,
|
||||
virt_text = { { "text", "Statement" } },
|
||||
virt_text_hide = false,
|
||||
virt_text_pos = "win_col",
|
||||
virt_text_win_col = 1,
|
||||
} }, get_extmark_by_id(ns, marks[2], { details = true }))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('Extmarks buffer api with many marks', function()
|
||||
|
@ -755,12 +755,24 @@ describe('Buffer highlighting', function()
|
||||
-- TODO: only a virtual text from the same ns curretly overrides
|
||||
-- an existing virtual text. We might add a prioritation system.
|
||||
set_virtual_text(id1, 0, s1, {})
|
||||
eq({{1, 0, 0, { priority = 0, virt_text = s1}}}, get_extmarks(id1, {0,0}, {0, -1}, {details=true}))
|
||||
eq({{1, 0, 0, {
|
||||
priority = 0,
|
||||
virt_text = s1,
|
||||
-- other details
|
||||
virt_text_pos = 'eol',
|
||||
virt_text_hide = false,
|
||||
}}}, get_extmarks(id1, {0,0}, {0, -1}, {details=true}))
|
||||
|
||||
-- TODO: is this really valid? shouldn't the max be line_count()-1?
|
||||
local lastline = line_count()
|
||||
set_virtual_text(id1, line_count(), s2, {})
|
||||
eq({{3, lastline, 0, { priority = 0, virt_text = s2}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {details=true}))
|
||||
eq({{3, lastline, 0, {
|
||||
priority = 0,
|
||||
virt_text = s2,
|
||||
-- other details
|
||||
virt_text_pos = 'eol',
|
||||
virt_text_hide = false,
|
||||
}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {details=true}))
|
||||
|
||||
eq({}, get_extmarks(id1, {lastline+9000,0}, {lastline+9000, -1}, {}))
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user