|
6 | 6 | import vscode, { env, version } from 'vscode' |
7 | 7 | import * as nls from 'vscode-nls' |
8 | 8 | import * as crypto from 'crypto' |
9 | | -import { LanguageClient, LanguageClientOptions, RequestType } from 'vscode-languageclient' |
| 9 | +import { LanguageClient, LanguageClientOptions, RequestType, State } from 'vscode-languageclient' |
10 | 10 | import { InlineCompletionManager } from '../app/inline/completion' |
11 | 11 | import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth' |
12 | 12 | import { |
@@ -268,7 +268,25 @@ export async function startLanguageServer( |
268 | 268 | }, |
269 | 269 | } as DidChangeWorkspaceFoldersParams) |
270 | 270 | }), |
271 | | - { dispose: () => clearInterval(refreshInterval) } |
| 271 | + { dispose: () => clearInterval(refreshInterval) }, |
| 272 | + // Set this inside onReady so that it only triggers on subsequent language server starts (not the first) |
| 273 | + onServerRestartHandler(client, auth) |
272 | 274 | ) |
273 | 275 | }) |
274 | 276 | } |
| 277 | + |
| 278 | +/** |
| 279 | + * When the server restarts (likely due to a crash, then the LanguageClient automatically starts it again) |
| 280 | + * we need to run some server intialization again. |
| 281 | + */ |
| 282 | +function onServerRestartHandler(client: LanguageClient, auth: AmazonQLspAuth) { |
| 283 | + return client.onDidChangeState(async (e) => { |
| 284 | + // Ensure we are in a "restart" state |
| 285 | + if (!(e.oldState === State.Starting && e.newState === State.Running)) { |
| 286 | + return |
| 287 | + } |
| 288 | + |
| 289 | + // Need to set the auth token in the again |
| 290 | + await auth.refreshConnection(true) |
| 291 | + }) |
| 292 | +} |
0 commit comments