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

Error (freezes nvim) when opening file with code block name in different case (e.g. "Python", "JSON", "R"): no such language: R #727

Closed
milanglacier opened this issue May 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@milanglacier
Copy link
Contributor

Describe the bug

This is a macOS only bug, I cannot reproduce it in linux.

When opening a markdown file that contains code block with same name with the treesitter parser but have different case (e.g. python vs Python, r vs R, Json vs json), you will get the following error:

stack traceback:
        [C]: in function '_ts_parse_query'
        ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'fn'
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'get'
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:128: in function 'new'
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:511: in function 'add_child'
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:395: in function '_add_injections'
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:447: in function 'parse'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:397: in function <....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:392>
Error in decoration provider treesitter/highlighter.win:
Error executing lua: ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: no such language: R

This error is actually the same error as in nvim-treesitter: nvim-treesitter/nvim-treesitter#6642

Steps to reproduce

  1. open the following example org mode file, say : hello.org

  2. Open it in neovim, get billions of errors so that you can't do anything with neovim.

https://pastebin.com/sSLFxXBZ

Expected behavior

  1. nvim should open this file normally.

Emacs functionality

No response

Minimal init.lua

local plugins = {
	orgmode = "https://github.com/nvim-orgmode/orgmode",
	ts = "https://github.com/nvim-treesitter/nvim-treesitter",
}

for name, url in pairs(plugins) do
	local install_path = "/tmp/nvim/site/" .. name
	if vim.fn.isdirectory(install_path) == 0 then
		vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
	end
	vim.o.runtimepath = install_path .. "," .. vim.o.runtimepath
end

require("nvim-treesitter.configs").setup({
	-- One of "all", "maintained" (parsers with maintainers), or a list of languages
	ensure_installed = {
		"r",
	},
	sync_install = true,
	highlight = {
		enable = true,
	},
})
require("orgmode").setup()


Screenshots and recordings

Screenshot 2024-05-16 at 21 30 08

OS / Distro

macos 13.4

Neovim version/commit

0.10

Additional context

R and r are both considered as "Canonical" name for R language, so you would expect to see different authors use R and r interchangably from different sources. While treesitter uses r as its name, the orgmode should handles language name R robustly.

@milanglacier milanglacier added the bug Something isn't working label May 17, 2024
@milanglacier milanglacier changed the title Error (freezes nvim) when opening markdown with code block name in different case (e.g. "Python", "JSON", "R"): no such language: R Error (freezes nvim) when opening markdown with code block name in different case (e.g. "Python", "JSON", "R"): no such language: R May 17, 2024
@milanglacier
Copy link
Contributor Author

Apply the following patch solves the problem for me.

According to this commit, neovim/neovim#28546, treesitter requires the parser name should be always lower case, so we can safely convert the text to lower case.

diff --git a/lua/orgmode/config/init.lua b/lua/orgmode/config/init.lua
index a9db1bf..75e7ca7 100644
--- a/lua/orgmode/config/init.lua
+++ b/lua/orgmode/config/init.lua
@@ -397,7 +397,7 @@ function Config:setup_ts_predicates()
     if not text or vim.trim(text) == '' then
       return
     end
-    metadata['injection.language'] = utils.detect_filetype(text) or text
+    metadata['injection.language'] = utils.detect_filetype(text) or text:lower()
   end, { force = true })
 end

@milanglacier milanglacier changed the title Error (freezes nvim) when opening markdown with code block name in different case (e.g. "Python", "JSON", "R"): no such language: R Error (freezes nvim) when opening file with code block name in different case (e.g. "Python", "JSON", "R"): no such language: R May 17, 2024
SlayerOfTheBad pushed a commit to SlayerOfTheBad/orgmode that referenced this issue Aug 16, 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
Projects
None yet
Development

No branches or pull requests

1 participant