nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.

Home Page:https://nvim-orgmode.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Neovim freezes when adding headings to large org files

oncomouse opened this issue · comments

Describe the bug

My main org file is 1026 lines (currently) and 11297 words. I noticed that when attempting to add third level headings on a particular task Neovim would completely freeze (it won't accept any terminal input; had to kill the process). Experimenting further with the file, I discovered that if I wait long enough, I get a message about redrawtime being exceeded (I don't have the specific error at hand, sorry). Further typing around the asterisk will produce another freeze.

Steps to reproduce

  1. Open this anonymized version of my todo.org file
  2. The problem specifically occurred at line 520, so 520G
  3. Insert a new line with o
  4. Type an asterisk

Expected behavior

Neovim shouldn't freeze when adding headlines.

Emacs functionality

No response

Minimal init.lua

-- Set Leader:
vim.g.mapleader = " "
local nvim_root = '/tmp/nvim_orgmode'
local lazy_root = nvim_root .. '/lazy'
local lazypath = lazy_root .. '/lazy.nvim'
if not vim.loop.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({
  root = lazy_root,
  lockfile = nvim_root .. '/lazy.json',
  spec = {
    {
      "nvim-orgmode/orgmode",
      config = function(_, opts)
        require("orgmode").setup_ts_grammar()
        require("nvim-treesitter.configs").setup({
          highlight = {
            enable = true,
            additional_vim_regex_highlighting = { "org" },
          },
          ensure_installed = { "org" },
        })
        require("orgmode").setup(opts)
      end,
      dependencies = {
        {
          "nvim-treesitter/nvim-treesitter",
        },
      },
    },
  },
})
-- # vim:ts=2:sw=2:sts=2:expandtab

Screenshots and recordings

No response

OS / Distro

Arch linux

Neovim version/commit

NVIM v0.10.0-dev-684e930

Additional context

Another thing to note, I tried this project's minimal_init.lua file. Doing so doesn't produce the error, but when I use that file (nvim -u ./minimal_init.lua todo.org), folding is disabled because foldexpr is set to 0 and none of the maps I would expect in orgmode appear to be working (I tried >> on a headline and C-<space on a checkbox, neither work). In the minimal init I supplied, foldexpr is set to nvim_treesitter#foldexpr() as one would expect.

This makes me think there's something going on with treesitter's fold function, but I'm not sure if that's the case or even how to debug it. I've tried disabling foldexpr with my minimal init file, and the problem persists.

Hi,

The problem appears because adding a * at that line actually switches ~500 lines to a drawer because some of the lines above and below are not properly parsed. That switch re-parses all the markup again and that causes the freeze.

Thanks for reporting. I'll let you know once this is fixed.

This issue should be fixed now. Just pull the latest master and do :TSUpdate org to fetch the latest tree-sitter grammar.