mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 02:16:31 +00:00
refactor(sign): move legacy signs to extmarks
Problem: The legacy signlist data structures and associated functions are redundant since the introduction of extmark signs. Solution: Store signs defined through the legacy commands in a hashmap, placed signs in the extmark tree. Replace signlist associated functions. Usage of the legacy sign commands should yield no change in behavior with the exception of: - "orphaned signs" are now always removed when the line it is placed on is deleted. This used to depend on the value of 'signcolumn'. - It is no longer possible to place multiple signs with the same identifier in a single group on multiple lines. This will now move the sign instead. Moreover, both signs placed through the legacy sign commands and through |nvim_buf_set_extmark()|: - Will show up in both |sign-place| and |nvim_buf_get_extmarks()|. - Are displayed by increasing sign identifier, left to right. Extmark signs used to be ordered decreasingly as opposed to legacy signs.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/pos.h"
|
||||
#include "nvim/sign.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/vim.h"
|
||||
|
||||
@@ -81,7 +82,7 @@ Dictionary nvim_get_namespaces(void)
|
||||
return retval;
|
||||
}
|
||||
|
||||
const char *describe_ns(NS ns_id)
|
||||
const char *describe_ns(NS ns_id, const char *unknown)
|
||||
{
|
||||
String name;
|
||||
handle_T id;
|
||||
@@ -90,7 +91,7 @@ const char *describe_ns(NS ns_id)
|
||||
return name.data;
|
||||
}
|
||||
})
|
||||
return "(UNKNOWN PLUGIN)";
|
||||
return unknown;
|
||||
}
|
||||
|
||||
// Is the Namespace in use?
|
||||
@@ -314,8 +315,8 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
|
||||
return extmark_to_array(&extmark, false, details, hl_name);
|
||||
}
|
||||
|
||||
/// Gets |extmarks| in "traversal order" from a |charwise| region defined by
|
||||
/// buffer positions (inclusive, 0-indexed |api-indexing|).
|
||||
/// Gets |extmarks| (including |signs|) in "traversal order" from a |charwise|
|
||||
/// region defined by buffer positions (inclusive, 0-indexed |api-indexing|).
|
||||
///
|
||||
/// Region can be given as (row,col) tuples, or valid extmark ids (whose
|
||||
/// positions define the bounds). 0 and -1 are understood as (0,0) and (-1,-1)
|
||||
@@ -750,7 +751,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
||||
}
|
||||
|
||||
if (HAS_KEY(opts, set_extmark, sign_text)) {
|
||||
VALIDATE_S(init_sign_text(&decor.sign_text, opts->sign_text.data),
|
||||
VALIDATE_S(init_sign_text(NULL, &decor.sign_text, opts->sign_text.data),
|
||||
"sign_text", "", {
|
||||
goto error;
|
||||
});
|
||||
@@ -1150,41 +1151,6 @@ static bool extmark_get_index_from_obj(buf_T *buf, Integer ns_id, Object obj, in
|
||||
});
|
||||
}
|
||||
}
|
||||
// adapted from sign.c:sign_define_init_text.
|
||||
// TODO(lewis6991): Consider merging
|
||||
static int init_sign_text(char **sign_text, char *text)
|
||||
{
|
||||
char *s;
|
||||
|
||||
char *endp = text + (int)strlen(text);
|
||||
|
||||
// Count cells and check for non-printable chars
|
||||
int cells = 0;
|
||||
for (s = text; s < endp; s += utfc_ptr2len(s)) {
|
||||
if (!vim_isprintc(utf_ptr2char(s))) {
|
||||
break;
|
||||
}
|
||||
cells += utf_ptr2cells(s);
|
||||
}
|
||||
// Currently must be empty, one or two display cells
|
||||
if (s != endp || cells > 2) {
|
||||
return FAIL;
|
||||
}
|
||||
if (cells < 1) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
// Allocate one byte more if we need to pad up
|
||||
// with a space.
|
||||
size_t len = (size_t)(endp - text + ((cells == 1) ? 1 : 0));
|
||||
*sign_text = xstrnsave(text, len);
|
||||
|
||||
if (cells == 1) {
|
||||
STRCPY(*sign_text + len - 1, " ");
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
VirtText parse_virt_text(Array chunks, Error *err, int *width)
|
||||
{
|
||||
|
@@ -2196,13 +2196,12 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *
|
||||
}
|
||||
}
|
||||
if (statuscol_lnum) {
|
||||
HlPriId line = { 0 };
|
||||
HlPriId cul = { 0 };
|
||||
HlPriId num = { 0 };
|
||||
int line_id = 0;
|
||||
int cul_id = 0;
|
||||
int num_id = 0;
|
||||
linenr_T lnum = statuscol_lnum;
|
||||
int num_signs = buf_get_signattrs(wp->w_buffer, lnum, sattrs, &num, &line, &cul);
|
||||
decor_redraw_signs(wp->w_buffer, lnum - 1, &num_signs, sattrs, &num, &line, &cul);
|
||||
wp->w_scwidth = win_signcol_count(wp);
|
||||
decor_redraw_signs(wp, wp->w_buffer, lnum - 1, sattrs, &line_id, &cul_id, &num_id);
|
||||
|
||||
statuscol.sattrs = sattrs;
|
||||
statuscol.foldinfo = fold_info(wp, lnum);
|
||||
@@ -2215,9 +2214,9 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *
|
||||
statuscol.use_cul = lnum == wp->w_cursorline && (wp->w_p_culopt_flags & CULOPT_NBR);
|
||||
}
|
||||
|
||||
statuscol.sign_cul_id = statuscol.use_cul ? cul.hl_id : 0;
|
||||
if (num.hl_id) {
|
||||
stc_hl_id = num.hl_id;
|
||||
statuscol.sign_cul_id = statuscol.use_cul ? cul_id : 0;
|
||||
if (num_id) {
|
||||
stc_hl_id = num_id;
|
||||
} else if (statuscol.use_cul) {
|
||||
stc_hl_id = HLF_CLN + 1;
|
||||
} else if (wp->w_p_rnu) {
|
||||
|
Reference in New Issue
Block a user