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

Show message to the user in case of language server starting error #824

Closed
robertoaloi opened this issue Oct 4, 2021 · 14 comments
Closed
Labels
info-needed Issue requires more information from poster
Milestone

Comments

@robertoaloi
Copy link
Contributor

Starting a language server via a client.start() can result in an error. Usually the stdout or stderr for the server process contain hints to what the problem could be. In case of such an error while starting the server, the only message displayed to the user is something like:

[Error - 1:33:53 PM] Connection to server got closed. Server will not be restarted.

I wonder if there's any way to improve the situation and display the stdout/stderr from the server to the user when the language server fails to start. The clientOptions include a errorHandler that can be customized, but that doesn't seem to help, since when the issue occurs the closed() method does not get any arguments.

Note: I'm not a Typescript / JS developer myself, so there may be something I'm missing.

@dbaeumer
Copy link
Member

dbaeumer commented Oct 5, 2021

If the communication channel is NOT stdout/stdin then everything a server write to stdout/stderr is printed to the output channel. The corresponding code is here:

serverProcess.stderr.on('data', data => this.outputChannel.append(Is.string(data) ? data : data.toString(encoding)));

So in your case it looks like the server doesn't start and even capturing stderr/stdout doesn't work.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Oct 5, 2021
@robertoaloi
Copy link
Contributor Author

The communication channel does use stdout/stdin (code at https://github.com/erlang-ls/vscode/blob/main/client/src/extension.ts#L19 and https://github.com/erlang-ls/vscode/blob/main/client/src/client.ts#L46). As a language server maintainer, what I'm trying to figure out is how can I improve things in the VS Code client so that eventual issues which cause the server to fail to start (e.g. due to environmental issues) can be propagated to the user via the UI.

@dbaeumer
Copy link
Member

dbaeumer commented Oct 8, 2021

If the communication happens over stderr / stdout the server can't use these to write message to the console. It will interfere with the communication.

The protocol defines alternative message which work in all cases. See https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#window_logMessage

@alanz
Copy link

alanz commented Oct 8, 2021

I think Roberto is talking about a scenario where the server is misconfigured, and fails to start.

At the moment you just get an error saying the server did not start, and eventually reports 5 failures and stops.

Perhaps we could have an option when that point is reached to display whatever the server did emit on stdout/stderr somewhere on the client.

@robertoaloi
Copy link
Contributor Author

Alan's interpretation is correct. I'm raising this with the Emacs LSP client as well.

@alanz
Copy link

alanz commented Oct 14, 2021

@robertoaloi
Copy link
Contributor Author

@alanz That looks promising. I can try and port that to our server. If that works it's probably worth implementing something similar in the client or, at least, in the LSP sample extension.

@dbaeumer
Copy link
Member

@robertoaloi so in our case the process creation fails. Right? What kind of server do you have and how do you start it.

@robertoaloi
Copy link
Contributor Author

@dbaeumer The process is an external executable, implemented in Erlang. You can see the start code here:

https://github.com/erlang-ls/vscode/blob/main/client/src/extension.ts#L14-L20

https://github.com/erlang-ls/vscode/blob/main/client/src/client.ts#L13

@robertoaloi
Copy link
Contributor Author

robertoaloi commented Oct 30, 2021

Here is a workaround for this issue in Erlang LS: erlang-ls/vscode#114

@dbaeumer dbaeumer added this to the 3.17 milestone Nov 15, 2021
@dbaeumer
Copy link
Member

The handler now allows to return a message that will be presented to the user with a button to open the output channel (which contains stdout)

@robertoaloi
Copy link
Contributor Author

That's nice. Will try this asap, thanks!

@axelson
Copy link

axelson commented Nov 27, 2021

The handler now allows to return a message that will be presented to the user with a button to open the output channel (which contains stdout)

That's great! Are there any examples of a client that utilizes it?

@dbaeumer
Copy link
Member

The LSP client itself uses it :-). Search for references.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants