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

example "scope" ]s mapping seemingly does nothing #604

Open
aktau opened this issue Apr 15, 2024 · 4 comments
Open

example "scope" ]s mapping seemingly does nothing #604

aktau opened this issue Apr 15, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@aktau
Copy link

aktau commented Apr 15, 2024

Describe the bug

Simply put, the ]s, [s, ]S, [S mappings do nothing for me (no movement), when attempting to navigate around simple C and Go files (haven't tried others yet). Mappings like ]m, [m, ]M, [M do work.

I'm not sure if this problem is PEBKAC or not, but having seen locals.scm for Go/C/..., I suspect it isn't. The README gives this example:

["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" },

But there is no movement (see below). I've verified that nmap ]s shows me an anonymous Lua function is bound.

To Reproduce

-- reproducer.lua
vim.opt.runtimepath:append("$HOME/.vim/bundle/nvim-treesitter")
vim.opt.runtimepath:append("$HOME/.vim/bundle/nvim-treesitter-textobjects")

local treesitter_parsers = {
  "c",
  "cpp",
  "go",
  "lua",
}
require('nvim-treesitter.configs').setup({
  ensure_installed = treesitter_parsers,
  sync_install = false,
  highlight = {
    enable = true,
    additional_vim_regex_highlighting = false,
  },
  textobjects = {
    move = {
      enable = true,
      set_jumps = true, -- whether to set jumps in the jumplist
      goto_next_start = {
        [']m'] = '@function.outer',
        ["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" },
      },
      goto_next_end = {
        [']M'] = '@function.outer',
        ["]S"] = { query = "@scope", query_group = "locals", desc = "Next scope" },
      },
      goto_previous_start = {
        ['[m'] = '@function.outer',
        ["[s"] = { query = "@scope", query_group = "locals", desc = "Next scope" },
      },
      goto_previous_end = {
        ['[M'] = '@function.outer',
        ["[S"] = { query = "@scope", query_group = "locals", desc = "Next scope" },
      },
    },
  },
})
$ nvim -u reproducer.lua example.go

Expected behavior

I expected some movement to happen.v

Output of :checkhealth nvim-treesitter

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 cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (Debian 13.2.0-10) 13.2.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.6.13-amd64",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Debian 6.6.13"
} ~

Parser/Features H L F I J

  • bash ✓ ✓ ✓ . ✓
  • c ✓ ✓ ✓ ✓ ✓
  • cpp ✓ ✓ ✓ ✓ ✓
  • go ✓ ✓ ✓ ✓ ✓
  • lua ✓ ✓ ✓ ✓ ✓
  • markdown ✓ . ✓ ✓ ✓
  • markdown_inline ✓ . . . ✓
  • python ✓ ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓
  • sql ✓ . . ✓ ✓
  • starlark ✓ ✓ ✓ ✓ ✓
  • 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 --version
NVIM v0.10.0-dev-2913+g5371ed36b
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188
Run "nvim -V1 -v" for more info

nvim-treesitter: 1ba86026
nvim-treesitter-textobjects: 6e9bb56
@aktau aktau added the bug Something isn't working label Apr 15, 2024
@Juhan280
Copy link
Contributor

Juhan280 commented Sep 9, 2024

Try this

["]s"] = { query = "@local.scope", query_group = "locals", desc = "Next scope" },

@aktau
Copy link
Author

aktau commented Sep 9, 2024

That actually does something, which is much better than before!

It's not exactly what I want, for example with this C code I first move to the first letter of the if, then to the first brace { when I use ]s. I would prefer just moving to the first brace:

    int c = 3;    

    
    if (ptr == MAP_FAILED) {
/* 1                                      2 */
      perror("mmap");
      return 0;
    }

But it's already a lot better than before. Thanks.

@Juhan280
Copy link
Contributor

Juhan280 commented Sep 9, 2024

This happens because for statement, if statement, while statement, function definition, etc are also defined to make their own scope in https://github.com/nvim-treesitter/nvim-treesitter/blob/4770d9a1a77b0cc2b723c646c3dbe43a9133e5db/queries/c/locals.scm#L58-L67

The work around is to copy that file to ~/.config/nvim/queries/c/locals.scm and then comment out the blocks you don't want to jump to.

@kiyoon
Copy link
Collaborator

kiyoon commented Sep 10, 2024

So the query names in nvim-treesitter seem to have been changed. I guess we need to update the README.

aktau added a commit to aktau/dotfiles that referenced this issue Nov 18, 2024
Otherwise it conflicts with tabularize.

Also difine a ]s, [s movement, though it doesn't work yet:
nvim-treesitter/nvim-treesitter-textobjects#604.
aktau added a commit to aktau/dotfiles that referenced this issue Nov 18, 2024
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

3 participants