nvim-treesitter / nvim-treesitter-textobjects

Apache License 2.0
2.19k stars 196 forks source link

Select Mode Keymaps appear broken #586

Closed josiah-lunit closed 7 months ago

josiah-lunit commented 8 months ago

Describe the bug After installing and configuring nvim-treesitter-textobjects, I cannot use vif or associated keymaps in a python file.

Environment MacOS Sonoma 14.3.1 NVChad commit 44a24e2fe5337b09b4a9ed44bdd001e672d99ec9

To Reproduce nvim/lua/custom/configs/overrides.lua

local M = {}

M.treesitter = {
  highlight = {
    enable = true,
  },
  ensure_installed = {
    -- defaults
    "vim",
    "lua",

    -- shell
    "bash",
    "elvish",

    -- build
    "cmake",
    "dockerfile",
    "make",
    "meson",
    "ninja",
    "starlark",

    -- web dev
    "html",
    "css",
    "scss",
    "javascript",
    "typescript",
    "tsx",
    "json",
    "graphql",

    -- backend
    "python",
    "rust",
    "cpp",
    "c_sharp",
    "c",
    "go",
    "haskell",
    "java",
    "solidity",

    -- gpu
    "cuda",
    "glsl",
    "wgsl",

    -- config
    "toml",
    "yaml",
    "terraform",
    "ini",

    -- serialization & network protocols
    "capnp",
    "proto",
    "http",

    -- source control
    "gitignore",
    "gitcommit",
    "gitattributes",
    "diff",
    "git_rebase",
    "git_config",

    -- documentation
    "latex",
    "markdown",
    "comment",

    -- tools
    "gpg",
    "regex",

    -- data
    "csv",
  },
  textobjects = {
    swap = {
      enable = true,
      swap_next = {
        ["<leader>a"] = "@parameter.inner",
      },
      swap_previous = {
        ["<leader>A"] = "@parameter.inner",
      }
    },
    move = {
      enable = true,
      set_jumps = true,
      goto_next_start = {
        ["]m"] = "@function.outer",
        ["gj"] = "@function.outer",
        ["]]"] = "@class.outer",
        ["]b"] = "@block.outer",
        ["]a"] = "@parameter.inner",
      },
      goto_next_end = {
        ["]M"] = "@function.outer",
        ["gJ"] = "@function.outer",
        ["]["] = "@class.outer",
        ["]B"] = "@block.outer",
        ["]A"] = "@parameter.inner",
      },
      goto_previous_start = {
        ["[m"] = "@function.outer",
        ["gk"] = "@function.outer",
        ["[["] = "@class.outer",
        ["[b"] = "@block.outer",
        ["[a"] = "@parameter.inner",
      },
      goto_previous_end = {
        ["[M"] = "@function.outer",
        ["gk"] = "@function.outer",
        ["[]"] = "@class.outer",
        ["[B"] = "@block.outer",
        ["[A"] = "@parameter.inner",
      }
    },
    select = {
      enable = true,
      lookahead = true,
      keymaps = {
        ["af"] = "@function.outer",
        ["if"] = "@function.inner",
        ["ac"] = "@class.outer",
        ["ic"] = "@class.inner",
        ["ab"] = "@block.outer",
        ["ib"] = "@block.inner",
        ["al"] = "@loop.outer",
        ["il"] = "@loop.inner",
        ["a/"] = "@comment.outer",
        ["i/"] = "@comment.inner",
        ["aa"] = "@parameter.outer",
        ["ia"] = "@parameter.inner",
      }
    }
  }
}

return M

nvim/lua/custom/plugins.lua

local overrides = require("custom.configs.overrides")
local plugins = {
  {
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "nvim-treesitter/nvim-treesitter-textobjects",
    dependencies = "nvim-treesitter",
  },
}
return plugins

nvim/lua/custom/chadrc.lua

---@type ChadrcConfig
local M = {}
M.plugins = 'custom.plugins'
return M

Expected behavior When I put the cursor over a function in python and type vaf I expect the function to be highlighted.

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check() Installation ~ - OK `tree-sitter` found 0.22.2 (parser generator, only needed for :TSInstallFromGrammar) - OK `node` found v21.7.1 (only needed for :TSInstallFromGrammar) - OK `git` executable found. - OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" } Version: Apple clang version 15.0.0 (clang-1500.3.9.4) - OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI. OS Info: { machine = "arm64", release = "23.3.0", sysname = "Darwin", version = "Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020" } ~ Parser/Features H L F I J - bash ✓ ✓ ✓ . ✓ - c ✓ ✓ ✓ ✓ ✓ - c_sharp ✓ ✓ ✓ . ✓ - capnp ✓ ✓ ✓ ✓ ✓ - cmake ✓ . ✓ ✓ . - comment ✓ . . . . - cpp ✓ ✓ ✓ ✓ ✓ - css ✓ . ✓ ✓ ✓ - csv ✓ . . . . - cuda ✓ ✓ ✓ ✓ ✓ - diff ✓ . . . . - dockerfile ✓ . . . ✓ - elvish ✓ . . . ✓ - git_config ✓ . ✓ . ✓ - git_rebase ✓ . . . ✓ - gitattributes ✓ ✓ . . ✓ - gitcommit ✓ . . . ✓ - gitignore ✓ . . . . - glsl ✓ ✓ ✓ ✓ ✓ - go ✓ ✓ ✓ ✓ ✓ - gpg ✓ . . . ✓ - graphql ✓ . . ✓ ✓ - haskell ✓ . ✓ . ✓ - html ✓ ✓ ✓ ✓ ✓ - http ✓ . . . ✓ - ini ✓ . ✓ . . - java ✓ ✓ ✓ ✓ ✓ - javascript ✓ ✓ ✓ ✓ ✓ - json ✓ ✓ ✓ ✓ . - latex ✓ . ✓ . ✓ - lua ✓ ✓ ✓ ✓ ✓ - make ✓ . ✓ . ✓ - markdown ✓ . ✓ ✓ ✓ - meson ✓ . ✓ ✓ ✓ - ninja ✓ . ✓ ✓ . - proto ✓ . ✓ . . - python ✓ ✓ ✓ ✓ ✓ - query ✓ ✓ ✓ ✓ ✓ - regex ✓ . . . . - ruby ✓ ✓ ✓ ✓ ✓ - rust ✓ ✓ ✓ ✓ ✓ - scss ✓ . ✓ ✓ . - solidity ✓ . ✓ . . - sql ✓ . . ✓ ✓ - starlark ✓ ✓ ✓ ✓ ✓ - terraform ✓ . ✓ ✓ ✓ - toml ✓ ✓ ✓ ✓ ✓ - 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} ~

Output of nvim --version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1710088188

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"

Run :checkhealth for more info
kiyoon commented 7 months ago

I believe it's a dependency problem in your config.

Your nvim-treesitter opts require nvim-treesitter-textobjects, so I think it makes sense to put nvim-treesitter-textobjects as nvim-treesitter dependency.

However, this plugin will be rewritten so that it doesn't have the module system in the future.

josiah-lunit commented 7 months ago

Yep that was it! I got confused on the dependencies and got it the wrong way around.