nvim-treesitter-textobjects icon indicating copy to clipboard operation
nvim-treesitter-textobjects copied to clipboard

Prompt a error when open a typescript file.

Open singlexyz opened this issue 2 years ago • 5 comments

image

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",
      },
    },
  },

singlexyz avatar May 13 '22 22:05 singlexyz

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

theHamsta avatar May 15 '22 06:05 theHamsta

When I emptied the content in queries/typescript/textobjects.scm, there was no error.

; inherits: javascript

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.

图片

singlexyz avatar Jul 30 '22 14:07 singlexyz

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.

theHamsta avatar Jul 30 '22 14:07 theHamsta

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.

singlexyz avatar Aug 02 '22 16:08 singlexyz

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.

theHamsta avatar Aug 02 '22 20:08 theHamsta