Skip to content

bug: pcall(treesitter.get_parser) returns 'true' when parser is nil #54

@Davito3

Description

@Davito3

Did you check docs and existing issues?

  • I have read all the twilight.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of twilight.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

v0.12.2

Operating system/version

Windows 11, WSL2 Ubuntu 26.04 LTS

Describe the bug

I encounter the following error when enabling Twilight on a .txt file:

Image
I think it has to do with no treesitter parser installed for text filetypes. I also have this issue with other filetypes that treesitter has no parser installed for. After some debugging it seems that the check for this in view.lua contains: `pcall(vim.treesitter.get_parser, buf)` which when I run manually returns (true, nil, ) when a parser isn't installed:

Image

Steps To Reproduce

  1. The following code will recreate this error in the recreate instance:
vim.o.filetype = "text" -- Set explicitly or open a .txt or other file lacking a treesitter parser
-- Can call :TwilightEnable here to see error

Expected Behavior

I believe the default behavior when no treesitter parser is enabled for the filetype is the revert to the equivalent of treesitter=false in the setup() options.

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/twilight.nvim", opts = { treesitter = true } }, -- This should be default
  },
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions