nvim-neorg / neorg

Modernity meets insane extensibility. The future of organizing your life in Neovim.
GNU General Public License v3.0
6.47k stars 213 forks source link

[nvim nightly] `is_metadata_present` fails with `attempt to call method 'range' (a nil value)` #1579

Open mikesmithgh opened 1 month ago

mikesmithgh commented 1 month ago

Prerequisites

Neovim Version

NVIM v0.11.0-dev-754+ga30afeeb8

Neorg setup

return {
  {
    'nvim-neorg/neorg',
    enabled = true,
    lazy = false, -- Disable lazy loading as some `lazy.nvim` distributions set `lazy = true` by default
    version = '*', -- Pin Neorg to the latest stable release
    config = function()
      require('neorg').setup({
        load = {
          ['core.defaults'] = {}, -- Loads default behaviour
          ['core.dirman'] = { -- Manages Neorg workspaces
            config = {
              default_workspace = 'notes',
              workspaces = {
                notes = '~/neorg/notes',
              },
              index = 'index.norg', -- The name of the main (root) .norg file
              use_popup = true,
            },
          },
          ['core.summary'] = {},
          ['core.concealer'] = {
            -- config = {
            --   icons = {
            --     todo = {
            --       pending = {
            --         icon = 'y',
            --       },
            --     },
            --   },
            -- },
          }, -- Adds pretty icons to your documents
          ['core.itero'] = {}, -- <M-CR> to add header/list items
          ['core.promo'] = {}, -- promotes/demotes headers, etc
          ['core.qol.toc'] = {},
          ['core.qol.todo_items'] = {},
          ['core.export'] = {},
        },
      })
    end,
  },
}

Actual behavior

Saving a norg file results in the following error and norg metadata is not automatically updated (e.g, updated date)

Error detected while processing BufWritePre Autocommands for "*.norg":
Error executing lua callback: ...eorg/lua/neorg/modules/core/esupports/metagen/module.lua:227: attempt to call method 'range' (a nil value)
stack traceback:
    ...eorg/lua/neorg/modules/core/esupports/metagen/module.lua:227: in function 'is_metadata_present'
    ...eorg/lua/neorg/modules/core/esupports/metagen/module.lua:309: in function 'update_metadata'
    ...eorg/lua/neorg/modules/core/esupports/metagen/module.lua:424: in function <...eorg/lua/neorg/modules/core/esupports/metagen/module.lua:423>

Expected behavior

Saving a norg file has no errorr and norg metadata is automatically updated (e.g, updated date)

Steps to reproduce

Open a norg file and save the file (:w)

Example norg metadata:

@document.meta
title: Test
description: test
authors: mike
categories: [
  test1
  test2
]
created: 2024-08-01T10:22:27-0500
updated: 2024-09-03T10:23:24-0500
version: 1.1.1
@end

Potentially conflicting plugins

No response

Other information

I can't reproduce on latest stable version of nvim NVIM v0.10.1 OS: MacOS 14.6.1 (23G93)

Help

None

Implementation help

No response

mikesmithgh commented 1 month ago

I'm using neorg v9.1.1 and the error is occurring here

https://github.com/nvim-neorg/neorg/blob/v9.1.1/lua/neorg/modules/core/esupports/metagen/module.lua#L227

tokisuno commented 1 month ago

image I'm also having the same problem on nightly.

olimorris commented 1 month ago

This has caused a lot of plugin's to fail on nightly.

I resolved it in my plugin recently:

https://github.com/olimorris/codecompanion.nvim/issues/190

Required me to be specific with the tree-sitter range.

mikesmithgh commented 1 month ago

FYI for a workaround you can disable updating the date on save by setting update_date to false from https://github.com/nvim-neorg/neorg/wiki/Metagen#update_date

Here is my config

return {
  {
    'nvim-neorg/neorg',
    enabled = true,
    lazy = false, -- Disable lazy loading as some `lazy.nvim` distributions set `lazy = true` by default
    version = '*', -- Pin Neorg to the latest stable release
    config = function()
      require('neorg').setup({
        load = {
          ['core.defaults'] = {}, -- Loads default behaviour
          ['core.dirman'] = { -- Manages Neorg workspaces
            config = {
              default_workspace = 'notes',
              workspaces = {
                notes = '~/neorg/notes',
              },
              index = 'index.norg', -- The name of the main (root) .norg file
              use_popup = true,
            },
          },
          ['core.summary'] = {},
          ['core.concealer'] = {}, -- Adds pretty icons to your documents
          ['core.itero'] = {}, -- <M-CR> to add header/list items
          ['core.promo'] = {}, -- promotes/demotes headers, etc
          ['core.qol.toc'] = {},
          ['core.qol.todo_items'] = {},
          ['core.export'] = {},
          -- https://github.com/nvim-neorg/neorg/wiki/Metagen
          ['core.esupports.metagen'] = { config = { update_date = false } }, -- do not update date until https://github.com/nvim-neorg/neorg/issues/1579 fixed
        },
      })
    end,
  },
}
tokisuno commented 1 month ago

FYI for a workaround you can disable updating the date on save by setting update_date to false from https://github.com/nvim-neorg/neorg/wiki/Metagen#update_date

Here is my config

return {
  {
    'nvim-neorg/neorg',
    enabled = true,
    lazy = false, -- Disable lazy loading as some `lazy.nvim` distributions set `lazy = true` by default
    version = '*', -- Pin Neorg to the latest stable release
    config = function()
      require('neorg').setup({
        load = {
          ['core.defaults'] = {}, -- Loads default behaviour
          ['core.dirman'] = { -- Manages Neorg workspaces
            config = {
              default_workspace = 'notes',
              workspaces = {
                notes = '~/neorg/notes',
              },
              index = 'index.norg', -- The name of the main (root) .norg file
              use_popup = true,
            },
          },
          ['core.summary'] = {},
          ['core.concealer'] = {}, -- Adds pretty icons to your documents
          ['core.itero'] = {}, -- <M-CR> to add header/list items
          ['core.promo'] = {}, -- promotes/demotes headers, etc
          ['core.qol.toc'] = {},
          ['core.qol.todo_items'] = {},
          ['core.export'] = {},
          -- https://github.com/nvim-neorg/neorg/wiki/Metagen
          ['core.esupports.metagen'] = { config = { update_date = false } }, -- do not update date until https://github.com/nvim-neorg/neorg/issues/1579 fixed
        },
      })
    end,
  },
}

noted. thanks!