Closed owarai closed 3 years ago
Hi, I am moving your issue in the correct repo, as this is a separate module.
Could you try to bisect (using git bisect
) when this started happening ? This will greatly help us !
Since this repo doesn't commit frequently, I rollback to commit 130d94(Sep 19, 2020), nothing different happened. I also rollback the commit of nvim-treesitter serveral times, stop onto ac4219(Dec 22, 2020), same with above.
goto_next_usage
is a feature that I use frequently, so I think it can't have stopped working before this time point and I didn't notice it.
I tried to use
goto_next_usage
in lua/go/rust, but none of them worked.
The phenomenon:
If I put my cursor to a variable name, trigger goto_next_usage
will only move the cursor to the start of variable name.
By the way, does the goto_next_usage
function work properly for you?
Had the same issue, installing it from commit 130d94
did help 🙂
Just noticed this. I think it's just a math error in navigation.lua:146
. The call below correctly finds the next usage:
require'nvim-treesitter-refactor.navigation'.goto_adjacent_usage(#buf, 2)
I looked into this more but I'm not particularly familiar with the internals of treesitter so I may be wrong about some things. It seems like find_usages
returns a table with two copies of each node, or maybe two different nodes for each usage which both have the same row/column. index_of
finds the first "copy" so subtracting 1 takes us to the second "copy" of the previous usage while adding one takes us to the second "copy" of the usage our cursor is currently on thus the cursor doesn't move.
Changing the definitions of goto_next_usage
& goto_previous_usage
to the following works:
function M.goto_next_usage(bufnr) return M.goto_adjacent_usage(bufnr, 2) end
function M.goto_previous_usage(bufnr) return M.goto_adjacent_usage(bufnr, -2) end
edit: it would probably make more sense to multiply delta
by two in goto_adjacent_usage
@harrygallagher4 this is a upstream problem that affects all tree-sitter modules, see #11 in this repo or my fix for nvim-dap-virtual-text. Neovim right now just includes the queries multiple times (all query results are doubled) which means that it will think that the definition on which you currently are is the same position as the next position.
@vigoux, @steelsojka
By the way, in some filetypes, tthe results aren't doubled, they are multiplied by 8. So, using M.goto_adjacent_usage(bufnr, 2)
is not reliable.
This is because the duplication is the result on how Neovim finds the query files. Depending on the filetype and your runtime path it may find one and the same file more than once and just appends them. Which results in doubling, trippling the reference results or just having them simple.
See this PR here: https://github.com/neovim/neovim/pull/13778 We could also fixing it be deduplicating the references in nvim-treesitter but this feels a bit like a hack. With #11 I fixed the same problem.
neovim/neovim#13778 has been merged. At least under normal circumstances (unless you have doubled-queries), this bug should no longer occur.
Confirmed that my issue from comment https://github.com/nvim-treesitter/nvim-treesitter-refactor/issues/10#issue-786707514 is fixed.
@owarai can this be closed then?
Yes!!! thanks for your work on this.
Describe the bug
the feature of treesitter refactor part:
goto_next_usage
not work from several days ago, butgoto_prev_usage
still works.To Reproduce Steps to reproduce the behavior:
'nvim-treesitter/nvim-treesitter', 'nvim-treesitter/nvim-treesitter-textobjects', 'nvim-treesitter/nvim-treesitter-refactor'
Expected behavior
goto_next_usage
works like before.Output of
:checkhealth nvim_treesitter
======================================================================== ## Installation - OK: `git` executable found. - OK: `cc` executable found. ## lua parser healthcheck - OK: lua parser found. - OK: `highlights.scm` found. - OK: `locals.scm` found. - OK: `folds.scm` found. - OK: `indents.scm` found. ## go parser healthcheck - OK: go parser found. - OK: `highlights.scm` found. - OK: `locals.scm` found. - OK: `folds.scm` found. - WARNING: No `indents.scm` query found for go - ADVICE: - Open an issue at https://github.com/nvim-treesitter/nvim-treesitter ## rust parser healthcheck - OK: rust parser found. - OK: `highlights.scm` found. - OK: `locals.scm` found. - OK: `folds.scm` found. - WARNING: No `indents.scm` query found for rust - ADVICE: - Open an issue at https://github.com/nvim-treesitter/nvim-treesitter
Output of
nvim --version
Additional context repo & parsers all updated to latest.