@@ -16,6 +16,7 @@ import {
1616 ExecuteCommandRequest ,
1717 MessageType ,
1818 ShowMessageNotification ,
19+ State ,
1920} from 'vscode-languageclient' ;
2021
2122import { Executable , LanguageClient , LanguageClientOptions , ServerOptions , StreamInfo } from 'vscode-languageclient/node' ;
@@ -29,6 +30,8 @@ const languageClientName = 'oxc';
2930const outputChannelName = 'Oxc' ;
3031const commandPrefix = 'oxc' ;
3132
33+ const RESTART_DELAY_MS = 50 ;
34+
3235const enum OxcCommands {
3336 RestartServer = `${ commandPrefix } .restartServer` ,
3437 ApplyAllFixesFile = `${ commandPrefix } .applyAllFixesFile` ,
@@ -63,13 +66,9 @@ export async function activate(context: ExtensionContext) {
6366 }
6467
6568 try {
66- // Guard against invoking restart while the client is in a transitional state.
67- // The languageclient exposes isRunning(), but we can also infer starting/stopping
68- // via internal state; here we only act if it is fully running or fully stopped.
69- // If starting, we bail out with a message to avoid race with initialize.
70- // Access internal _state (not part of public API) for finer grained restart guarding.
71- const state : string | undefined = ( client as any ) . _state ;
72- if ( state === 'starting' ) {
69+
70+ const state = ( client as LanguageClient ) ?. state ;
71+ if ( state === State . Starting ) {
7372 window . showWarningMessage ( 'oxc server is still starting; try restart again in a moment.' ) ;
7473 return ;
7574 }
@@ -80,7 +79,7 @@ export async function activate(context: ExtensionContext) {
8079 if ( externalSocketSpec ) {
8180 // External socket: stop sends shutdown/exit internally; wait a tick for server loop.
8281 await client . stop ( ) ;
83- await new Promise ( r => setTimeout ( r , 50 ) ) ;
82+ await new Promise ( r => setTimeout ( r , RESTART_DELAY_MS ) ) ;
8483 await client . start ( ) ;
8584 } else {
8685 // Spawned process: restart() is sufficient, but guard against transitional state.
@@ -217,7 +216,7 @@ export async function activate(context: ExtensionContext) {
217216 socket . on ( 'error' , ( err ) => {
218217 socket . destroy ( ) ;
219218 if ( attempt < maxAttempts ) {
220- const delay = baseDelayMs * Math . pow ( 2 , attempt - 1 ) ;
219+ const delay = baseDelayMs * ( 2 ** ( attempt - 1 ) ) ;
221220 outputChannel . info ( `Language server not ready (attempt ${ attempt } /${ maxAttempts } ). Retrying in ${ delay } ms...` ) ;
222221 setTimeout ( tryConnect , delay ) ;
223222 } else {
0 commit comments