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

Rust @function.outer breaks with indentation #553

Open
farnoy opened this issue Jan 15, 2024 · 1 comment
Open

Rust @function.outer breaks with indentation #553

farnoy opened this issue Jan 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@farnoy
Copy link

farnoy commented Jan 15, 2024

Describe the bug
@function.outer works when the function is defined in the first column, but breaks when indented.

To Reproduce
Steps to reproduce the behavior:
1.

impl Test {
    fn one() {
    }

    fn two() {
    }
}
  1. omap af *@<Cmd>lua require'nvim-treesitter.textobjects.select'.select_textobject('@function.outer','textobjects','o')<CR>
  2. gg0vaf
  3. It selects lines 2 through 5, including the fn two() {

Expected behavior
It should have selected lines 2 and 3, the first 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 clang executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: clang version 17.0.5
  • 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 = "10.0.22631",
sysname = "Windows_NT",
version = "Windows 11 Pro for Workstations"
} ~

Parser/Features H L F I J

  • c ✓ ✓ ✓ ✓ ✓
  • elixir ✓ ✓ ✓ ✓ ✓
  • heex ✓ ✓ ✓ ✓ ✓
  • html ✓ ✓ ✓ ✓ ✓
  • javascript ✓ ✓ ✓ ✓ ✓
  • lua ✓ ✓ ✓ ✓ ✓
  • markdown ✓ . ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓
  • rust ✓ ✓ ✓ ✓ ✓
  • slang ✓ ✓ ✓ ✓ ✓
  • toml ✓ ✓ ✓ ✓ ✓
  • vim ✓ ✓ ✓ . ✓
  • vimdoc ✓ . . . ✓

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-2080+g92c59c39c
Build type: RelWithDebInfo
LuaJIT 2.1.1703358377

Additional context

@farnoy farnoy added the bug Something isn't working label Jan 15, 2024
@nhu
Copy link

nhu commented Feb 6, 2024

I have noticed the same issue in rust and csharp.

It may be related to the 'textobjects.select.include_surrounding_whitespace' option.
If it is set to true, I get the described behaviour.
If it is et to false, the function is selected correctly.

InspectTree shows that the syntax tree is correct, if this is any useful.

2024-02-06_15-43

config (it's the sample config without comments)
textobjects = {
  select = {
    enable = true,
    lookahead = true,
    keymaps = {
      ["af"] = "@function.outer",
      ["if"] = "@function.inner",
      ["ac"] = "@class.outer",
      ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
      ["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" },
    },
    selection_modes = {
      ['@parameter.outer'] = 'v', 
      ['@function.outer'] = 'V',  
      ['@class.outer'] = '<c-v>', 
    },
    include_surrounding_whitespace = false,  -- <-- set to TRUE and the selection breaks
  },
}
:checkhealth nvim-treesitter ============================================================================== nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~

  • OK tree-sitter found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
  • OK node found v21.6.1 (only needed for :TSInstallFromGrammar)
  • OK git executable found.
  • OK cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (GCC) 13.2.1 20230801
  • 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.7.2-arch1-1",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Fri, 26 Jan 2024 19:10:20 +0000"
} ~

Parser/Features H L F I J

  • bash ✓ ✓ ✓ . ✓
  • c ✓ ✓ ✓ ✓ ✓
  • c_sharp ✓ ✓ ✓ . ✓
  • csv ✓ . . . .
  • graphql ✓ . . ✓ ✓
  • html ✓ ✓ ✓ ✓ ✓
  • hurl ✓ . ✓ ✓ ✓
  • javascript ✓ ✓ ✓ ✓ ✓
  • json ✓ ✓ ✓ ✓ .
  • lua ✓ ✓ ✓ ✓ ✓
  • luadoc ✓ . . . .
  • luap ✓ . . . .
  • markdown ✓ . ✓ ✓ ✓
  • markdown_inline ✓ . . . ✓
  • python ✓ ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓
  • regex ✓ . . . .
  • rust ✓ ✓ ✓ ✓ ✓
  • sql ✓ . . ✓ ✓
  • tsx ✓ ✓ ✓ ✓ ✓
  • typescript ✓ ✓ ✓ ✓ ✓
  • vim ✓ ✓ ✓ . ✓
  • vimdoc ✓ . . . ✓
  • wgsl ✓ . ✓ ✓ .
  • 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} ~

nvim --version NVIM v0.9.5 Build type: Release LuaJIT 2.1.1702233742

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

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