Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triggering incremental selection in an empty file will report an error #5683

Open
onntztzf opened this issue Nov 17, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@onntztzf
Copy link

Describe the bug

Triggering incremental selection in an empty file will report an error.

This is my configuration:

-- https://github.com/nvim-treesitter/nvim-treesitter
require'nvim-treesitter.configs'.setup({
    -- a list of parser names, or "all" (the four listed parsers should always be installed)
    -- https://github.com/nvim-treesitter/nvim-treesitter#supported-languages
    ensure_installed = {"bash", "vim", "lua", "go", "sql", "php", "javascript", "vue", "css", "json", "yaml",
    "markdown", "dockerfile"},
    highlight = {
        enable = true,
        disable = function(lang, buf)
            local max_filesize = 100 * 1024 -- 100 KB
            local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
            if ok and stats and stats.size > max_filesize then
                return true
            end
        end,
        -- setting this to true will run `:h syntax` and tree-sitter at the same time.
        -- set this to `true` if you depend on 'syntax' being enabled (like for indentation).
        -- using this option may slow down your editor, and you may see some duplicate highlights.
        -- instead of true it can also be a list of languages
        additional_vim_regex_highlighting = false
    },
    incremental_selection = {
        enable = true,
        keymaps = {
            init_selection = "<CR>",
            node_incremental = "<CR>",
            node_decremental = "<BS>",
            scope_incremental = "<Tab>",
        },
    },
})

To Reproduce

  1. Create an empty file
    nvim t.go
  2. Click enter
  3. You can see the error
    E5108: Error executing lua: ...r/neovim/0.9.4/share/nvim/runtime/lua/vim/treesitter.lua:190: attempt to index local 'node_or_range' (a nil value) stack traceback:
        ...r/neovim/0.9.4/share/nvim/runtime/lua/vim/treesitter.lua:190: in function 'get_node_range'
        ...im/lazy/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua:279: in function 'update_selection'
        ...treesitter/lua/nvim-treesitter/incremental_selection.lua:18: in function <...treesitter/lua/nvim-treesitter/incremental_selection.lua:14>

Expected behavior

no error will occur

Output of :checkhealth nvim-treesitter

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

Installation ~
- OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v21.2.0 (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.0.40.1)
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "23.1.0",
  sysname = "Darwin",
  version = "Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:27 PDT 2023; root:xnu-10002.41.9~6/RELEASE_X86_64"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - css                 ✓ . ✓ ✓ ✓
  - dockerfile          ✓ . . . ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - json                ✓ ✓ ✓ ✓ .
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - php                 ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - solidity            ✓ . ✓ . .
  - sql                 ✓ . . ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - vue                 ✓ . ✓ ✓ ✓
  - 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.4
Build type: Release
LuaJIT 2.1.1699801871

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.9.4/share/nvim"

Additional context

No response

@onntztzf onntztzf added the bug Something isn't working label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant