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

bug: Crash for large lua file (with lsp configed) #315

Closed
3 tasks done
mathjiajia opened this issue Jan 14, 2023 · 37 comments
Closed
3 tasks done

bug: Crash for large lua file (with lsp configed) #315

mathjiajia opened this issue Jan 14, 2023 · 37 comments
Labels
bug Something isn't working

Comments

@mathjiajia
Copy link

Did you check docs and existing issues?

  • I have read all the noice.nvim docs
  • I have searched the existing issues of noice.nvim
  • I have searched the exsiting issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.0-dev-2065ce877

Operating system/version

macOS 13.1

Describe the bug

When scrolling very fast in a larger lua file, nvim will crash.

Steps To Reproduce

  1. make sure lua-language-server is in the PATH;
  2. use this repro.lua, nvim -u repro.lua, to install the plugins;
  3. quit nvim;
  4. open a large file (200 loc, say), nvim -u repro.lua health.lua, where health.lua is the file in this repo, or you make replace it with a large lua file.
  5. scroll quickly.

Expected Behavior

as normal, no crash

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	-- add any other plugins here
	{
		"neovim/nvim-lspconfig",
		config = function()
			require("lspconfig").sumneko_lua.setup({})
		end,
	},
	{
		"folke/noice.nvim",
		dependencies = { "MunifTanjim/nui.nvim" },
		config = true,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@mathjiajia mathjiajia added the bug Something isn't working label Jan 14, 2023
@folke
Copy link
Owner

folke commented Jan 14, 2023

Does this happen with the latest noice version? I fixed something for nightly half an hour ago

@mathjiajia
Copy link
Author

Yes, even with the latest noice

@folke
Copy link
Owner

folke commented Jan 14, 2023

I can't reproduce this with the latest noice version and your repro. It does crash with the version before that.

Are you 100% sure you're testing this with the latest noice version?

Make sure to delete ./.repro to get the latets version

@mathjiajia
Copy link
Author

Make sure to delete ./.repro to get the latets version

Yeah, that is what I did.

The problem is still there, as shown by the recording:

Screen.Recording.2023-01-15.at.8.22.03.AM.mov

@folke
Copy link
Owner

folke commented Jan 15, 2023

You deleted the whole directory? Including the lazy-lock.json file?

Can you double-check by opening in with -u, run lazy and check the commit?

@mathjiajia
Copy link
Author

I can confirm that everything is updated.
The larger the lua file is, the easier to crash: scroll up and down very fast.

Screenshot 2023-01-15 at 3 59 55 PM

Screenshot 2023-01-15 at 4 02 04 PM

@folke
Copy link
Owner

folke commented Jan 15, 2023

To further debug this, you'll have to generate a stacktrace for Neovim.
Build it from source and then use coredumpctl -1 gdb

@mathjiajia
Copy link
Author

Sorry, is this tool available on macOS?
I didn't find it.

@folke
Copy link
Owner

folke commented Jan 15, 2023

Check the Neovim wiki on how you can generate a stack trace for macos

@mathjiajia
Copy link
Author

mathjiajia commented Jan 15, 2023

@folke
Copy link
Owner

folke commented Jan 16, 2023

That shows the default as it was before my changes.

The fix is here https://github.com/folke/noice.nvim/blob/main/lua/noice/ui/init.lua#L107

Can you post what that first ui is for you?

You are using TUI right?

@folke
Copy link
Owner

folke commented Jan 16, 2023

And do you have termguicolors set to true?

@mathjiajia
Copy link
Author

Can you post what that first ui is for you?

Sorry that I did not follow your point. Below is what I get by running lua vim.pretty_print(vim.api.nvim_list_uis()[1]):
Screenshot 2023-01-16 at 10 27 48 PM

You are using TUI right?

I am just using nvim in kitty.

@folke
Copy link
Owner

folke commented Jan 16, 2023

Does this happen with the latest nightly?

@mathjiajia
Copy link
Author

mathjiajia commented Jan 16, 2023

still occurs (with nightly nvim and latest plugins)

@al-ce
Copy link

al-ce commented Jan 17, 2023

Responding to your question in #298 about other Mac users.

NVIM v0.9.0-dev-1941+g20b7be2d1-dirty
macOs 12.5.1 Monterey

Can reproduce in:
Terminal (emulator): kitty or iTerm2 or macOs Terminal
shell: zsh or bash

I can reproduce this when scrolling with a mousewheel in large files. Scrolling very slowly does not cause the crash. Also occurs if I "scroll" fast by holding down Ctrl+D/U, but not instantly as it does with the mousewheel.

@folke
Copy link
Owner

folke commented Jan 17, 2023

@al-ce are you sure this is due to noice?

See also neovim/neovim#21815

@mathjiajia can you check if the issue persists without noice?

@al-ce
Copy link

al-ce commented Jan 17, 2023

I'm not sure what all I should test to rule everything out, but here's some situations I'm trying.

Using a minimal packer config, I can only reproduce the behavior if there's a Noice notification window displayed as I'm scrolling (e.g. :lua vim.notify("hi"), start scrolling). Otherwise, scrolling through a large file doesn't crash it.

Using the LazyVim starter config, with Noice disabled I seemingly can't reproduce the issue. With Noice enabled, it occurs whether there is a notification window displayed or not.

@mathjiajia
Copy link
Author

mathjiajia commented Jan 17, 2023

@mathjiajia can you check if the issue persists without noice?

For me, once remove either lspconfig or noice, then cannot reproduce the crash.

@folke
Copy link
Owner

folke commented Jan 18, 2023

Does it happen when you disable nvim-notify?

@folke
Copy link
Owner

folke commented Jan 18, 2023

What if you disable:

config.lsp.message.enabled = false

or

config.lsp.progress.enabled = false

@mathjiajia
Copy link
Author

mathjiajia commented Jan 18, 2023

Does it happen when you disable nvim-notify?

What if you disable:

config.lsp.message.enabled = false

or

config.lsp.progress.enabled = false

Still crash by doing those.
Note: crash only happens when lsp is NOT ready, e.g., when sumneko_lua is loading workspaces.

@folke
Copy link
Owner

folke commented Jan 18, 2023

I just tested on Macos and I still can't reproduce this...

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "rcarriga/nvim-notify",
  -- add any other plugins here
  {
    "neovim/nvim-lspconfig",
    dependencies = {
      { "williamboman/mason.nvim", config = true },
      { "williamboman/mason-lspconfig.nvim", opts = { ensure_installed = { "sumneko_lua" } } },
    },
    config = function()
      require("lspconfig").sumneko_lua.setup({})
    end,
  },
  {
    "folke/noice.nvim",
    -- dir = "~/projects/noice.nvim",
    dependencies = { "MunifTanjim/nui.nvim" },
    config = true,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

@folke
Copy link
Owner

folke commented Jan 18, 2023

Tested with neovim/runtime/lua/vim/lsp.lua file

@mathjiajia
Copy link
Author

Tested with neovim/runtime/lua/vim/lsp.lua file

scroll fast with trackpad?
(NOT Ctrl-F or something like this)

@folke
Copy link
Owner

folke commented Jan 18, 2023

Can you try running the test in empty directory? At least a directory without a luarc.json file?

@mathjiajia
Copy link
Author

Can you try running the test in empty directory? At least a directory without a luarc.json file?

You caught the point. No crash this time.

@folke
Copy link
Owner

folke commented Jan 18, 2023

ok, great. Can you show the contents of that file?

@folke
Copy link
Owner

folke commented Jan 18, 2023

I can actually reproduce it now. Even in an empty directory

@mathjiajia
Copy link
Author

mathjiajia commented Jan 18, 2023

ok, great. Can you show the contents of that file?

{
    "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
    "Lua.workspace.checkThirdParty": false
}

I can reproduce with my own config (not repro.lua) even without luarc.json file
will try to find another minimal repro.lua.

PS: below seems very important, which explains why it crashes for larger files.

Note: crash only happens when lsp is NOT ready, e.g., when sumneko_lua is loading workspaces.

@folke
Copy link
Owner

folke commented Jan 18, 2023

At least, I can already confirm this issue is not caused by vim.ui_attach. Looking into it further

@folke
Copy link
Owner

folke commented Jan 18, 2023

When I set noice config.lsp.progress.enabled = false, then I no longer have crashes. Can you doublecheck that?

Also set config.lsp.message.enabled = false

@fibbo
Copy link

fibbo commented Jan 18, 2023

I'm pretty sure it's not related to noice. I reported a similar bug here: nvim-telescope/telescope.nvim#2331 and I start to believe it's not a telescope issue either but it allows me to trigger it. The assertions that are triggered in a debug build were:

rbuffer.c:144 and rbuffer.c:168 but I'm not sure what's causing them.

@mathjiajia
Copy link
Author

When I set noice config.lsp.progress.enabled = false, then I no longer have crashes. Can you doublecheck that?

Also set config.lsp.message.enabled = false

So wired. Still crash in a new directory with only two files: repro.lua and the neovim/runtime/lua/vim/lsp.lua file.

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	-- add any other plugins here
	{
		"neovim/nvim-lspconfig",
		config = function()
			require("lspconfig").sumneko_lua.setup({})
		end,
	},
	{
		"folke/noice.nvim",
		dependencies = { "MunifTanjim/nui.nvim" },
		opts = {
			lsp = {
				progress = { enabled = false },
				message = { enabled = false },
			},
		},
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

@folke
Copy link
Owner

folke commented Jan 18, 2023

I think @fibbo is right. There's a couple of other bug reports in Neovim with the same issue, but without Noice.

And I can confirm that the issue on macos is not caused by that bug in vim.ui_attach for which I created the work-around.

@folke
Copy link
Owner

folke commented Feb 2, 2023

Multiple fixes have bee made upstream. Would be great if you could test again on the latest nightly

@mathjiajia
Copy link
Author

Thanks.
No crash anymore.
IMO, this issue has been resolved.

@folke folke closed this as completed Feb 2, 2023
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

4 participants