orgmode icon indicating copy to clipboard operation
orgmode copied to clipboard

0.11.1 cause no treesitter, if set `lazy = true`

Open cxwx opened this issue 7 months ago • 8 comments

Describe the bug

19:40:57 msg_show Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: ...rew/Cellar/neovim/0.11.1/share/nvim/runtime/filetype.lua:36: BufReadPost Autocommands for "*"..FileType Autocommands for "org": Vim(append):Error executing vim.schedule lua callback: ...m/0.11.1/share/nvim/runtime/lua/vim/treesitter/query.lua:906: No handler for org-set-fold-offset!
stack traceback:
	[C]: in function 'error'
	...m/0.11.1/share/nvim/runtime/lua/vim/treesitter/query.lua:906: in function '_apply_directives'
	...m/0.11.1/share/nvim/runtime/lua/vim/treesitter/query.lua:1106: in function '(for generator)'
	...m/0.11.1/share/nvim/runtime/lua/vim/treesitter/_fold.lua:108: in function 'fn'
	...1/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:650: in function 'for_each_tree'
	...m/0.11.1/share/nvim/runtime/lua/vim/treesitter/_fold.lua:100: in function 'cb'
	...1/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:478: in function '_run_async_callbacks'
	...1/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:534: in function <...1/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:513>
	[C]: in function 'wait'
	.../nvim/lazy/plugins/orgmode/lua/orgmode/utils/promise.lua:279: in function 'wait'
	...plugins/orgmode/lua/orgmode/utils/treesitter/install.lua:125: in function 'get_installed_version'
	...
	...xu/software/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:395: in function 'config'
	...xu/software/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:362: in function '_load'
	...xu/software/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:197: in function 'load'
	...ware/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:85: in function <...ware/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:72>
	[C]: in function 'nvim_cmd'
	...rew/Cellar/neovim/0.11.1/share/nvim/runtime/filetype.lua:36: in function <...rew/Cellar/neovim/0.11.1/share/nvim/runtime/filetype.lua:35>
	[C]: in function 'pcall'
	vim/shared.lua: in function <vim/shared.lua:0>
	[C]: in function '_with'
	...rew/Cellar/neovim/0.11.1/share/nvim/runtime/filetype.lua:35: in function <...rew/Cellar/neovim/0.11.1/share/nvim/runtime/filetype.lua:10>
stack traceback:
	[C]: in function '_with'
	...rew/Cellar/neovim/0.11.1/share/nvim/runtime/filetype.lua:35: in function <...rew/Cellar/neovim/0.11.1/share/nvim/runtime/filetype.lua:10>

Steps to reproduce

upgrade 0.11.1 nvim open a org file with fold

  • a ** aa
  • [ ] a
  • [ ] a

Expected behavior

bug fix

Emacs functionality

No response

Minimal init.lua

unknown

Screenshots and recordings

No response

nvim-orgmode version

lastest

OS / Distro

macos 15.4.1

Neovim version/commit

0.11.1

Additional context

No response

cxwx avatar May 05 '25 11:05 cxwx

https://github.com/nvim-treesitter/nvim-treesitter/pull/7634

treesitter drop support for org filetype

cxwx avatar May 05 '25 11:05 cxwx

nvim-orgmode does not have a dependency on nvim-treesitter. If you previously installed the parser using nvim-treesitter, remove it from the nvim-treesitter/parser folder, and restart Neovim. Orgmode should automatically install the parser.

kristijanhusak avatar May 05 '25 11:05 kristijanhusak

nvim-treesitter/parser

old version org.so removed.

and the .m/0.11.1/share/nvim/runtime/lua/vim/treesitter/query.lua:906: No handler for org-set-fold-offset! problem is still there

  1. the problem seem to be the fold method using treesitter,
  2. If I remove the orgmode.nvim plugin, the error disappeared

cxwx avatar May 05 '25 13:05 cxwx

The Problem may be cause by the order of some plugins

OK if lazy = false, event = "VeryLazy"

  {
    "nvim-orgmode/orgmode",
    event = "VeryLazy",
    lazy = false,
    opts = {
      org_agenda_files = { "~/org/*", "~/orgs/**/*" },
      org_default_notes_file = "~/org/note.org",
    },
  },

errors when lazy = true, ft = "org"

  {
    "nvim-orgmode/orgmode",
   ft = "org",
    lazy = true,
    opts = {
      org_agenda_files = { "~/org/*", "~/orgs/**/*" },
      org_default_notes_file = "~/org/note.org",
    },
  },

I think the errors is cause

treesitter foldmethod loaded -> filetype detected -> orgmode fold (here)

but if lazy = false

orgmode fold worked

cxwx avatar May 05 '25 14:05 cxwx

I can't reproduce it. Does this minimal init work for you ?

--- save this file as minimal_init.lua
--- Run as `nvim -u minimal_init.lua

local tmp_dir = vim.env.TMPDIR or vim.env.TMP or vim.env.TEMP or '/tmp'
local nvim_root = tmp_dir .. '/nvim_orgmode'
local lazy_root = nvim_root .. '/lazy'
local lazypath = lazy_root .. '/lazy.nvim'

for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = nvim_root .. '/' .. name
end

-- Install lazy.nvim if not already installed
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable', -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
  {
    'nvim-orgmode/orgmode',
    lazy = true,
    ft = 'org',
    opts = {
      org_agenda_files = { '~/org/*', '~/orgs/**/*' },
      org_default_notes_file = '~/org/note.org',
    },
  },
}, {
  root = lazy_root,
  lockfile = nvim_root .. '/lazy.json',
  install = {
    missing = false,
  },
})

require('lazy').sync({
  wait = true,
  show = false,
})

kristijanhusak avatar May 05 '25 15:05 kristijanhusak

I've also set

      vim.wo.foldmethod = 'expr'
      vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'

and nvim v0.11 remove org https://github.com/emiasims/tree-sitter-org it cause this bug.

cxwx avatar May 18 '25 00:05 cxwx

You mean you used nvim_treesitter#foldexpr() ?

kristijanhusak avatar May 18 '25 11:05 kristijanhusak

I'm also using nvim-orgmode on Neovim 0.11, but have switched to nvim-treesitter's new main branch, which allows users to freely define when to set foldmethod, indentexpr and enable tree-sitter highlighting. Things work fine for me.

My setup is as below:

-- Need to be lazy-loaded on both VeryLazy and ft.
-- ft="org" is required when an org file is opened on start (.e.g nvim notes.org)
{
    "nvim-orgmode/orgmode",
    event = "VeryLazy",
    ft = "org",
    lazy = true,
    opts = {},
},

And for nvim-treesitter, I enable its features on FileType event:

vim.api.nvim_create_autocmd("FileType", {
    callback = function(args)
        local lang = vim.treesitter.language.get_lang(vim.bo[args.buf].filetype)
        if lang and lang ~= "org" then
            vim.treesitter.start(args.buf, lang)
            vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
            ...
        end
    end,
})

folliehiyuki avatar May 21 '25 07:05 folliehiyuki

I believe I also had this issue, and it was caused by an existing treesitter parser for *.org. I was able to resolve it by running rm ~/.local/share/nvim/lazy/nvim-treesitter/parser/org.so and re-installing nvim-orgmode. I did also include the ignore_install = {'org'} when configuring the plugin.

jonjnicholson avatar Jul 03 '25 14:07 jonjnicholson

Closing this for now. If the problem persists, please open up a separate issue.

kristijanhusak avatar Sep 08 '25 12:09 kristijanhusak