Repository: neovim
Issue: Treesitter:  Make `iter_captures` include all "parent" captures when called on one line
Labels: enhancement,has:repro,treesitter

### Problem

Update: I might be misremembering something about the "old" behavior, so that can be disregarded, but I would still like an option for the described behavior. 

In earlier versions of neovim `iter_captures` included all the captures caught from the "parents" of the captures on the line it was called on, when called on one line. (This is not very clear, I think the example is easier to follow.) But now it only includes the outermost capture and not the internal ones. (Looking back at this, I am not 100% sure that neovim used to behave exactly as I said here, but there has definitely been some change since the Fall of 2023.)

For example, in `rainbow-delimiters` most queries look something like
```query
(name
  "(" @delimiter
  ")" @delimiter @sentinel) @container
```
or similar with `[]`, `{}`, etc. 

When capturing a change at the cursor (marked by `|`) in
```lua
local tmp = {
  [1] = {1},
  [2] = {
    a = print(|)
  },
}
```
and updating highlighting via `iter_captures` on the cursor line (and not the whole tree), I now get capture names like this:
```
container (from outer {})
container (from [2])
container (from inner {})
container (from print() )
delimiter 
delimiter
sentinel
```
where I used to get all `delimiter` and `sentinel` captures from the included `container` captures in the above. 

The old captures with all `delimiter` and `sentinel` captures included (so the above would look like
```
container -- from outer {}
delimiter -- {   from outer {}

container -- from [2]
delimiter -- [   from [2]
delimiter -- ]   from [2]
sentinel  -- ]   from [2], which ends here

container -- from inner {}
delimiter -- {   from inner {}

container -- from () in print()
delimiter -- (   from ()
delimiter -- )   from ()
sentinel  -- )   from (), which ends here

delimiter -- }   from inner {}
sentinel  -- }   from inner {}, which ends here

delimiter -- }   from outer {}
sentinel  -- }   from outer {}, which ends here
```
), were much easier to reason about when figuring out the nesting level.

(Update: The above might not have actually been an old behavior for one line changes, but it is similar to the _current_ behavior when using `iter_captures` on the whole buffer, and it is a behavior I would like to be able to get.)

With the way captures are currently reported the only way to figure out nesting is by making assumptions that are not always true or try using a lot of ancestor checks in treesitter, but that affects the performance (or at least it did last I checked) and doesn't work as well, so it would be nice to have an option to include all the captures as above. 

Note: For a lot of situations, you might not want as much information as I am asking for, so I think it makes sense to keep an option in `opts` table deciding which way to use.

Also, I know that some work on `iter_captures` is already being done in #27274, so that PR might already fix this? I haven't fully looked into the details of what is causing my problem yet.

### Expected behavior

Be able to get all "parent" captures as you used to be able to do.

Note: `iter_matches` already has an `opts` table, and thus `iter_captures` basically also has one too although the types don't reflect this currently.