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

@inner.block @outer.block makes no sense in C I believe #589

Open
ilan-schemoul opened this issue Apr 2, 2024 · 4 comments
Open

@inner.block @outer.block makes no sense in C I believe #589

ilan-schemoul opened this issue Apr 2, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@ilan-schemoul
Copy link
Contributor

To Reproduce
open a c file

Capture d'écran 2024-04-02 021921

select inner block
Capture d'écran 2024-04-02 021932

select outer block
Capture d'écran 2024-04-02 021947

Expected behavior
expected inner block
Capture d'écran 2024-04-02 021955

expected outer block

Capture d'écran 2024-04-02 022003

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)
  • OK node found v18.19.1 (only needed for :TSInstallFromGrammar)
  • OK git executable found.
  • OK cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.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 = "5.15.146.1-microsoft-standard-WSL2",
sysname = "Linux",
version = "#1 SMP Thu Jan 11 04:09:03 UTC 2024"
} ~

Parser/Features H L F I J

  • bash ✓ ✓ ✓ . ✓
  • c ✓ ✓ ✓ ✓ ✓
  • cpp ✓ ✓ ✓ ✓ ✓
  • css ✓ . ✓ ✓ ✓
  • diff ✓ . . . .
  • fish ✓ ✓ ✓ ✓ ✓
  • git_config ✓ . ✓ . ✓
  • git_rebase ✓ . . . ✓
  • gitcommit ✓ . . . ✓
  • gitignore ✓ . . . .
  • json ✓ ✓ ✓ ✓ .
  • lua ✓ ✓ ✓ ✓ ✓
  • markdown ✓ . ✓ ✓ ✓
  • markdown_inline ✓ . . . ✓
  • nix ✓ ✓ ✓ . ✓
  • norg . . . . .
  • python ✓ ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓
  • regex ✓ . . . .
  • rust ✓ ✓ ✓ ✓ ✓
  • toml ✓ ✓ ✓ ✓ ✓
  • 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.10.0-dev-2765+gb8858dddb
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188
Run ":verbose version" for more info

@ilan-schemoul
Copy link
Contributor Author

block.inner is kind of random everytime it selects a unexpected thing sometimes even outside the block

@ilan-schemoul
Copy link
Contributor Author

inner.block does not seem defined for C

I tried (_ (compound_statement) @block.inner) @block.outer but then inner and outer block both select the same thing (the thing between two stars **)

if (test) **{
   a
   b
}**

Ideally I want
Inner

if (test) {
   **a
   b**
}

Outer

if (test) **{
   a
   b
}**

I don't think it's possible because of how C is represented in Treesitter. So at the very least it could do like Javascript

if (test) **{
   a
   b
}**

Outer

**if (test) {
   a
   b
}**

@ilan-schemoul
Copy link
Contributor Author

ilan-schemoul commented May 18, 2024

There are multiple problems:

  1. no block.inner specified
  2. selecting randomly when nothing is defined.
  3. make-range to exclude "{" curly brackets is inconsistent as explained here Add #make-range-between! #608
  4. block.outer defined but buggy. E.g:
    Capture d'écran 2024-05-18 103750
    As said I expect block.outer to be :
    Capture d'écran 2024-05-18 104331

Selecting inner/outer block is a common use case I hope this issue will get some attention because right now there are way too many problems for me alone to fix easily.

@ribru17
Copy link
Collaborator

ribru17 commented Jun 7, 2024

I think in the printf case, it might be selecting inside the parentheses because it can't find an inner block so it falls back to the default ib behavior. As for the last screenshot, do you have include_surrounding_whitespace on for this block? I think that might be why the range is so expansive

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

2 participants