nvim-treesitter / nvim-treesitter-refactor

Refactor module for nvim-treesitter
Apache License 2.0
407 stars 25 forks source link

Don't rename function usages in shell script #52

Open saccarosium opened 1 year ago

saccarosium commented 1 year ago

Describe the bug

Considering the following script:

For example, I have the following script:

greet() {
  echo "Hello"
}

greet

If I try to rename the function greet with new_name it will rename the function declaration, or the individual function call I have my cursor on, but not all the other references to than function.

The function will look something like this:

new_name() {
  echo "Hello"
}

greet

Expected behavior

After I rename one reference to a function I expect that all the renamed references were renamed too.

Output of :checkhealth nvim_treesitter

Installation - OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar) - OK `node` found v20.8.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 15.0.0 (clang-1500.0.40.1) - OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI. OS Info: { machine = "x86_64", release = "23.0.0", sysname = "Darwin", version = "Darwin Kernel Version 23.0.0: Fri Sep 15 14:42:42 PDT 2023; root:xnu-10002.1.13~1/RELEASE_X86_64" } ~ Parser/Features H L F I J - bash ✓ ✓ ✓ . ✓ - c ✓ ✓ ✓ ✓ ✓ - cmake ✓ . ✓ ✓ . - cpp ✓ ✓ ✓ ✓ ✓ - diff ✓ . . . . - git_rebase ✓ . . . ✓ - gitcommit ✓ . . . ✓ - gitignore ✓ . . . . - java ✓ ✓ ✓ ✓ ✓ - javascript ✓ ✓ ✓ ✓ ✓ - json ✓ ✓ ✓ ✓ . - lua ✓ ✓ ✓ ✓ ✓ - make ✓ . ✓ . ✓ - markdown ✓ . ✓ ✓ ✓ - markdown_inline ✓ . . . ✓ - python ✓ ✓ ✓ ✓ ✓ - query ✓ ✓ ✓ ✓ ✓ - requirements ✓ . . . ✓ - teal ✓ ✓ ✓ ✓ ✓ - toml ✓ ✓ ✓ ✓ ✓ - 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

Note Appens also on stable release

NVIM v0.10.0-dev-1280+g3079fa1f9
Build type: RelWithDebInfo
LuaJIT 2.1.1695653777
Run "nvim -V1 -v" for more info

Additional context

I'm pretty sure is a problem with the bash parser, but wanna make sure that it is the case.

The parser will produce the following AST for the example script above:

(function_definition) ; [1:1 - 3:1]
 name: (word) ; [1:1 - 5]
 body: (compound_statement) ; [1:9 - 3:1]
  (command) ; [2:5 - 16]
   name: (command_name) ; [2:5 - 8]
    (word) ; [2:5 - 8]
   argument: (string) ; [2:10 - 16]
    (string_content) ; [2:11 - 15]
(command) ; [5:1 - 5]
 name: (command_name) ; [5:1 - 5]
  (word) ; [5:1 - 5]

When you call a function it doesn't distinguish if you are calling a function or an executable. I think this is the issue.