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

Rework shutdown/exit requests #55

Merged
merged 6 commits into from
Nov 6, 2023
Merged

Rework shutdown/exit requests #55

merged 6 commits into from
Nov 6, 2023

Conversation

tdroxler
Copy link
Member

@tdroxler tdroxler commented Oct 31, 2023

Resolves: #37

@simerplaha I think we can have a review.

Base on eclipse-lsp4j/lsp4j#770 it's better to cancel the listener on exit

As explained in the issue, I tried to follow the lsp specs

Note about tests: every time I try to use scalamock I fail, I tried all possibility I could find to mock the client and mock the logMessage function, but it always failed, so I went with an EmpytRalphLangClient, don't hesitate to give it a try

As suggested by the `lsp4j` team: eclipse-lsp4j/lsp4j#770
I couldn't manage to make a working mock of `RalphLangClient`, as we
need the `logMessage` to be implemented, so I created an `EmptyRalphLangClient` instead
Copy link
Member

@simerplaha simerplaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

Minor suggestions and a question for my knowledge.

thisServer.synchronized {
logger.info("shutdown")
if(thisServer.state.shutdownReceived){
notifyAndThrow(ResponseError.ShutdownRequested)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question for my knowledge - Since this throws an Exception, the client that invoked shutdown() is still waiting a response right? Because CompletableFuture remains un-responded. Should a failed CompletableFuture be returned instead?

CompletableFuture.failedFuture(ResponseError.ShutdownRequested.toResponseErrorException)

Another question: Since the protocol here say

If a server receives requests after a shutdown request those requests should error with InvalidRequest.

Should all other requests (didOpen, didChange, didClose, didSave, didChangeWatchedFiles etc) also respond with InvalidRequest when a shutdown in progress?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice catch, we shouldn't throw indeed. I don't event think we need to complete with a failure, we maybe need to simply complete the error:

CompletableFuture.completedFuture(ResponseError.ShutdownRequested)

I'll check.

Regarding the second question I think so yes, it seems every request should get rejected in case of shutdown. I'll create an issue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so yes throwing isn't a good idea 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually all the did* functions are notifications, not requests, so we don't need to answer with InvalidRequest, We could just do nothing from our side.

We need to reply on things like: Completion Request, currently we only need to add this to the Initialize request

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and actually you were right, they recommend to fail the future, but with completeExceptionnally: https://github.com/eclipse-lsp4j/lsp4j/blob/3c98376797b96922689af963b8403431135f0f35/documentation/jsonrpc.md?plain=1#L36-L56

Then the json rpc server handle it and return an error to the client

tdroxler and others added 3 commits November 6, 2023 08:03
…angServer.scala

Co-authored-by: Simer <simer.j@gmail.com>
Co-authored-by: Simer <simer.j@gmail.com>
We shouldn't throw the error, as the app will then stop and the client
will wait forever an answered. As defined in the protocol, we should
respond with the error to the client
@tdroxler
Copy link
Member Author

tdroxler commented Nov 6, 2023

@simerplaha I pushed a commit following https://github.com/eclipse-lsp4j/lsp4j/blob/3c98376797b96922689af963b8403431135f0f35/documentation/jsonrpc.md?plain=1#L36-L56

Copy link
Member

@simerplaha simerplaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 awesome!

@tdroxler tdroxler merged commit 75a570d into master Nov 6, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server not stopped when editor exit
2 participants