Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Properly shutdown language server #472

Merged
merged 5 commits into from
Sep 27, 2021

Conversation

charlespwd
Copy link
Contributor

@charlespwd charlespwd commented Sep 27, 2021

Turns out the process for closing the server is two messages.

  1. A shutdown request sent by the client (expects a response!)
  2. An exit notification sent by the client to shut it down

If we're not doing the exit, VS Code doesn't clear the logs. That's why we were getting multiple instances of Theme Check Language Server when restarting the server in VS Code.

Ooops!

https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#shutdown

Also, I changed $DEBUG to THEME_CHECK_DEBUG. $DEBUG has a special meaning in ruby and it logs all exception to STDERR. EVEN WHEN CAUGHT! It took me a while to figure out why the vs code logs were not disappearing. Turns out I had enabled that (because I set THEME_CHECK_DEBUG to true in my environment).

Also, now, instead of crashing the server, errors raised in a request handler will be sent back as an internal error.

This means you can keep having completions even when diagnostics are breaking and vice versa.

Copy link
Contributor

@macournoyer macournoyer left a comment

Choose a reason for hiding this comment

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

Looks good!

But I would change the ThemeCheck::THEME_CHECK_DEBUG to avoid a warning.

@charlespwd charlespwd force-pushed the fix/properly-shutdown-language-server branch 2 times, most recently from 7f75900 to f9c308c Compare September 27, 2021 19:31
$DEBUG is a standard ruby flag. It also logs all exceptions to STDERR.
When using the language server with this option, things were weird in
the logs pane. Since stuff kept getting logged even though the server
was closing and the exceptions were being caught.

This resulted in logs that stayed around instead of going away. Took me
way too long to figure that out. By moving to ThemeCheck.debug? instead,
this doesn't happen anymore.
result: null is a valid response (used in Shutdown exchange)
The shutdown -> exit loop makes it so the logs are properly cleaned up in VS Code.

Oops.
@charlespwd charlespwd force-pushed the fix/properly-shutdown-language-server branch from f9c308c to 694e14b Compare September 27, 2021 19:32
@charlespwd charlespwd merged commit 7bd837f into main Sep 27, 2021
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems November 9, 2021 18:20 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants