aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Reineke <lukas.reineke@protonmail.com>2020-12-25 01:33:52 +0900
committerGitHub <noreply@github.com>2020-12-24 17:33:52 +0100
commit88ae03bcdb8992fd91a3efdb61dbd7e2aa395eff (patch)
tree14dc4b5e156bba0380f25af525afb7d2ef6125a7
parent6c28bddfad73c527da5e5629919d617dffdea229 (diff)
downloadrneovim-88ae03bcdb8992fd91a3efdb61dbd7e2aa395eff.tar.gz
rneovim-88ae03bcdb8992fd91a3efdb61dbd7e2aa395eff.tar.bz2
rneovim-88ae03bcdb8992fd91a3efdb61dbd7e2aa395eff.zip
feat(sign):Allow signs to be 0 width (#13290)
Adds support for signs to be 0 cells wide. If all signs of the same group have no width, the signcolumn will not be rendered for that group.
-rw-r--r--src/nvim/buffer.c4
-rw-r--r--src/nvim/sign.c70
-rw-r--r--src/nvim/sign_defs.h16
-rw-r--r--src/nvim/testdir/test_signs.vim8
-rw-r--r--test/functional/ui/sign_spec.lua66
5 files changed, 133 insertions, 31 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index f40ebaad90..a8cb90ff0e 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -5479,7 +5479,9 @@ int buf_signcols(buf_T *buf)
curline = sign->lnum;
linesum = 0;
}
- linesum++;
+ if (sign->has_text_or_icon) {
+ linesum++;
+ }
}
if (linesum > buf->b_signcols_max) {
buf->b_signcols_max = linesum;
diff --git a/src/nvim/sign.c b/src/nvim/sign.c
index ffe51287c5..fc9f53c192 100644
--- a/src/nvim/sign.c
+++ b/src/nvim/sign.c
@@ -173,13 +173,15 @@ static void insert_sign(
const char_u *group, // sign group; NULL for global group
int prio, // sign priority
linenr_T lnum, // line number which gets the mark
- int typenr // typenr of sign we are adding
+ int typenr, // typenr of sign we are adding
+ bool has_text_or_icon // sign has text or icon
)
{
signlist_T *newsign = xmalloc(sizeof(signlist_T));
newsign->id = id;
newsign->lnum = lnum;
newsign->typenr = typenr;
+ newsign->has_text_or_icon = has_text_or_icon;
if (group != NULL) {
newsign->group = sign_group_ref(group);
} else {
@@ -210,13 +212,14 @@ static void insert_sign(
/// Insert a new sign sorted by line number and sign priority.
static void insert_sign_by_lnum_prio(
- buf_T *buf, // buffer to store sign in
- signlist_T *prev, // previous sign entry
- int id, // sign ID
- const char_u *group, // sign group; NULL for global group
- int prio, // sign priority
- linenr_T lnum, // line number which gets the mark
- int typenr // typenr of sign we are adding
+ buf_T *buf, // buffer to store sign in
+ signlist_T *prev, // previous sign entry
+ int id, // sign ID
+ const char_u *group, // sign group; NULL for global group
+ int prio, // sign priority
+ linenr_T lnum, // line number which gets the mark
+ int typenr, // typenr of sign we are adding
+ bool has_text_or_icon // sign has text or icon
)
{
signlist_T *sign;
@@ -234,7 +237,7 @@ static void insert_sign_by_lnum_prio(
sign = prev->next;
}
- insert_sign(buf, prev, sign, id, group, prio, lnum, typenr);
+ insert_sign(buf, prev, sign, id, group, prio, lnum, typenr, has_text_or_icon);
}
/// Get the name of a sign by its typenr.
@@ -342,12 +345,13 @@ static void sign_sort_by_prio_on_line(buf_T *buf, signlist_T *sign)
/// Add the sign into the signlist. Find the right spot to do it though.
void buf_addsign(
- buf_T *buf, // buffer to store sign in
- int id, // sign ID
+ buf_T *buf, // buffer to store sign in
+ int id, // sign ID
const char_u *groupname, // sign group
- int prio, // sign priority
- linenr_T lnum, // line number which gets the mark
- int typenr // typenr of sign we are adding
+ int prio, // sign priority
+ linenr_T lnum, // line number which gets the mark
+ int typenr, // typenr of sign we are adding
+ bool has_text_or_icon // sign has text or icon
)
{
signlist_T *sign; // a sign in the signlist
@@ -363,13 +367,29 @@ void buf_addsign(
sign_sort_by_prio_on_line(buf, sign);
return;
} else if (lnum < sign->lnum) {
- insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, lnum, typenr);
+ insert_sign_by_lnum_prio(
+ buf,
+ prev,
+ id,
+ groupname,
+ prio,
+ lnum,
+ typenr,
+ has_text_or_icon);
return;
}
prev = sign;
}
- insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, lnum, typenr);
+ insert_sign_by_lnum_prio(
+ buf,
+ prev,
+ id,
+ groupname,
+ prio,
+ lnum,
+ typenr,
+ has_text_or_icon);
}
// For an existing, placed sign "markId" change the type to "typenr".
@@ -786,11 +806,15 @@ static int sign_define_init_text(sign_T *sp, char_u *text)
}
cells += utf_ptr2cells(s);
}
- // Currently must be one or two display cells
- if (s != endp || cells < 1 || cells > 2) {
+ // Currently must be empty, one or two display cells
+ if (s != endp || cells > 2) {
EMSG2(_("E239: Invalid sign text: %s"), text);
return FAIL;
}
+ if (cells < 1) {
+ sp->sn_text = NULL;
+ return OK;
+ }
xfree(sp->sn_text);
// Allocate one byte more if we need to pad up
@@ -939,7 +963,15 @@ int sign_place(
if (lnum > 0) {
// ":sign place {id} line={lnum} name={name} file={fname}":
// place a sign
- buf_addsign(buf, *sign_id, sign_group, prio, lnum, sp->sn_typenr);
+ bool has_text_or_icon = sp->sn_text != NULL || sp->sn_icon != NULL;
+ buf_addsign(
+ buf,
+ *sign_id,
+ sign_group,
+ prio,
+ lnum,
+ sp->sn_typenr,
+ has_text_or_icon);
} else {
// ":sign place {id} file={fname}": change sign type
lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr);
diff --git a/src/nvim/sign_defs.h b/src/nvim/sign_defs.h
index 687c15bbd6..c898dba890 100644
--- a/src/nvim/sign_defs.h
+++ b/src/nvim/sign_defs.h
@@ -1,6 +1,7 @@
#ifndef NVIM_SIGN_DEFS_H
#define NVIM_SIGN_DEFS_H
+#include <stdbool.h>
#include "nvim/pos.h"
#include "nvim/types.h"
@@ -22,13 +23,14 @@ typedef struct signlist signlist_T;
struct signlist
{
- int id; // unique identifier for each placed sign
- linenr_T lnum; // line number which has this sign
- int typenr; // typenr of sign
- signgroup_T *group; // sign group
- int priority; // priority for highlighting
- signlist_T *next; // next signlist entry
- signlist_T *prev; // previous entry -- for easy reordering
+ int id; // unique identifier for each placed sign
+ linenr_T lnum; // line number which has this sign
+ int typenr; // typenr of sign
+ bool has_text_or_icon; // has text or icon
+ signgroup_T *group; // sign group
+ int priority; // priority for highlighting
+ signlist_T *next; // next signlist entry
+ signlist_T *prev; // previous entry -- for easy reordering
};
// Default sign priority for highlighting
diff --git a/src/nvim/testdir/test_signs.vim b/src/nvim/testdir/test_signs.vim
index 1e6c311374..4bbd722fdb 100644
--- a/src/nvim/testdir/test_signs.vim
+++ b/src/nvim/testdir/test_signs.vim
@@ -122,9 +122,9 @@ func Test_sign()
call assert_fails("sign define Sign4 text=a\e linehl=Comment", 'E239:')
call assert_fails("sign define Sign4 text=\ea linehl=Comment", 'E239:')
- " Only 1 or 2 character text is allowed
+ " Only 0, 1 or 2 character text is allowed
call assert_fails("sign define Sign4 text=abc linehl=Comment", 'E239:')
- call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:')
+ " call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:')
call assert_fails("sign define Sign4 text=\\ ab linehl=Comment", 'E239:')
" define sign with whitespace
@@ -306,7 +306,7 @@ func Test_sign_invalid_commands()
call assert_fails('sign jump 1 name=', 'E474:')
call assert_fails('sign jump 1 name=Sign1', 'E474:')
call assert_fails('sign jump 1 line=100', '474:')
- call assert_fails('sign define Sign2 text=', 'E239:')
+ " call assert_fails('sign define Sign2 text=', 'E239:')
" Non-numeric identifier for :sign place
call assert_fails("sign place abc line=3 name=Sign1 buffer=" . bufnr(''),
\ 'E474:')
@@ -415,7 +415,7 @@ func Test_sign_funcs()
" Tests for invalid arguments to sign_define()
call assert_fails('call sign_define("sign4", {"text" : "===>"})', 'E239:')
- call assert_fails('call sign_define("sign5", {"text" : ""})', 'E239:')
+ " call assert_fails('call sign_define("sign5", {"text" : ""})', 'E239:')
call assert_fails('call sign_define([])', 'E730:')
call assert_fails('call sign_define("sign6", [])', 'E715:')
diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua
index 0ed62b21b2..d1b8de5e4e 100644
--- a/test/functional/ui/sign_spec.lua
+++ b/test/functional/ui/sign_spec.lua
@@ -76,6 +76,28 @@ describe('Signs', function()
]])
end)
+ it('allows signs with no text', function()
+ feed('ia<cr>b<cr><esc>')
+ command('sign define piet1 text= texthl=Search')
+ command('sign place 1 line=1 name=piet1 buffer=1')
+ screen:expect([[
+ a |
+ b |
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
+
it('can be called right after :split', function()
feed('ia<cr>b<cr>c<cr><esc>gg')
-- This used to cause a crash due to :sign using a special redraw
@@ -244,6 +266,50 @@ describe('Signs', function()
]]}
end)
+ it('ignores signs with no icon and text when calculting the signcolumn width', function()
+ feed('ia<cr>b<cr>c<cr><esc>')
+ command('set number')
+ command('set signcolumn=auto:2')
+ command('sign define pietSearch text=>> texthl=Search')
+ command('sign define pietError text= texthl=Error')
+ command('sign place 2 line=1 name=pietError buffer=1')
+ -- no signcolumn with only empty sign
+ screen:expect([[
+ {6: 1 }a |
+ {6: 2 }b |
+ {6: 3 }c |
+ {6: 4 }^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ -- single column with 1 sign with text and one sign without
+ command('sign place 1 line=1 name=pietSearch buffer=1')
+ screen:expect([[
+ {1:>>}{6: 1 }a |
+ {2: }{6: 2 }b |
+ {2: }{6: 3 }c |
+ {2: }{6: ^4 } |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
+
it('can have 32bit sign IDs', function()
command('sign define piet text=>> texthl=Search')
command('sign place 100000 line=1 name=piet buffer=1')