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

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

Closed
chipsenkbeil opened this issue Jun 10, 2024 · 3 comments · Fixed by nvim-orgmode/orgmode#795
Closed

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

chipsenkbeil opened this issue Jun 10, 2024 · 3 comments · Fixed by nvim-orgmode/orgmode#795
Labels
bug Something isn't working nvim-orgmode Issue is related to the nvim-orgmode plugin

Comments

@chipsenkbeil
Copy link
Owner

chipsenkbeil commented Jun 10, 2024

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>
@chipsenkbeil chipsenkbeil added the bug Something isn't working label Jun 10, 2024
troiganto pushed a commit to troiganto/orgmode that referenced this issue Aug 15, 2024
Fixes chipsenkbeil/org-roam.nvim#49

Org-roam offers a "node buffer", a sidebar that shows information such
as backlinks from other locations to the current headline/file. The node
buffer allows previewing the location of such a backlink. This inserts
orgmode syntax into a buffer with filetype `org-roam-node-buffer`.

If virtual indent is enabled, it'll attempt to deduce the virtual indent
of the preview. This in turn calls `closest_headline_node()`, which in
turn calls `get_node_at_cursor`, which in turn calls
`vim.treesitter.get_node()`.

If `get_node()` is called without an explicit treesitter language, it'll
attempt to deduce that language from the filetype. The filetype
`org-roam-node-buffer` isn't associated with the `org` language (and
I don't think it *should*), so this call fails.

This fixes the issue by explicitly passing `{ lang = 'org' }` in all
instances where the language *may* be deduced. I think this is
acceptable because if someone calls
`orgmode.utils.treesitter.get_node()` AFAIK is only ever called on text
that is org syntax.

While making this change, I grepped for other treesitter calls with an
optional language argument. Where I found them, I passed it explicitly
as well. AFAICT, this is only `Stars:on_line()` and
`ts_utils.restart_highlighting()`.
troiganto pushed a commit to troiganto/orgmode that referenced this issue Aug 15, 2024
Fixes chipsenkbeil/org-roam.nvim#49

Org-roam offers a "node buffer", a sidebar that shows information such
as backlinks from other locations to the current headline/file. The node
buffer allows previewing the location of such a backlink. This inserts
orgmode syntax into a buffer with filetype `org-roam-node-buffer`.

If virtual indent is enabled, it'll attempt to deduce the virtual indent
of the preview. This in turn calls `closest_headline_node()`, which in
turn calls `get_node_at_cursor`, which in turn calls
`vim.treesitter.get_node()`.

If `get_node()` is called without an explicit treesitter language, it'll
attempt to deduce that language from the filetype. The filetype
`org-roam-node-buffer` isn't associated with the `org` language (and
I don't think it *should*), so this call fails.

This fixes the issue by explicitly passing `{ lang = 'org' }` in all
instances where the language *may* be deduced. I think this is
acceptable because if someone calls
`orgmode.utils.treesitter.get_node()` AFAIK is only ever called on text
that is org syntax.

While making this change, I grepped for other treesitter calls with an
optional language argument. Where I found them, I passed it explicitly
as well. AFAICT, this is only `Stars:on_line()` and
`ts_utils.restart_highlighting()`.
@troiganto
Copy link
Contributor

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 nvim-orgmode/orgmode#795 so if and when that PR is accepted, this should work without updates to org-roam itself.

troiganto pushed a commit to troiganto/orgmode that referenced this issue Aug 15, 2024
Fixes chipsenkbeil/org-roam.nvim#49

Org-roam offers a "node buffer", a sidebar that shows information such
as backlinks from other locations to the current headline/file. The node
buffer allows previewing the location of such a backlink. This inserts
orgmode syntax into a buffer with filetype `org-roam-node-buffer`.

If virtual indent is enabled, it'll attempt to deduce the virtual indent
of the preview. This in turn calls `closest_headline_node()`, which in
turn calls `get_node_at_cursor`, which in turn calls
`vim.treesitter.get_node()`.

If `get_node()` is called without an explicit treesitter language, it'll
attempt to deduce that language from the filetype. The filetype
`org-roam-node-buffer` isn't associated with the `org` language (and
I don't think it *should*), so this call fails.

This fixes the issue by explicitly passing `{ lang = 'org' }` in all
instances where the language *may* be deduced. I think this is
acceptable because if someone calls
`orgmode.utils.treesitter.get_node()` AFAIK is only ever called on text
that is org syntax.

While making this change, I grepped for other treesitter calls with an
optional language argument. Where I found them, I passed it explicitly
as well. AFAICT, this is only `Stars:on_line()` and
`ts_utils.restart_highlighting()`.
kristijanhusak pushed a commit to nvim-orgmode/orgmode that referenced this issue Aug 15, 2024
Fixes chipsenkbeil/org-roam.nvim#49

Org-roam offers a "node buffer", a sidebar that shows information such
as backlinks from other locations to the current headline/file. The node
buffer allows previewing the location of such a backlink. This inserts
orgmode syntax into a buffer with filetype `org-roam-node-buffer`.

If virtual indent is enabled, it'll attempt to deduce the virtual indent
of the preview. This in turn calls `closest_headline_node()`, which in
turn calls `get_node_at_cursor`, which in turn calls
`vim.treesitter.get_node()`.

If `get_node()` is called without an explicit treesitter language, it'll
attempt to deduce that language from the filetype. The filetype
`org-roam-node-buffer` isn't associated with the `org` language (and
I don't think it *should*), so this call fails.

This fixes the issue by explicitly passing `{ lang = 'org' }` in all
instances where the language *may* be deduced. I think this is
acceptable because if someone calls
`orgmode.utils.treesitter.get_node()` AFAIK is only ever called on text
that is org syntax.

While making this change, I grepped for other treesitter calls with an
optional language argument. Where I found them, I passed it explicitly
as well. AFAICT, this is only `Stars:on_line()` and
`ts_utils.restart_highlighting()`.

Co-authored-by: troiganto <troiganto@proton.me>
@troiganto
Copy link
Contributor

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

@chipsenkbeil
Copy link
Owner Author

Can confirm that as of nvim-orgmode/orgmode@56c8246, this has been fixed. Thanks @troiganto for getting this resolved upstream!

@chipsenkbeil chipsenkbeil added the nvim-orgmode Issue is related to the nvim-orgmode plugin label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working nvim-orgmode Issue is related to the nvim-orgmode plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants