nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects

Ruby @function and @block not working

Open
#238 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Tree-sitter Query
Stars
2.8k
Forks
271
Avg merge
8d 8h
Merged PRs (30d)
1

Description

Using an example class:

class Teste
  def method_a # first function
  end

  def method_b  # first function
  end

  first_block do
  end

  second_block do
  end
end

My setup:

local M = {}

function M.setup()
  require'nvim-treesitter.configs'.setup {
    ensure_installed = "all",

    textobjects = {
      move = {
        enable = true,
        set_jumps = true, -- whether to set jumps in the jumplist
        goto_next_start = {
          ["]c"] = "@class.outer",
          ["]]"] = "@function.outer",
        },
        goto_next_end = {
          ["]C"] = "@class.outer",
          ["]["] = "@function.outer",
        },
        goto_previous_start = {
          ["[c"] = "@class.outer",
          ["[["] = "@function.outer",
        },
        goto_previous_end = {
          ["[C"] = "@class.outer",
          ["[]"] = "@function.outer",
        },
      },
      rainbow = { enabled = true, extended_mode = true, max_file_lines = 1500 },
      select = {
        enable = true,

        lookahead = true,

        keymaps = {
          ["af"] = "@function.outer",
          ["if"] = "@function.inner",
          ["ac"] = "@class.outer",
          ["ic"] = "@class.inner",
        },
      },
    },

    endwise = {
      enable = true,
    },


    -- List of parsers to ignore installing
    ignore_install = { "phpdoc" },

    autotag = {
      enable = true,
    },
    -- Install languages synchronously (only applied to `ensure_installed`)
    sync_install = false,

    indent = { enable = true, disable = { "ruby", "python" } },

    highlight = {
      enable = true,
    },
  }
end

return M

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Ruby example and the nvim-treesitter.configs textobjects setup shown in the issue, focusing on the @function and @block captures used by movement and selection. Reproduce the behavior in Neovim, then verify that the configured mappings move between and select the expected Ruby methods and blocks.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, ruby, vim
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.