diff options
author | L Lllvvuu <git@llllvvuu.dev> | 2023-09-13 16:51:54 -0700 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2023-09-16 11:12:06 +0100 |
commit | 908843df61fc80f160392edc0af0d1672a8f9a68 (patch) | |
tree | 37cd0c2d22e3855a1dd0fd003a63c77a03583fcd /test/functional/treesitter/highlight_spec.lua | |
parent | 40bfca744dd0c87df6ec2ab776f982636e4b0904 (diff) | |
download | rneovim-908843df61fc80f160392edc0af0d1672a8f9a68.tar.gz rneovim-908843df61fc80f160392edc0af0d1672a8f9a68.tar.bz2 rneovim-908843df61fc80f160392edc0af0d1672a8f9a68.zip |
fix(languagetree): apply `resolve_lang` to `metadata['injection.language']`
`resolve_lang` is applied to `@injection.language` when it's supplied as a
capture:
https://github.com/neovim/neovim/blob/f5953edbac14febce9d4f8a3c35bdec1eae26fbe/runtime/lua/vim/treesitter/languagetree.lua#L766-L768
If we want to support `metadata['injection.language']` (as per #22518 and
[tree-sitter upstream](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#language-injection))
then the behavior should be consistent.
Fixes: nvim-treesitter/nvim-treesitter#4918
Diffstat (limited to 'test/functional/treesitter/highlight_spec.lua')
-rw-r--r-- | test/functional/treesitter/highlight_spec.lua | 117 |
1 files changed, 70 insertions, 47 deletions
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index 0528370e2a..0aa0cdd6d6 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -85,6 +85,56 @@ void ui_refresh(void) } }]] +local injection_text_c = [[ +int x = INT_MAX; +#define READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) +#define foo void main() { \ + return 42; \ + } +]] + +local injection_grid_c = [[ + int x = INT_MAX; | + #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) | + #define foo void main() { \ | + return 42; \ | + } | + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | +]] + +local injection_grid_expected_c = [[ + {3:int} x = {5:INT_MAX}; | + #define {5:READ_STRING}(x, y) ({3:char} *)read_string((x), ({3:size_t})(y)) | + #define foo {3:void} main() { \ | + {4:return} {5:42}; \ | + } | + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | +]] + describe('treesitter highlighting (C)', function() local screen @@ -411,34 +461,9 @@ describe('treesitter highlighting (C)', function() end) it("supports injected languages", function() - insert([[ - int x = INT_MAX; - #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) - #define foo void main() { \ - return 42; \ - } - ]]) + insert(injection_text_c) - screen:expect{grid=[[ - int x = INT_MAX; | - #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) | - #define foo void main() { \ | - return 42; \ | - } | - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - | - ]]} + screen:expect{grid=injection_grid_c} exec_lua [[ local parser = vim.treesitter.get_parser(0, "c", { @@ -448,26 +473,24 @@ describe('treesitter highlighting (C)', function() test_hl = highlighter.new(parser, {queries = {c = hl_query}}) ]] - screen:expect{grid=[[ - {3:int} x = {5:INT_MAX}; | - #define {5:READ_STRING}(x, y) ({3:char} *)read_string((x), ({3:size_t})(y)) | - #define foo {3:void} main() { \ | - {4:return} {5:42}; \ | - } | - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - | - ]]} + screen:expect{grid=injection_grid_expected_c} + end) + + it("supports injecting by ft name in metadata['injection.language']", function() + insert(injection_text_c) + + screen:expect{grid=injection_grid_c} + + exec_lua [[ + vim.treesitter.language.register("c", "foo") + local parser = vim.treesitter.get_parser(0, "c", { + injections = {c = '(preproc_def (preproc_arg) @injection.content (#set! injection.language "fOO")) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.language "fOO"))'} + }) + local highlighter = vim.treesitter.highlighter + test_hl = highlighter.new(parser, {queries = {c = hl_query}}) + ]] + + screen:expect{grid=injection_grid_expected_c} end) it("supports overriding queries, like ", function() |