microsoft / microsoft/language-server-protocol

How to abort during initialize?

Open
#246 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request initialization
Dominant language
TypeScript
Stars
13k
Forks
1k
Avg merge
6d 1h
Merged PRs (30d)
10

Description

How can the client abort/cancel/shutdown during initialization?

Our language service sometimes takes ~5 minutes to start up, during which time it's unable to successfully handle any requests or notifications. Because if this I decided to make the "initialize" method only respond once it has finished starting up [see at end for explanation why].

But how to handle the case when the client wants to abandon the initialization part way through?

  • I imagine the client could send a $/cancelRequest notification to cancel the initialize request. This is allowed by JsonRpc, but LSP says the only notification allowed before the initialize request is exit, and other notifications should be dropped, and the client must not send additional notifications until the server has responded to initialize.

  • I imagine the client could send a shutdown request. The LSP spec says that the server must respond with code -32002 if this (or any) request comes before the initialize request, and says the client must not send any requests until after the initialize response.

  • I imagine the client could send a exit notification. This would work in theory according to the LSP spec. But the way LanguageClient is implemented, when you call stop(), it first sends a shutdown request, and only if that succeeds will it send the exit notification. So this plan won't work well. Indeed, if LanguageClient is asked to stop() in the middle of initialization, it will transition into the Stopping state and not dispose of anything or clean anything up.

https://github.com/Microsoft/vscode-languageserver-node/blob/master/client/src/client.ts#L1530

Why can't the server respond immediately to the initialize request? ... If it responded to initialize immediately, then the client would merrily send loads of "didOpen/didChange" notifications, and the server would have no way of indicating that it wasn't ready for them, so it would have to queue every single such notification up until such time as it could handle them. That'd be crummy. Dynamic registration might notionally work, but I don't think it's good to rely on clients supporting it.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the initialize, shutdown, exit, and $/cancelRequest rules in the issue, then inspect client/src/client.ts around line 1530. Compare the protocol constraints with LanguageClient's stop() behavior; done means reaching and documenting a decided cancellation or shutdown behavior for initialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.