diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2024-01-28 21:13:58 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-28 21:13:58 -0600 |
commit | 15e77a56b711102fdc123e15b3f37d49bc0b1df1 (patch) | |
tree | bdd554e82b4da3ecceb82ca44fb6282871703923 /test/functional/api/extmark_spec.lua | |
parent | af6537bc66e2ea506b9640c34720ef85d4704be6 (diff) | |
download | rneovim-15e77a56b711102fdc123e15b3f37d49bc0b1df1.tar.gz rneovim-15e77a56b711102fdc123e15b3f37d49bc0b1df1.tar.bz2 rneovim-15e77a56b711102fdc123e15b3f37d49bc0b1df1.zip |
feat(extmarks): subpriorities (relative to declaration order) (#27131)
The "priority" field of extmarks can be used to set priorities of
extmarks which dictates which highlight group a range will actually have
when there are multiple extmarks applied. However, when multiple
extmarks have the same priority, the only way to enforce an actual
priority is through the order in which the extmarks are set.
It is not always possible or desirable to set extmarks in a specific
order, however, so we add a new "subpriority" field that explicitly
enforces the ordering of extmarks that have the same priority.
For now this will be used only to enforce priority of treesitter
highlights. A single node in a treesitter tree may match multiple
captures, in which case that node will have multiple extmarks set. The
order in which captures are returned from the treesitter API is not
_necessarily_ in the same order they are defined in a query file, so we
use the new subpriority field to force that ordering.
For now subpriorites are not documented and are not meant to be used by
external code, and it only applies to ephemeral extmarks. We indicate
the "private" nature of subpriorities by prefixing the field name with
an "_".
Diffstat (limited to 'test/functional/api/extmark_spec.lua')
-rw-r--r-- | test/functional/api/extmark_spec.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 0a286965f2..2acfbfc949 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1798,6 +1798,36 @@ describe('API/extmarks', function() eq(1, #extmarks) eq('https://example.com', extmarks[1][4].url) end) + + it('respects priority', function() + screen = Screen.new(15, 10) + screen:attach() + + set_extmark(ns, marks[1], 0, 0, { + hl_group = 'Comment', + end_col = 2, + priority = 20, + }) + + -- Extmark defined after first extmark but has lower priority, first extmark "wins" + set_extmark(ns, marks[2], 0, 0, { + hl_group = 'String', + end_col = 2, + priority = 10, + }) + + screen:expect { + grid = [[ + {1:12}34^5 | + {2:~ }|*8 + | + ]], + attr_ids = { + [1] = { foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Blue1, bold = true }, + }, + } + end) end) describe('Extmarks buffer api with many marks', function() |