Skip to content

textobjects.move errors when no Treesitter parser is available (should no-op like select) #883

@jonas-srlabs

Description

@jonas-srlabs

Describe the bug
nvim-treesitter-textobjects movement functions (e.g. goto_next_start) throw a Lua error when no Treesitter parser is available for the current buffer, instead of failing silently.

Selection textobjects (e.g. select_textobject) do not error in the same situation, which leads to inconsistent behavior within the plugin.


To Reproduce

  1. Open a filetype without an installed Treesitter parser (e.g. :e test.txt)
  2. Define a mapping using goto_next_start, e.g.:
vim.keymap.set('n', ']m', function()
  require('nvim-treesitter-textobjects.move')
    .goto_next_start('@function.outer', 'textobjects')
end)
  1. Press ]m
  2. Observe Lua error:
attempt to perform arithmetic on local 'score' (a nil value)

Expected behavior
Movement functions should behave like selection textobjects and fail silently / no-op when:

  • no Treesitter parser is available, or
  • no valid matches are found

They should not raise Lua errors.


Output of :checkhealth nvim-treesitter

Details

(omitted / not relevant — issue occurs specifically when no parser is installed)


Output of nvim --version

NVIM v0.12.1
Build type: Release

Additional context


Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions