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

vif/vaf not working in Lua code

Open
#688 1 comment 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

Describe the bug
vaf/vif not working in Lua code

To Reproduce

  1. install nvim-treesitter and nvim-treesitter-textobjects
  2. load a .lua file
  3. move cursor inside a Lua function definition
  4. use vaf/vif to attempt to mark the function

Expected behavior
I expect the lines comprising the function to be selected. Instead, it just changes into visual mode

The following work, however:

  • marking functions with vif/vaf in Python code works
  • marking paragraphs with vip/vap in Lua code works
  • :InspectTree shows that the function is properly recognized by the parser

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~

  • OK tree-sitter found 0.23.0 (parser generator, only needed for :TSInstallFromGrammar)
  • OK node found v18.20.4 (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.5.0",
sysname = "Darwin",
version = "Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000"
} ~

Parser/Features H L F I J

  • c ✓ ✓ ✓ ✓ ✓
  • cpp ✓ ✓ ✓ ✓ ✓
  • fortran ✓ . ✓ ✓ ✓
  • go ✓ ✓ ✓ ✓ ✓
  • haskell ✓ ✓ ✓ . ✓
  • lua ✓ ✓ ✓ ✓ ✓
  • markdown ✓ . ✓ ✓ ✓
  • markdown_inline ✓ . . . ✓
  • python ✓ ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓
  • 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.1
Build type: Release
LuaJIT 2.1.1724512491
Run "nvim -V1 -v" for more info

Additional context
I'm using this init.lua file with -u to isolate the problem, but I get the same problem with my full .lua file:

-- Packer setup to manage plugins
require('packer').startup({
  function(use)
    -- Packer manages itself
    use 'wbthomason/packer.nvim'

    -- Treesitter for syntax highlighting and textobjects
    use {
      'nvim-treesitter/nvim-treesitter',
      run = ':TSUpdate',
      config = function()
        require('nvim-treesitter.configs').setup {
          ensure_installed = { "lua" },  -- Install Lua parser
          highlight = { enable = true }, -- Enable syntax highlighting
          textobjects = { enable = true } -- Enable textobjects
        }
      end
    }

    -- Treesitter Textobjects support
    use 'nvim-treesitter/nvim-treesitter-textobjects'
  end,
  config = {
    auto_clean = false,  -- Disable automatic cleanup of unused plugins
  }

})

-- Basic Neovim settings
vim.opt.number = true             -- Show line numbers
vim.opt.relativenumber = true     -- Show relative line numbers
vim.opt.expandtab = true          -- Use spaces instead of tabs
vim.opt.shiftwidth = 2            -- Number of spaces for each indentation
vim.opt.tabstop = 2               -- Number of spaces per tab

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 isolated init.lua configuration and reproduce the issue on a Lua function using vaf and vif. Use :InspectTree to compare the Lua function structure with the working Python case, then verify that vaf/vif selects the function lines while vip/vap and Python textobjects continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
developer-experience, 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.