nvim-treesitter-textobjects icon indicating copy to clipboard operation
nvim-treesitter-textobjects copied to clipboard

Ruby @function and @block not working

Open otavioschwanck opened this issue 1 year ago • 11 comments

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

otavioschwanck avatar Aug 02 '22 14:08 otavioschwanck

I just tried to use the configuration in the README.md, and I'm seeing this too. I was able to confirm that the mappings do show up in in :nmap <buffer> at least, but they don't appear to do anything.

technicalpickles avatar Aug 14 '22 16:08 technicalpickles

I realized the reason my config wasn't working was because nvim-treesitter-textobjects wasn't actually installed 🤦🏻‍♂️ I think this is probably particularly easy because how these are keys passed into the treesitter setup, rather than requiring something.

technicalpickles avatar Aug 14 '22 16:08 technicalpickles

@otavioschwanck I have the same keymaps as you, and similarly they no longer work. By any chance that you're seeing file read errors if you run :file after opening a Ruby file running :file? Removing the keymaps resolves this issue for me. I noticed that the Ruby queries were updated recently and am going to see if reverting those changes fixes things.

emilford avatar Aug 26 '22 02:08 emilford

@npezza93 reverting the Ruby queries changes fixes the read errors issue mentioned in my previous comment. I can look into it more tomorrow, but any idea what's going on or how best to go about debugging? Thanks!

emilford avatar Aug 26 '22 02:08 emilford

Have you pulled in the latest from nvim-treesitter and installed the newest ruby-tree-sitter?

npezza93 avatar Aug 26 '22 11:08 npezza93

@npezza93 Yes, I've pulled the latest from nvim-treesitter. When you ask whether I've installed the newest ruby-tree-sitter, do you mean the latest Ruby parsers? If so, TSUpdate show that all parsers are up-to-date.

emilford avatar Aug 27 '22 02:08 emilford

Looks like this was an issue on my end. Some combination of reinstalling plugins, parsers, etc., to resolve some checkhealth errors seems to have everything working again for me. Thanks!

emilford avatar Aug 30 '22 16:08 emilford

Hi, for me @function.* is working while @block.* is not

theHamsta avatar Aug 30 '22 18:08 theHamsta

@theHamsta, actually the same for me.

emilford avatar Aug 30 '22 21:08 emilford

I was not able to get this to work for ruby -- is it still the same for others?

manuraj17 avatar Oct 16 '22 05:10 manuraj17

Both of these are working for me, I think this ticket can be closed.

AZanellato avatar Nov 22 '23 13:11 AZanellato