Nvim-treesitter: smart_rename fails for multiple replacements in the same line

Created on 20 Jul 2020  ยท  6Comments  ยท  Source: nvim-treesitter/nvim-treesitter

Describe the bug
smart_rename does not work correctly when replacing the same variable multiple times in the same row, iff the desired variable name is of different length than the original variable name.

To Reproduce
Consider this code:

template <class Functor>
auto inspect(Functor& f, value& ec) {
  return f(ec.a, ec.b);
}

Use smart_rename to rename ec to x.

This is the result:

template <class Functor>
auto inspect(Functor& f, value& x) {
  return f(x.a, exb);
}

Expected behavior

template <class Functor>
auto inspect(Functor& f, value& x) {
  return f(x.a, x.b);
}

Output of :checkhealth nvim_treesitter


health#nvim_treesitter#check

Installation

  • OK: git executable found.
  • OK: cc executable found.

html parser healthcheck

typescript parser healthcheck

markdown parser healthcheck

regex parser healthcheck

c parser healthcheck

  • OK: c parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.

nix parser healthcheck

swift parser healthcheck

java parser healthcheck

python parser healthcheck

  • OK: python parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.

yaml parser healthcheck

elm parser healthcheck

vue parser healthcheck

cpp parser healthcheck

  • OK: cpp parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.

toml parser healthcheck

lua parser healthcheck

ruby parser healthcheck

ocaml parser healthcheck

go parser healthcheck

  • OK: go parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.

scala parser healthcheck

haskell parser healthcheck

rust parser healthcheck

  • OK: rust parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.

json parser healthcheck

jsdoc parser healthcheck

javascript parser healthcheck

css parser healthcheck

julia parser healthcheck

php parser healthcheck

c_sharp parser healthcheck

bash parser healthcheck

tsx parser healthcheck


Output of nvim --version

โฏ nvim --version
NVIM v0.5.0-nightly-217-g950ca6abc
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20200720-14610-1xe0vle/build/config -I/tmp/neovim-20200720-14610-1xe0vle/src -I/usr/local/include -I/tmp/neovim-20200720-14610-1xe0vle/deps-build/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.16.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20200720-14610-1xe0vle/build/src/nvim/auto -I/tmp/neovim-20200720-14610-1xe0vle/build/include
Compiled by dominiklohmann@amethyst

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-950ca6a/share/nvim"

Run :checkhealth for more info
bug

Most helpful comment

I can confirm your PR fixes the issue for me.

All 6 comments

Hi ! thanks for reporting that ! That's actually a bug ! I think I know how this should be fixed (no time now though) !

@steelsojka didn't you have a similar problem once ?

@steelsojka has already some experience with lsp applyTextEdits

Ok, I think I already implemented it @steelsojka

Could you please test #207 ? @dominiklohmann I will have a look on my PR tomorrow. I just coded in really fast and need to check it again.

Sorry, there's still a bug in the fix.
Should be ok now.

I can confirm your PR fixes the issue for me.

Was this page helpful?
0 / 5 - 0 ratings