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

Treesitter Initialisation Condition on Save #108

Open
oddish3 opened this issue Feb 27, 2025 · 2 comments
Open

Treesitter Initialisation Condition on Save #108

oddish3 opened this issue Feb 27, 2025 · 2 comments

Comments

@oddish3
Copy link

oddish3 commented Feb 27, 2025

When using Zotcite with Treesitter, I encountered an issue where the plugin fails to initialise properly if it's set up to load before Treesitter. Specifically, the error message "is treesitter enabled?" appears after saving a file, suggesting that Treesitter isn't fully initialised when Zotcite tries to use it.

Steps to reproduce:

  • Set up Zotcite with Treesitter as a dependency in lazy.nvim.
  • Save a file with Zotcite enabled.
  • The error message "is treesitter enabled?" appears.

What I tried:

  • After checking :checkhealth nvim-treesitter, Treesitter appears to be properly installed and up to date.
    I added vim.defer_fn to delay Zotcite's setup, which resolved the issue:
{
  "jalvesaq/zotcite",
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
    "nvim-telescope/telescope.nvim",
  },
  lazy = false,
  config = function()
    vim.defer_fn(function()
      require("zotcite").setup({})
    end, 100) -- Delay setup slightly
  end,
}

Expected behavior:

Zotcite should properly initialize only after Treesitter has been fully loaded, without the need for manual delay.

Proposed solution:

It seems Zotcite tries to use Treesitter functions before Treesitter is fully initialized. I suggest adding a check to ensure that Treesitter is ready before proceeding with any Treesitter-dependent functionality, or deferring the setup until Treesitter is available.

@jalvesaq
Copy link
Owner

Thanks for reporting the bug! How can we know that treesitter is not ready yet? The command that uses treesitter is already scheduled to run when Neovim is idle (lua/zotcite/config.lua, line 252):

        vim.schedule(function() require("zotcite.get").collection_name(bn) end)

@oddish3
Copy link
Author

oddish3 commented Feb 27, 2025

My apologies, I think the actual issue is somewhere inbetween treesitter.nvim, obsidian.nvim and zotcite.nvim
Since (independently) disabling both obsidian and zotcite stops the issue happening.
And, it only seems to happen when navigating from a file explorer within nvim as opposed to opening the file directly

I'll have a look at this and try to produce a MWE, but my nvim config is here: nvim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants