diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-01-17 22:27:17 +0100 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-02-10 13:10:15 +0100 |
commit | 95fd28f4a1ef4e298695e0204bdb5b347aa0f57c (patch) | |
tree | 61728978f5d8570a2a96d10304520f983edbde61 /src | |
parent | 6c5bbf07d988ef55e5e8ba8d70b62c1f0885261b (diff) | |
download | rneovim-95fd28f4a1ef4e298695e0204bdb5b347aa0f57c.tar.gz rneovim-95fd28f4a1ef4e298695e0204bdb5b347aa0f57c.tar.bz2 rneovim-95fd28f4a1ef4e298695e0204bdb5b347aa0f57c.zip |
treesitter: use internal "decorations" buffer
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 11 | ||||
-rw-r--r-- | src/nvim/extmark.c | 7 | ||||
-rw-r--r-- | src/nvim/globals.h | 4 | ||||
-rw-r--r-- | src/nvim/screen.c | 82 |
4 files changed, 47 insertions, 57 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 30fc48fea5..5c60e9f99e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2598,7 +2598,8 @@ Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err) /// interface should probably be derived from a reformed /// bufhl/virttext interface with full support for multi-line /// ranges etc -void nvim__put_attr(Integer id, Integer c0, Integer c1) +void nvim__put_attr(Integer id, Integer start_row, Integer start_col, + Integer end_row, Integer end_col) FUNC_API_LUA_ONLY { if (!lua_attr_active) { @@ -2608,10 +2609,8 @@ void nvim__put_attr(Integer id, Integer c0, Integer c1) return; } int attr = syn_id2attr((int)id); - c0 = MAX(c0, 0); - c1 = MIN(c1, (Integer)lua_attr_bufsize); - for (Integer c = c0; c < c1; c++) { - lua_attr_buf[c] = (sattr_T)hl_combine_attr(lua_attr_buf[c], (int)attr); + if (attr == 0) { + return; } - return; + decoration_state_add_tmp(attr, start_row, start_col, end_row, end_col); } diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index 60ff5c3af9..69dbda5bb9 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -756,17 +756,18 @@ VirtText *extmark_find_virttext(buf_T *buf, int row, uint64_t ns_id) return NULL; } - +// TODO: use decoration_state prefix bool extmark_decorations_reset(buf_T *buf, DecorationState *state) { state->row = -1; - return buf->b_extmark_index; + kv_size(state->active) = 0; + // TODO: for tmp decorations! + return buf->b_extmark_index || true; } bool extmark_decorations_start(buf_T *buf, int top_row, DecorationState *state) { - kv_size(state->active) = 0; state->top_row = top_row; marktree_itr_get(buf->b_marktree, top_row, 0, state->itr); if (!state->itr->node) { diff --git a/src/nvim/globals.h b/src/nvim/globals.h index a53879188c..323c6cf9c3 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -127,10 +127,6 @@ typedef off_t off_T; EXTERN int mod_mask INIT(= 0x0); /* current key modifiers */ -// TODO(bfredl): for the final interface this should find a more suitable -// location. -EXTERN sattr_T *lua_attr_buf INIT(= NULL); -EXTERN size_t lua_attr_bufsize INIT(= 0); EXTERN bool lua_attr_active INIT(= false); /* diff --git a/src/nvim/screen.c b/src/nvim/screen.c index b9450e63eb..5294868855 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -637,6 +637,15 @@ bool win_cursorline_standout(const win_T *wp) static DecorationState decorations; bool decorations_active = false; +// VERY ad-hoc, should be in mark_extended.c? +void decoration_state_add_tmp(int attr_id, + int start_row, int start_col, + int end_row, int end_col) +{ + kv_push(decorations.active, + ((HlRange){ start_row, start_col, end_row, end_col, attr_id, NULL })); +} + /* * Update a single window. * @@ -2311,6 +2320,8 @@ win_line ( char *luatext = NULL; + buf_T *buf = wp->w_buffer; + if (!number_only) { // To speed up the loop below, set extra_check when there is linebreak, // trailing white space and/or syntax processing to be done. @@ -2332,6 +2343,33 @@ win_line ( } } + if (buf->b_luahl && buf->b_luahl_line != LUA_NOREF) { + Error err = ERROR_INIT; + // TODO(bfredl): build a macro for the "static array" pattern + // in buf_updates_send_changes? + FIXED_TEMP_ARRAY(args, 3); + args.items[0] = WINDOW_OBJ(wp->handle); + args.items[1] = BUFFER_OBJ(buf->handle); + args.items[2] = INTEGER_OBJ(lnum-1); + lua_attr_active = true; + extra_check = true; + Object o = executor_exec_lua_cb(buf->b_luahl_line, "line", + args, true, &err); + lua_attr_active = false; + if (o.type == kObjectTypeString) { + // TODO(bfredl): this is a bit of a hack. A final API should use an + // "unified" interface where luahl can add both bufhl and virttext + luatext = o.data.string.data; + do_virttext = true; + } else if (ERROR_SET(&err)) { + ELOG("error in luahl line: %s", err.msg); + luatext = err.msg; + do_virttext = true; + } + decorations_active = true; // TODO: huff! + } + + if (decorations_active) { has_decorations = extmark_decorations_line(wp->w_buffer, lnum-1, &decorations); @@ -2532,41 +2570,6 @@ win_line ( line = ml_get_buf(wp->w_buffer, lnum, FALSE); ptr = line; - buf_T *buf = wp->w_buffer; - if (buf->b_luahl && buf->b_luahl_line != LUA_NOREF) { - size_t size = STRLEN(line); - if (lua_attr_bufsize < size) { - xfree(lua_attr_buf); - lua_attr_buf = xcalloc(size, sizeof(*lua_attr_buf)); - lua_attr_bufsize = size; - } else if (lua_attr_buf) { - memset(lua_attr_buf, 0, size * sizeof(*lua_attr_buf)); - } - Error err = ERROR_INIT; - // TODO(bfredl): build a macro for the "static array" pattern - // in buf_updates_send_changes? - FIXED_TEMP_ARRAY(args, 3); - args.items[0] = WINDOW_OBJ(wp->handle); - args.items[1] = BUFFER_OBJ(buf->handle); - args.items[2] = INTEGER_OBJ(lnum-1); - lua_attr_active = true; - extra_check = true; - Object o = executor_exec_lua_cb(buf->b_luahl_line, "line", - args, true, &err); - lua_attr_active = false; - if (o.type == kObjectTypeString) { - // TODO(bfredl): this is a bit of a hack. A final API should use an - // "unified" interface where luahl can add both bufhl and virttext - luatext = o.data.string.data; - do_virttext = true; - } else if (ERROR_SET(&err)) { - ELOG("error in luahl line: %s", err.msg); - luatext = err.msg; - do_virttext = true; - api_clear_error(&err); - } - } - if (has_spell && !number_only) { // For checking first word with a capital skip white space. if (cap_col == 0) { @@ -3549,15 +3552,6 @@ win_line ( } } - // TODO(bfredl): luahl should reuse the "active decorations" buffer - if (buf->b_luahl && v > 0 && v < (long)lua_attr_bufsize+1) { - if (!attr_pri) { - char_attr = hl_combine_attr(char_attr, lua_attr_buf[v-1]); - } else { - char_attr = hl_combine_attr(lua_attr_buf[v-1], char_attr); - } - } - if (wp->w_buffer->terminal) { char_attr = hl_combine_attr(term_attrs[vcol], char_attr); } |