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

Clear nullability warnings in server/omnisharp.ts #5199

Merged

Conversation

50Wliu
Copy link
Contributor

@50Wliu 50Wliu commented May 2, 2022

Mostly, this adds a mini state machine to server.ts that controls which variables can be accessed.

I believe there's the following behavior changes to watch out for:

  • _makeRequest now errors out if a request is sent when the server isn't running. (This would throw an uncaught exception anyway because of this._serverProcess being undefined, now it's just explicit.)
  • stop now short-circuits if the server is already stopped.
  • autoStart now calls _start directly rather than going through restart. Given how it's called autoStart, I feel like this makes sense.

Potential future improvements:

  • Make launchTarget non-nullable. This is more difficult because o.restart currently tries to restart by implicitly using the server's last-known launch target. However, it could be possible if we...
  • Make the state machine into actual classes that inherit from each other. This would provide even stronger safety guarantees because now we can hide entire methods instead of just properties. And this enables the first bullet point by statefully exposing the last launch target for o.restart to target.

My naming scheme for ServerState and State is terrible. Please advise on better names for them :).

private _makeRequest(request: Request) {
private _makeRequest(request: Request): number {
if (this._state.status !== ServerState.Started) {
throw new Error("Tried to make a request when the OmniSharp server wasn't running");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this post to the EventStream instead?

Copy link
Member

Choose a reason for hiding this comment

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

I could see it emitting an event. OmnisharpFailure isn't what we want because it focuses the OmniSharp Log in the Output pane. It likely needs a new Event type which will be logged by the OmnisharpDebugModeLoggerObserver. This could certainly come as a follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I looked into what it would take to make this emit an event instead. The event emitting itself is easy; the problem is that _makeRequest needs to return an ID that's used by RequestQueue: https://github.com/OmniSharp/omnisharp-vscode/blob/f1f38b774243526a798a16922d3b8c2f2008a84b/src/omnisharp/requestQueue.ts#L95-L99

So, two options:

  1. Keep the throw to stop execution.
  2. Change _makeRequest to return number | undefined, emit the event, and don't add the request to the queue if it's undefined.

Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

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

Thanks!

@JoeRobich JoeRobich merged commit a64910f into dotnet:master May 9, 2022
@50Wliu 50Wliu deleted the users/winstonliu/omnisharp-server-nullability branch May 9, 2022 20:04
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.

2 participants