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

Lua-original used for code containing vim #297

Open
sharpchen opened this issue Sep 26, 2024 · 1 comment
Open

Lua-original used for code containing vim #297

sharpchen opened this issue Sep 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@sharpchen
Copy link

sharpchen commented Sep 26, 2024

Describe the bug
Same as title

To Reproduce

  • copy this code sample:
---@generic TResult
---@return TResult[]
---@param iterator fun(self: any? ): fun(): TResult
---@param source any?
local function collect(iterator, source)
	local ret = {}
	for element in iterator(source) do
		table.insert(ret, element)
	end
	return ret
end
---collect all children of a node recursively
---it's a bad practice, but I just leave it here for now. may be fix it in the future...
---@param node TSNode
---@return TSNode[]
local function collect_node_rec(node)
	local current_level = collect(node.iter_children, node)
	local ret = {}
	for _, child in ipairs(current_level) do
		if child:child_count() > 0 then
			ret = vim.tbl_extend("error", ret, collect_node_rec(child))
		end
		table.insert(ret, child)
	end
	return ret
end

local foo = vim.treesitter.get_string_parser("var foo = string.Empty;", "c_sharp"):parse(true)[1]:root()
vim.print(#collect_node_rec(foo)) -- <-- error here
  • select all, then run it with sniprun.
  • error occurs.
  • however a simple snip like vim.print('foo') just works.

Screenshots
image

Environment:

  • NVIM v0.10.1
  • ArchWSL
{
  machine = "x86_64",
  release = "5.15.153.1-microsoft-standard-WSL2",
  sysname = "Linux",
  version = "#1 SMP Fri Mar 29 23:14:13 UTC 2024"
}
@sharpchen sharpchen added the bug Something isn't working label Sep 26, 2024
@michaelb
Copy link
Owner

Hmm yeah, the tomfoolery between Lua_original and Lua_nvim was originally intended to prevent unexpected failures for small snippets (trying vim.print, and trying native lua code that could behave differently in nvim).

The cause of the issue here is probably that the snippet produced an error also in the Lua_nvim interpreter, which disqualified it as a fallback, and returned the original error instead.

The solution for you is probably to add "Lua_nvim" to your configuration (the selected_interpreters key), to force the use of Lua_nvim for every lua snippet

The solution for me is to communicate more effectively what happened when such fallbacks occur, especially when they're not successfull.

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

2 participants