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

TelescopePreviewerLoaded Error executing vim.schedule lua callback #12

Open
YodaEmbedding opened this issue Feb 6, 2024 · 3 comments · May be fixed by #3 or #19
Open

TelescopePreviewerLoaded Error executing vim.schedule lua callback #12

YodaEmbedding opened this issue Feb 6, 2024 · 3 comments · May be fixed by #3 or #19

Comments

@YodaEmbedding
Copy link

When actions-preview.nvim is installed and the user calls require("actions-preview").code_actions(), it triggers TelescopePreviewerLoaded autocmd, but with a nil args.data.bufname. This causes an error when args.data.bufname is parsed.

Error message:

Error executing vim.schedule lua callback: ...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:460: User Autocommands for "TelescopePreviewerLoaded": Vim(append):Error executing lua callback: .../share/nvim/lazy/ltex-utils.nvim/lua/ltex-utils/init.lua:66: attempt to index field 'bufname' (a nil value)
stack traceback:
        .../share/nvim/lazy/ltex-utils.nvim/lua/ltex-utils/init.lua:66: in function <.../share/nvim/lazy/ltex-utils.nvim/lua/ltex-utils/init.lua:64>
        [C]: in function 'nvim_exec_autocmds'
        ...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:461: in function <...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:460>
        [C]: in function 'nvim_buf_call'
        ...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:460: in function <...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:454>

Fixed in PR #3.

@tbdcit
Copy link

tbdcit commented Feb 21, 2024

I am having the same issue. The pull request supplied didn't quite fix the issue either. So far what seems to be working for me is

 	vim.api.nvim_create_autocmd("User", {
 		pattern = "TelescopePreviewerLoaded",
 		callback = function(args)
 			---@type string
+			if args.data == nil then
+				return
+			end
 			local extension = args.data.bufname:match("%.(%w+)$")
 			if extension == "md" or extension == "tex" then
 				vim.wo.number = Config.rule_ui.previewer_line_number
 				vim.wo.wrap = Config.rule_ui.previewer_wrap
 			end
 		end,
 	})

@YodaEmbedding
Copy link
Author

YodaEmbedding commented Feb 21, 2024

In that case, we probably should do:

if args.data == nil or args.data.bufname == nil then
	return
end

@GeorgeFlerovsky
Copy link

This PR also adds a check for args.data being nil:

#19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants