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

Inconsistent behavior between delete and select operations for the same text-object #506

Open
ghostbuster91 opened this issue Oct 13, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@ghostbuster91
Copy link
Contributor

ghostbuster91 commented Oct 13, 2023

Describe the bug
Deleting a scala function using function.outer text object in some cases deletes also the next function, while using the same text-object to select code always highlights correctly only a single function.

To Reproduce
Given the following code:

object Outer {

  object Inner {

    override def methodA(): String =
      "some text"

    override def methodB(): String = ""

  }
}

and the cursor on methodA selecting the function outer object using:
lua require("nvim-treesitter.textobjects.select").select_textobject('@function.outer', 'textobjects', 'x')

results in:
image

However if we try to call the same object but with a delete operation it results in both methods getting deleted:
image

Expected behavior
I would expect both operators - delete and select to work in a consistent way. Especially deleting using @fuction.outer should only delete a single function.

Output of :checkhealth nvim-treesitter

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

Installation ~
- WARNING `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
- WARNING `node` executable not found (only needed for :TSInstallFromGrammar, not required for :TSInstall)
- OK `git` executable found.
- OK `gcc` executable found. Selected from { "gcc", "cc", "gcc", "clang", "cl", "zig" }
  Version: gcc (GCC) 12.3.0
- 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 = "6.1.52",
  sysname = "Linux",
  version = "#1-NixOS SMP PREEMPT_DYNAMIC Wed Sep  6 20:27:03 UTC 2023"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - comment             ✓ . . . .
  - devicetree          ✓ ✓ ✓ ✓ ✓
  - dockerfile          ✓ . . . ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - graphql             ✓ . . ✓ ✓
  - hocon               ✓ . . . ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - java                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - json                ✓ ✓ ✓ ✓ .
  - kotlin              ✓ ✓ ✓ . ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - nix                 ✓ ✓ ✓ . ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - scala               ✓ ✓ ✓ . ✓
  - scheme              ✓ . ✓ . ✓
  - smithy              ✓ . . . .
  - sql                 ✓ . . ✓ ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - xml                 ✓ . ✓ ✓ ✓
  - 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.9.2
Build type: Release
LuaJIT 2.1.1693350652

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/nix/store/1b4pbg130cdq5pjyi7vxqqrf7nqh63a5-neovim-unwrapped-0.9.2/share/nvim
"

Additional context
Add any other context about the problem here.

while trying to minimize the reproduction example I found following interesting cases:
If we remove the inner object but leave the indentation intact, both functions will be deleted:
image
but if we format the code (fix the redundant indentations) the delete operation will work correctly.
image

After compacting the first function to a single line it also works correctly:
image

It also works if the function that is being deleted is defined using braces:
image

treesitter-scala rev: 70afdd5632d57dd63a960972ab25945e353a52f6

@ghostbuster91 ghostbuster91 added the bug Something isn't working label Oct 13, 2023
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