@@ -67,7 +67,7 @@ import { initializeRunConfiguration, runConfigurationProvider, runConfigurationN
6767import { InputStep , MultiStepInput } from './utils' ;
6868import { PropertiesView } from './propertiesView/propertiesView' ;
6969import { openJDKSelectionView } from './jdkDownloader' ;
70-
70+ import { NODE_WINDOWS_LABEL } from './constants' ;
7171const API_VERSION : string = "1.0" ;
7272const SERVER_NAME : string = "Oracle Java SE Language Server" ;
7373export const COMMAND_PREFIX : string = "jdk" ;
@@ -78,7 +78,7 @@ let nbProcess : ChildProcess | null = null;
7878let debugPort : number = - 1 ;
7979let debugHash : string | undefined ;
8080let consoleLog : boolean = ! ! process . env [ 'ENABLE_CONSOLE_LOG' ] ;
81-
81+ let deactivated : boolean = true ;
8282export class NbLanguageClient extends LanguageClient {
8383 private _treeViewService : TreeViewService ;
8484
@@ -330,8 +330,8 @@ class InitialPromise extends Promise<NbLanguageClient> {
330330}
331331
332332export function activate ( context : ExtensionContext ) : VSNetBeansAPI {
333+ deactivated = false ;
333334 let log = vscode . window . createOutputChannel ( SERVER_NAME ) ;
334-
335335 var clientResolve : ( x : NbLanguageClient ) => void ;
336336 var clientReject : ( err : any ) => void ;
337337
@@ -513,19 +513,26 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
513513
514514 context . subscriptions . push ( vscode . commands . registerCommand ( COMMAND_PREFIX + ".delete.cache" , async ( ) => {
515515 const storagePath = context . storageUri ?. fsPath ;
516- if ( ! storagePath ) {
516+ if ( ! storagePath ) {
517517 vscode . window . showErrorMessage ( 'Cannot find workspace path' ) ;
518518 return ;
519519 }
520+
520521 const userDir = path . join ( storagePath , "userdir" ) ;
521522 if ( userDir && fs . existsSync ( userDir ) ) {
522- const confirmation = await vscode . window . showInformationMessage ( 'Are you sure you want to delete cache for this workspace?' ,
523+ const confirmation = await vscode . window . showInformationMessage ( 'Are you sure you want to delete cache for this workspace and reload the window ?' ,
523524 'Yes' , 'Cancel' ) ;
524525 if ( confirmation === 'Yes' ) {
525- await fs . promises . rmdir ( userDir , { recursive : true } ) ;
526- const res = await vscode . window . showInformationMessage ( 'Cache cleared successfully for this workspace' , 'Reload window' ) ;
527- if ( res === 'Reload window' ) {
528- await vscode . commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
526+ try {
527+ await stopClient ( client ) ;
528+ deactivated = true ;
529+ await killNbProcess ( false , log ) ;
530+ await fs . promises . rmdir ( userDir , { recursive : true } ) ;
531+ await vscode . window . showInformationMessage ( "Cache deleted successfully" , 'Reload window' ) ;
532+ } catch ( err ) {
533+ await vscode . window . showErrorMessage ( 'Error deleting the cache' , 'Reload window' ) ;
534+ } finally {
535+ vscode . commands . executeCommand ( "workbench.action.reloadWindow" ) ;
529536 }
530537 }
531538 } else {
@@ -960,7 +967,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
960967 if ( p == nbProcess && code != 0 && code ) {
961968 vscode . window . showWarningMessage ( `${ SERVER_NAME } exited with ` + code ) ;
962969 }
963- if ( stdErr ?. match ( / C a n n o t f i n d j a v a / ) || os . type ( ) === "Windows_NT" ) {
970+ if ( stdErr ?. match ( / C a n n o t f i n d j a v a / ) || ( os . type ( ) === NODE_WINDOWS_LABEL && ! deactivated ) ) {
964971 vscode . window . showInformationMessage (
965972 "No JDK found!" ,
966973 "Download JDK and setup automatically"
0 commit comments