chipsenkbeil / org-roam.nvim

Port of org-roam to neovim using orgmode
MIT License
125 stars 11 forks source link

'org-roam-node-buffer' is not a valid language name #49

Closed chipsenkbeil closed 3 months ago

chipsenkbeil commented 5 months ago

Encountered in neovim 0.10 when attempting to expand a backlink. Must be something I missed when adding support for neovim 0.10. I'm assuming they changed how creating a parser works. I'm assuming that I'm setting the filetype to this somewhere, and neovim is trying to do virtual identation, a feature new to neovim 0.10 that I have enabled. Not sure why it's happening for a non-org buffer, though.

Error executing vim.schedule lua callback: ....10.0/share/nvim/runtime/lua/vim/treesitter/language.lua:101: 'org-r
oam-node-buffer' is not a valid language name
stack traceback:
        [C]: in function 'error'
        ....10.0/share/nvim/runtime/lua/vim/treesitter/language.lua:101: in function 'add'
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:111: in function 'new'
        .../neovim/0.10.0/share/nvim/runtime/lua/vim/treesitter.lua:41: in function '_create_parser'
        .../neovim/0.10.0/share/nvim/runtime/lua/vim/treesitter.lua:108: in function 'get_parser'
        .../neovim/0.10.0/share/nvim/runtime/lua/vim/treesitter.lua:386: in function 'get_node_at_cursor'
        .../nvim/lazy/orgmode/lua/orgmode/utils/treesitter/init.lua:51: in function 'closest_headline_node'
        ...hare/nvim/lazy/orgmode/lua/orgmode/ui/virtual_indent.lua:86: in function 'set_indent'
        ...hare/nvim/lazy/orgmode/lua/orgmode/ui/virtual_indent.lua:154: in function <...hare/nvim/lazy/orgmode/lu
a/orgmode/ui/virtual_indent.lua:153>
troiganto commented 3 months ago

The problem seems to be this line: https://github.com/nvim-orgmode/orgmode/blob/e365b85b4a5bfea507d77a16a7b66d8c6860e9b7/lua/orgmode/utils/treesitter/init.lua#L21:

function M.get_node_at_cursor(cursor)
  M.parse_current_file()
  if not cursor then
    return vim.treesitter.get_node()
  end

  return vim.treesitter.get_node({
    bufnr = 0,
    pos = { cursor[1] - 1, cursor[2] },
  })
end

where orgmode calls vim.treesitter.get_node() twice without specifying the language. The behavior of get_node() in that case is to deduce the language from the filetype. For that it checks the table filled via vim.treesitter.language.register().

The way I see it, there are two ways to fix this:

  1. in orgmode proper, we pass the language explicitly where it makes sense, eg: get_node({lang = 'org'})
  2. in org-roam, we register our custom filetypes with the org language: vim.treesitter.language.register('org', {'org-roam-node-buffer'})

Personally, I think the first option makes more sense. I've submitted https://github.com/nvim-orgmode/orgmode/pull/795 so if and when that PR is accepted, this should work without updates to org-roam itself.

troiganto commented 3 months ago

The fix just got merged, so the error should no longer appear after an update!

chipsenkbeil commented 3 months ago

Can confirm that as of https://github.com/nvim-orgmode/orgmode/commit/56c8246c633bcde845cefc2090979ec23bd9034e, this has been fixed. Thanks @troiganto for getting this resolved upstream!