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

fix: explicitly pass treesitter language to get_node() #795

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

troiganto
Copy link
Contributor

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().

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()`.
Copy link
Member

@kristijanhusak kristijanhusak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
I'll merge it in and extract it to own helper so we are sure we always get the node with proper language.

Thanks!

@kristijanhusak kristijanhusak merged commit 56c8246 into nvim-orgmode:master Aug 15, 2024
6 checks passed
@troiganto troiganto deleted the explicit-lang-org branch August 15, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'org-roam-node-buffer' is not a valid language name
2 participants