Subject: Re: bug#62116: RFE: eglot: support window.showDocument LSP RPC

From: Alan Donovan <[email-masked]>
Date: Fri, 5 May 2023 13:06:58 -0400

On Fri, 5 May 2023 at 12:48, João Távora <[email-masked]> wrote:
> Also, can you comment on why you think Alan Donovan's patch has that
> non-synchronous find-file mechanism?  Since Alan, doesn't reply, what do
> you conjecture is the reason his patch goes through this trouble?

Hi Joao, sorry for the long radio silence. I've been meaning to return
to this but we're in a release crunch lately.

The reason for the async approach is to avoid nested RPCs between the
client and gopls (Go LSP) server. The server is effectively
single-threaded (the underlying JSON RPC implementation is full duplex
but gopls' handlers use a lock), so if a server RPC initiates a
showDocument downcall, which causes the client to open a file, then
the find-file hooks for that file will make another RPC to the server,
which causes it to get stuck. Arguably this is a problem in the design
of gopls, but I doubt it is easy to fix, and I wonder how many other
LSP servers have ended up taking the same approach. An alternative
solution would be for gopls never to make a synchronous showDocument
downcall, but instead to fire it off in another thread.

> 1. if you think the Emacs frame should be raised and/or focused when a window.showDocument comes in.

I think this is appropriate, since there's otherwise a good chance
that nothing would appear to happen in response to (e.g.) a click. But
perhaps we can play with it and get some experience. It may warrant a
configuration option, but let's try to avoid that if possible.

> 2. if browse-url should be used for non-file: urls (it might open a browser window outside of Emacs, which IMO is fine.)

What's the alternative? The very purpose of the operation is to open a
URL in a browser.

cheers
alan