aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2021-07-17 14:41:17 +0200
committerStephan Seitz <stephan.seitz@fau.de>2021-07-22 21:38:57 +0200
commit242608e6693f06c8e52ebf5813e697d28e96db52 (patch)
tree1bf6829b7e1e1d4f71477a2c07e74322b1064b7c
parenta8c3d50fad94971ebfe9eeedf933bdd829e66787 (diff)
downloadrneovim-242608e6693f06c8e52ebf5813e697d28e96db52.tar.gz
rneovim-242608e6693f06c8e52ebf5813e697d28e96db52.tar.bz2
rneovim-242608e6693f06c8e52ebf5813e697d28e96db52.zip
feat(treesitter): allow to set highlight priority for queries
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua4
-rw-r--r--test/functional/treesitter/highlight_spec.lua43
2 files changed, 45 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua
index 84b6a5f135..cf3cdf4505 100644
--- a/runtime/lua/vim/treesitter/highlighter.lua
+++ b/runtime/lua/vim/treesitter/highlighter.lua
@@ -248,7 +248,7 @@ local function on_line_impl(self, buf, line)
end
while line >= state.next_row do
- local capture, node = state.iter()
+ local capture, node, metadata = state.iter()
if capture == nil then break end
@@ -260,7 +260,7 @@ local function on_line_impl(self, buf, line)
{ end_line = end_row, end_col = end_col,
hl_group = hl,
ephemeral = true,
- priority = 100 -- Low but leaves room below
+ priority = tonumber(metadata.priority) or 100 -- Low but leaves room below
})
end
if start_row > line then
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua
index 05e0c5fe2c..175525b3f2 100644
--- a/test/functional/treesitter/highlight_spec.lua
+++ b/test/functional/treesitter/highlight_spec.lua
@@ -570,4 +570,47 @@ describe('treesitter highlighting', function()
]]}
screen:expect{ unchanged=true }
end)
+
+ it("supports highlighting with priority", function()
+ if pending_c_parser(pending) then return end
+
+ insert([[
+ int x = INT_MAX;
+ #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
+ #define foo void main() { \
+ return 42; \
+ }
+ ]])
+
+ exec_lua [[
+ local parser = vim.treesitter.get_parser(0, "c")
+ test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = hl_query..'\n((translation_unit) @Error (set! "priority" 101))\n'}})
+ ]]
+ -- expect everything to have Error highlight
+ screen:expect{grid=[[
+ {12:int}{8: x = INT_MAX;} |
+ {8:#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))}|
+ {8:#define foo void main() { \} |
+ {8: return 42; \} |
+ {8: }} |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]], attr_ids={
+ [1] = {bold = true, foreground = Screen.colors.Blue1};
+ [8] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red};
+ -- bold will not be overwritten at the moment
+ [12] = {background = Screen.colors.Red, bold = true, foreground = Screen.colors.Grey100};
+ }}
+ end)
end)