nvim-treesitter-textobjects
nvim-treesitter-textobjects copied to clipboard
Prompt a error when open a typescript file.
![image](https://user-images.githubusercontent.com/4456413/168396537-ba8ab1b1-4414-468d-8c6e-1367408f195a.png)
NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
When I delete textobjects
config part of require("nvim-treesitter.configs").setup()
, It works fine. but at the same time there is no corresponding configuration for textobjects.
Here's my textobjects
config:
textobjects = {
move = {
enable = true,
set_jumps = true,
goto_next_start = {
["]x"] = "@attribute.outer",
["]i"] = "@import.outer",
["]f"] = "@function.outer",
["]c"] = "@class.outer",
["]d"] = "@declaration.outer",
["],"] = "@lhs.inner",
["]z"] = "@comment.outer",
},
goto_next_end = {
["]X"] = "@attribute.outer",
["]I"] = "@import.outer",
["]F"] = "@function.outer",
["]C"] = "@class.outer",
["]D"] = "@declaration.outer",
["]."] = "@rhs.inner",
["]Z"] = "@comment.outer",
},
goto_previous_start = {
["[x"] = "@attribute.outer",
["[i"] = "@import.outer",
["[f"] = "@function.outer",
["[c"] = "@class.outer",
["[d"] = "@declaration.outer",
["[,"] = "@lhs.inner",
["[z"] = "@comment.outer",
},
goto_previous_end = {
["[X"] = "@attribute.outer",
["[I"] = "@import.outer",
["[F"] = "@function.outer",
["[C"] = "@class.outer",
["[D"] = "@declaration.outer",
["[."] = "@rhs.inner",
["[Z"] = "@comment.outer",
},
},
select = {
enable = true,
lookahead = true,
keymaps = {
["ax"] = "@attribute.outer",
["ix"] = "@attribute.inner",
["az"] = "@comment.outer",
["iz"] = "@comment.outer",
-- ["at"] = "@tag.outer",
-- ["it"] = "@tag.inner",
["am"] = "@import.outer",
["im"] = "@import.inner",
["a,"] = "@lhs.outer",
["i,"] = "@lhs.inner",
["a."] = "@rhs.outer",
["i."] = "@rhs.inner",
["ad"] = "@declaration.outer",
["id"] = "@declaration.inner",
["af"] = "@function.outer",
["if"] = "@function.inner",
-- ["aC"] = "@class.outer",
-- ["iC"] = "@class.inner",
["ac"] = "@call.outer",
["ic"] = "@call.inner",
-- ["ao"] = "@block.outer",
-- ["io"] = "@block.inner",
["a;"] = "@block.outer",
["i;"] = "@block.inner",
-- json
["ak"] = "@key.outer",
["ik"] = "@key.inner",
["av"] = "@value.outer",
["iv"] = "@value.inner",
},
},
},
Can you try to run the query linter from nvim-treesitter/playground to see whether there are any invalid nodes? You can copy the contents ecma/textobjects.scm into typescript/textobjects.scm to test the ecma queries explicitly in the context of typescript. Also use nvim_get_runtimefile
to check whether there is an additional installation of the typescript parser
When I emptied the content in queries/typescript/textobjects.scm
, there was no error.
Then I copy the queries from queries/javascript/textobjects.scm
into it, It works fine.
As long as typescript inherits javascript, it will report an error, even if it is textobjects.scm in the after/queries directory.
Then I tried the highlights module, there is no such problem.
![图片](https://user-images.githubusercontent.com/4456413/181918122-610766c4-7227-4cfe-b66d-ceabf2621f25.png)
Yes, this is because JavaScript contains JSX nodes which the typescript parser can't handle (only in TSX mode). We created the "emca" alias for queries that are compatible with JavaScript and typescript.
Yes, this is because JavaScript contains JSX nodes which the typescript parser can't handle (only in TSX mode). We created the "emca" alias for queries that are compatible with JavaScript and typescript.
Can i initiate a PR? I simply added ecma and inherited it from javascript/typescript and it works fine.
Can i initiate a PR? I simply added ecma and inherited it from javascript/typescript and it works fine.
Yes, please! Actually javascript/typescript should inherit from emca
with ecma
containing all the parts of javascript that don't cause error in typescript. You can see in highlights.scm of javascript/typscript/ecma on how it is indented to be used.