aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2020-02-09 20:21:23 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2020-02-10 13:10:15 +0100
commit7d7adf7acc0d4f5219e1fc433d26c6c6c30b46fc (patch)
tree3d6ccec65f486382fc8ef6caf60781a131ea0271 /src
parent95fd28f4a1ef4e298695e0204bdb5b347aa0f57c (diff)
downloadrneovim-7d7adf7acc0d4f5219e1fc433d26c6c6c30b46fc.tar.gz
rneovim-7d7adf7acc0d4f5219e1fc433d26c6c6c30b46fc.tar.bz2
rneovim-7d7adf7acc0d4f5219e1fc433d26c6c6c30b46fc.zip
treesitter: cleanup some luahl stuff
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/vim.c3
-rw-r--r--src/nvim/buffer_updates.c5
-rw-r--r--src/nvim/extmark.c19
-rw-r--r--src/nvim/extmark.h2
-rw-r--r--src/nvim/screen.c71
5 files changed, 46 insertions, 54 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 5c60e9f99e..cf18f6b19a 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -2612,5 +2612,6 @@ void nvim__put_attr(Integer id, Integer start_row, Integer start_col,
if (attr == 0) {
return;
}
- decoration_state_add_tmp(attr, start_row, start_col, end_row, end_col);
+ decorations_add_luahl_attr(attr, (int)start_row, (colnr_T)start_col,
+ (int)end_row, (colnr_T)end_col);
}
diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c
index 80780a3aa3..e6393bf02c 100644
--- a/src/nvim/buffer_updates.c
+++ b/src/nvim/buffer_updates.c
@@ -296,10 +296,7 @@ void buf_updates_send_splice(buf_T *buf,
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
bool keep = true;
if (cb.on_bytes != LUA_NOREF) {
- Array args = ARRAY_DICT_INIT;
- Object items[8];
- args.size = 8;
- args.items = items;
+ FIXED_TEMP_ARRAY(args, 8);
// the first argument is always the buffer handle
args.items[0] = BUFFER_OBJ(buf->handle);
diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c
index 69dbda5bb9..d00943c1be 100644
--- a/src/nvim/extmark.c
+++ b/src/nvim/extmark.c
@@ -756,17 +756,16 @@ 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)
+bool decorations_redraw_reset(buf_T *buf, DecorationRedrawState *state)
{
state->row = -1;
kv_size(state->active) = 0;
- // TODO: for tmp decorations!
- return buf->b_extmark_index || true;
+ return buf->b_extmark_index || buf->b_luahl;
}
-bool extmark_decorations_start(buf_T *buf, int top_row, DecorationState *state)
+bool decorations_redraw_start(buf_T *buf, int top_row,
+ DecorationRedrawState *state)
{
state->top_row = top_row;
marktree_itr_get(buf->b_marktree, top_row, 0, state->itr);
@@ -818,17 +817,17 @@ next_mark:
return true; // TODO(bfredl): check if available in the region
}
-bool extmark_decorations_line(buf_T *buf, int row, DecorationState *state)
+bool decorations_redraw_line(buf_T *buf, int row, DecorationRedrawState *state)
{
if (state->row == -1) {
- extmark_decorations_start(buf, row, state);
+ decorations_redraw_start(buf, row, state);
}
state->row = row;
state->col_until = -1;
return true; // TODO(bfredl): be more precise
}
-int extmark_decorations_col(buf_T *buf, int col, DecorationState *state)
+int decorations_redraw_col(buf_T *buf, int col, DecorationRedrawState *state)
{
if (col <= state->col_until) {
return state->current;
@@ -907,9 +906,9 @@ next_mark:
return attr;
}
-VirtText *extmark_decorations_virt_text(buf_T *buf, DecorationState *state)
+VirtText *decorations_redraw_virt_text(buf_T *buf, DecorationRedrawState *state)
{
- extmark_decorations_col(buf, MAXCOL, state);
+ decorations_redraw_col(buf, MAXCOL, state);
for (size_t i = 0; i < kv_size(state->active); i++) {
HlRange item = kv_A(state->active, i);
if (item.start_row == state->row && item.virt_text) {
diff --git a/src/nvim/extmark.h b/src/nvim/extmark.h
index 829cbe0236..b5eb0db3b6 100644
--- a/src/nvim/extmark.h
+++ b/src/nvim/extmark.h
@@ -83,7 +83,7 @@ typedef struct {
int col_until;
int current;
VirtText *virt_text;
-} DecorationState;
+} DecorationRedrawState;
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 5294868855..5df279c0a7 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -634,13 +634,12 @@ bool win_cursorline_standout(const win_T *wp)
|| (wp->w_p_cole > 0 && (VIsual_active || !conceal_cursor_line(wp)));
}
-static DecorationState decorations;
+static DecorationRedrawState 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)
+void decorations_add_luahl_attr(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 }));
@@ -1237,6 +1236,8 @@ static void win_update(win_T *wp)
srow = 0;
lnum = wp->w_topline; // first line shown in window
+ decorations_active = decorations_redraw_reset(buf, &decorations);
+
if (buf->b_luahl && buf->b_luahl_window != LUA_NOREF) {
Error err = ERROR_INIT;
FIXED_TEMP_ARRAY(args, 4);
@@ -1257,7 +1258,6 @@ static void win_update(win_T *wp)
}
}
- decorations_active = extmark_decorations_reset(buf, &decorations);
for (;; ) {
/* stop updating when reached the end of the window (check for _past_
@@ -2343,36 +2343,32 @@ 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;
+ if (decorations_active) {
+ if (buf->b_luahl && buf->b_luahl_line != LUA_NOREF) {
+ Error err = ERROR_INIT;
+ 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);
+ has_decorations = decorations_redraw_line(wp->w_buffer, lnum-1,
+ &decorations);
if (has_decorations) {
extra_check = true;
}
@@ -3541,8 +3537,8 @@ win_line (
}
if (has_decorations && v > 0) {
- int extmark_attr = extmark_decorations_col(wp->w_buffer, (colnr_T)v-1,
- &decorations);
+ int extmark_attr = decorations_redraw_col(wp->w_buffer, (colnr_T)v-1,
+ &decorations);
if (extmark_attr != 0) {
if (!attr_pri) {
char_attr = hl_combine_attr(char_attr, extmark_attr);
@@ -4036,8 +4032,7 @@ win_line (
kv_push(virt_text, ((VirtTextChunk){ .text = luatext, .hl_id = 0 }));
do_virttext = true;
} else if (has_decorations) {
- VirtText *vp = extmark_decorations_virt_text(wp->w_buffer,
- &decorations);
+ VirtText *vp = decorations_redraw_virt_text(wp->w_buffer, &decorations);
if (vp) {
virt_text = *vp;
do_virttext = true;