@@ -31,6 +31,14 @@ function getExecutor(): Executor {
3131 return executor ;
3232}
3333
34+ /**
35+ * Get the background executor
36+ */
37+ function getBackgroundExecutor ( ) : Executor {
38+ const executor = getExecutor ( ) ;
39+ return executor . BackgroundExecutor ?? executor ;
40+ }
41+
3442function joinCommand ( command : string , args : string [ ] = [ ] ) : string {
3543 if ( ! Array . isArray ( args ) ) return command ;
3644 return [ command , ...args ] . join ( " " ) ;
@@ -42,7 +50,18 @@ function wrapShellCommand(command: string): string {
4250 return `sh -lc "set -e; ${ escaped } "` ;
4351}
4452
45- async function runCommand ( command : string ) : Promise < string > {
53+ /**
54+ * Run a quick shell command using the background executor.
55+ */
56+ async function runQuickCommand ( command : string ) : Promise < string > {
57+ const wrapped = wrapShellCommand ( command ) ;
58+ return getBackgroundExecutor ( ) . execute ( wrapped , true ) ;
59+ }
60+
61+ /**
62+ * Run a shell command using the foreground executor
63+ */
64+ async function runForegroundCommand ( command : string ) : Promise < string > {
4665 const wrapped = wrapShellCommand ( command ) ;
4766 return getExecutor ( ) . execute ( wrapped , true ) ;
4867}
@@ -396,7 +415,7 @@ async function performInstallCheck(
396415) : Promise < boolean > {
397416 try {
398417 if ( launcher . checkCommand ) {
399- await runCommand ( launcher . checkCommand ) ;
418+ await runQuickCommand ( launcher . checkCommand ) ;
400419 }
401420 checkedCommands . set ( cacheKey , STATUS_PRESENT ) ;
402421 return true ;
@@ -434,7 +453,7 @@ async function performInstallCheck(
434453 `Installing ${ server . label } ...` ,
435454 ) ;
436455 loadingDialog . show ( ) ;
437- await runCommand ( install . command ) ;
456+ await runForegroundCommand ( install . command ) ;
438457 toast ( `${ server . label } installed` ) ;
439458 checkedCommands . set ( cacheKey , STATUS_PRESENT ) ;
440459 return true ;
@@ -663,18 +682,26 @@ export async function ensureServerRunning(
663682export function stopManagedServer ( serverId : string ) : void {
664683 const entry = managedServers . get ( serverId ) ;
665684 if ( ! entry ) return ;
666- getExecutor ( )
667- . stop ( entry . uuid )
668- . catch ( ( error : Error ) => {
669- console . warn ( `Failed to stop language server ${ serverId } ` , error ) ;
670- } ) ;
685+ const executor = getExecutor ( ) ;
686+ executor . stop ( entry . uuid ) . catch ( ( error : Error ) => {
687+ console . warn ( `Failed to stop language server ${ serverId } ` , error ) ;
688+ } ) ;
671689 managedServers . delete ( serverId ) ;
672690 announcedServers . delete ( serverId ) ;
691+
692+ // Stop foreground service when all servers are stopped
693+ if ( managedServers . size === 0 ) {
694+ executor . stopService ( ) . catch ( ( ) => { } ) ;
695+ }
673696}
674697
675698export function resetManagedServers ( ) : void {
676699 for ( const id of Array . from ( managedServers . keys ( ) ) ) {
677700 stopManagedServer ( id ) ;
678701 }
679702 managedServers . clear ( ) ;
703+ // Ensure foreground service is stopped
704+ getExecutor ( )
705+ . stopService ( )
706+ . catch ( ( ) => { } ) ;
680707}
0 commit comments