glacambre / firenvim

Embed Neovim in Chrome, Firefox & others.
GNU General Public License v3.0
4.71k stars 146 forks source link

Firenvim has started reporting "neovim is not responding" #1593

Open larsks opened 7 months ago

larsks commented 7 months ago

Firenvim was previously working, but now has started reporting "neovim is not responding". I've walked through the troubleshooting guide and I've gotten as far as "Make sure the browser extension can communicate with neovim". In the background page, I see:

_generated_background_page.html:1 Uncaught (in promise) Neovim is not responding.
Promise.then (async)
updateSettings @ background.ts:159
updateSettings @ background.ts:315
(anonymous) @ background.ts:326
onMessage @ browser-polyfill.js:1

When I load a new page in the browser and then run ps -fe |grep firenvim in a terminal, I see:

lars      146262  144605  0 11:51 ?        00:00:00 /usr/bin/nvim --headless --cmd let g:firenvim_config={'globalSettings':{},'localSettings':{'.*':{}}}|let g:firenvim_i=[]|let g:firenvim_o=[]|let g:Firenvim_oi={i,d,e->add(g:firenvim_i,d)}|let g:Firenvim_oo={t->[chansend(2,t)]+add(g:firenvim_o,t)}|let g:firenvim_c=stdioopen({'on_stdin':{i,d,e->g:Firenvim_oi(i,d,e)},'on_print':{t->g:Firenvim_oo(t)}}) --cmd let g:started_by_firenvim = v:true -c try|call firenvim#run()|catch /Unknown function/|call chansend(g:firenvim_c,["f\n\n\n"..json_encode({"messages":["Your plugin manager did not load the Firenvim plugin for neovim."],"version":"0.0.0"})])|call chansend(2,["Firenvim not in runtime path. &rtp="..&rtp])|qall!|catch|call chansend(g:firenvim_c,["l\n\n\n"..json_encode({"messages": ["Something went wrong when running firenvim. See troubleshooting guide."],"version":"0.0.0"})])|call chansend(2,[v:exception])|qall!|endtry

But that command exits after a few seconds. If I run strace -p <pid> -f on that process before it exits, I see this, which I hope is more useful to you than it is to me (I don't see any obvious errors).

My neovim configuration is currently https://github.com/LazyVim/starter, firenvim, and some lsp configuration installed with Mason.

glacambre commented 7 months ago

Hi, thank you for attempting to debug this yourself! The strace file is useful, we can see that Neovim managed to start and even load a bunch of plugins. We can also see that it writes some shada and properly closes the file descriptor, making me think that it's probably shutting down properly instead of crashing.

This is further confirmed by read(0, "", 65421 returning an empty string (meaning we go through this branch? https://github.com/glacambre/firenvim/blob/master/autoload/firenvim.vim#L171 ) and no write(1, or write(2, implying neovim exited without emitting messages.

I guess we'll need to check whether messages are properly sent to neovim by the browser. Could you edit the firenvim script (usually ~/.local/share/firenvim/firenvim) and prepend exec tee /tmp/stdin | to the line executing neovim as well as append 2>/tmp/stderr | tee /tmp/stdout at the end?

Then, attempting to run firenvim by clicking on a textarea a couple of times should create /tmp/stdin, /tmp/stdout and /tmp/stderr. Please upload them here :)

larsks commented 7 months ago

With those modifications, in /tmps/stderr we see a lua error:

Error detected while processing function <lambda>3[1]..OnStdin:
line   30:
E5108: Error executing lua [string "luaeval()"]:1: attempt to index a boolean value
stack traceback:
    [string "luaeval()"]:1: in main chunk
stack traceback:
    [string "luaeval()"]:1: in main chunk
    [string "luaeval()"]:1: in main chunk

That doesn't reproduce when running e.g. nvim --cmd 'let g:started_by_firenvim = v:true'.

/tmp/stdin contains:

o���{"newInstance":true,"password":"..."}

And /tmp/stdout is empty.


In case it's important, I'm using neovim 0.9.5.

glacambre commented 7 months ago

Thanks! Stdin looks as expected, but stderr does not. I don't understand where this "attempt to index a boolean value" comes from.

The stack trace being anonymous + the problem coming from luaeval mean that the problem has to be here: https://github.com/glacambre/firenvim/blob/master/autoload/firenvim.vim#L198-L200 . The only indexing happening there is require("firenvim").start_server, this must mean that somehow require("firenvim") is returning false.

This can be confirmed by making a dummy lua module that returns false instead of an object and then attempting to index it, which results in the exact same error message:

E5108: Error executing lua [string "luaeval()"]:1: attempt to index a boolean value                                                                                                                                 
stack traceback:                                                                                                                                                                                                    
        [string "luaeval()"]:1: in main chunk  

So this means that there is a problem with your plugin manager, it is not installing firenvim or loading it properly. I can't help you more than that without seeing your exact config.

larsks commented 7 months ago

Thanks, that was very helpful. I've identified the culprit, but I remain confused. First, the entire configuration is available here. There is a file lua/firenvim.lua that causes firenvim to crash simply by existing -- the crash happens even when the file is not required by anything.

Is this some sort of naming conflict?

larsks commented 7 months ago

Is this some sort of naming conflict?

Indeed, if I name it anything else, everything works as expected.

glacambre commented 7 months ago

There is a file lua/firenvim.lua that causes firenvim to crash simply by existing

Aha! I guess neovim sees it first in its runtime path and loads it instead of https://github.com/glacambre/firenvim/blob/master/lua/firenvim.lua . Have you been able to use your neovim config (with a file named firenvim.lua) on previous neovim versions? I wonder if the runtime path order changed.

larsks commented 7 months ago

Have you been able to use your neovim config (with a file named firenvim.lua) on previous neovim versions?

No, this was all part of ditching my old init.vim configuration and moving to a strictly lua-based config. I put all the firenvim config in lua/firenvim.lua so that I could simply require(firenvim), which seemed like an obvious name :).

glacambre commented 6 months ago

I think I might be able to at least improve error messages for this problem.