nvim-treesitter / nvim-treesitter-textobjects

Apache License 2.0
2.09k stars 187 forks source link

Ruby @function and @block not working #238

Open otavioschwanck opened 2 years ago

otavioschwanck commented 2 years ago

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
technicalpickles commented 2 years ago

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 commented 2 years ago

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.

emilford commented 2 years ago

@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 commented 2 years ago

@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!

npezza93 commented 2 years ago

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

emilford commented 2 years ago

@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 commented 2 years ago

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!

theHamsta commented 2 years ago

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

emilford commented 2 years ago

@theHamsta, actually the same for me.

manuraj17 commented 1 year ago

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

AZanellato commented 9 months ago

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