Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS "generator function" expression are not recognised #736

Open
tizot opened this issue Mar 2, 2025 · 0 comments
Open

JS "generator function" expression are not recognised #736

tizot opened this issue Mar 2, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@tizot
Copy link

tizot commented Mar 2, 2025

Hi,

I am stumbling on an issue similar to #633, more specifically in the case where the generator function is not declared as a statement but as an expression (for example as an argument of another function).
The command :TSTextobjectSelect @function.outer selects nothing when the cursor is placed inside a generator function, when that function is not declared with a statement.

Thanks for the help!

To reproduce

  1. Open a new file, in a neovim instance with TS installed
  2. Write/paste a generator function and assign it to a variable
    const fn = function* () {
      yield 1;
    };
  3. Put cursor inside and try select the whole function with :TSTextobjectSelect @function.outer

Expected behaviour

The full function is selected instead of nothing happening.

Image

Note that the code is correctly parsed and the "function" is parsed as a generator_function:

Image

Additional context

I have tried to add new text objects definitions in the file <config folder>/queries/ecma/textobjects.scm:

(generator_function 
  body: (statement_block)) @function.outer

(generator_function
  body: (statement_block
    .
    "{"
    .
    (_) @_start @_end
    (_)? @_end
    .
    "}"
    (#make-range! "function.inner" @_start @_end)))

But it does not work as expected (now, the :TSTextobjectSelect @function.outer command only selected generator functions and not regular functions anymore 😅). I guess I am missing something...

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter:                     require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.25.2 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.11.0 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: Apple clang version 16.0.0 (clang-1600.0.26.6)
- OK Neovim was compiled with tree-sitter runtime ABI version 15 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "arm64",
  release = "24.3.0",
  sysname = "Darwin",
  version = "Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - diff                ✓ . ✓ . ✓
  - dockerfile          ✓ . . . ✓
  - graphql             ✓ . . ✓ ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - json                ✓ ✓ ✓ ✓ .
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - prisma              ✓ . ✓ . ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - regex               ✓ . . . .
  - svelte              ✓ ✓ ✓ ✓ ✓
  - tsx                 ✓ ✓ ✓ ✓ ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - yaml                ✓ ✓ ✓ ✓ ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

Output of nvim --version

NVIM v0.11.0-dev-1878+g45d7aa3301
Build type: RelWithDebInfo
LuaJIT 2.1.1736781742
Run "nvim -V1 -v" for more info
@tizot tizot added the bug Something isn't working label Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant