@@ -342,6 +342,7 @@ export class PawSQLTreeProvider
342342 }
343343 public async validateConfiguration ( hideMessage ?: boolean ) : Promise < void > {
344344 const config = vscode . workspace . getConfiguration ( "pawsql" ) ;
345+
345346 const apiKey = config . get < string > ( "apiKey" ) ;
346347 const frontendUrl = config . get < string > ( "frontendUrl" ) ;
347348 const backendUrl = config . get < string > ( "backendUrl" ) ;
@@ -350,8 +351,6 @@ export class PawSQLTreeProvider
350351 // Reset all validation states first
351352 this . isConfigValid = false ;
352353
353- // Validate backend connectivity
354-
355354 const backendResult = await validateBackend ( backendUrl ?? "" ) ;
356355
357356 const isBackendConnected = backendResult . isAvailable ;
@@ -366,20 +365,20 @@ export class PawSQLTreeProvider
366365 return ;
367366 }
368367
369- // Validate frontend connectivity
370- const frontendReuslt = await validateFrontend ( frontendUrl ?? "" ) ;
368+ // // Validate frontend connectivity
369+ // const frontendReuslt = await validateFrontend(frontendUrl ?? "");
371370
372- const isFrontendConnected = frontendReuslt . isAvailable ;
371+ // const isFrontendConnected = frontendReuslt.isAvailable;
373372
374- if ( ! isFrontendConnected ) {
375- ! hideMessage &&
376- vscode . window . showErrorMessage (
377- `${ LanguageService . getMessage (
378- "error.config.validate.failed"
379- ) } : ${ LanguageService . getMessage ( "error.frontendUrl.invalid" ) } `
380- ) ;
381- return ;
382- }
373+ // if (!isFrontendConnected) {
374+ // !hideMessage &&
375+ // vscode.window.showErrorMessage(
376+ // `${LanguageService.getMessage(
377+ // "error.config.validate.failed"
378+ // )}: ${LanguageService.getMessage("error.frontendUrl.invalid")}`
379+ // );
380+ // return;
381+ // }
383382
384383 // Validate API key
385384 const isApikeyValid = await ApiService . validateUserKey ( apiKey ?? "" ) ;
@@ -426,6 +425,69 @@ export class PawSQLTreeProvider
426425 ) ;
427426 }
428427 }
428+ public async validatePawSQLConfig ( ) : Promise < boolean > {
429+ const pawsqlConfig = vscode . workspace . getConfiguration ( "pawsql" ) ;
430+
431+ const apiKey = pawsqlConfig . get < string > ( "apiKey" ) ;
432+ const frontendUrl = pawsqlConfig . get < string > ( "frontendUrl" ) ;
433+ const backendUrl = pawsqlConfig . get < string > ( "backendUrl" ) ;
434+
435+ try {
436+ // Reset all validation states first
437+ this . isConfigValid = false ;
438+
439+ if ( ! backendUrl || ! frontendUrl || ! apiKey ) {
440+ this . isConfigValid = false ;
441+ vscode . commands . executeCommand ( "setContext" , "isConfigured" , false ) ;
442+ this . workspaces = [ ] ;
443+ return false ;
444+ }
445+
446+ const backendResult = await validateBackend ( backendUrl ) ;
447+ const isBackendConnected = backendResult . isAvailable ;
448+
449+ if ( ! isBackendConnected ) {
450+ this . isConfigValid = false ;
451+ vscode . commands . executeCommand ( "setContext" , "isConfigured" , false ) ;
452+ this . workspaces = [ ] ;
453+ return false ;
454+ }
455+
456+ const frontendReuslt = await validateFrontend ( frontendUrl ) ;
457+ const isFrontendConnected = frontendReuslt . isAvailable ;
458+
459+ if ( ! isFrontendConnected ) {
460+ this . isConfigValid = false ;
461+ vscode . commands . executeCommand ( "setContext" , "isConfigured" , false ) ;
462+
463+ this . workspaces = [ ] ;
464+ return false ;
465+ }
466+
467+ const isApikeyValid = await ApiService . validateUserKey ( apiKey ) ;
468+
469+ if ( ! isApikeyValid ) {
470+ this . isConfigValid = false ;
471+ vscode . commands . executeCommand ( "setContext" , "isConfigured" , false ) ;
472+
473+ this . workspaces = [ ] ;
474+ return false ;
475+ }
476+
477+ this . isConfigValid = true ;
478+ vscode . commands . executeCommand ( "setContext" , "isConfigured" , true ) ;
479+
480+ await this . loadWorkspaceData ( ) ;
481+ return true ;
482+ } catch ( error : any ) {
483+ console . error ( error ) ;
484+ this . isConfigValid = false ;
485+ vscode . commands . executeCommand ( "setContext" , "isConfigured" , false ) ;
486+
487+ this . workspaces = [ ] ;
488+ return false ;
489+ }
490+ }
429491
430492 private async registerProviders ( ) : Promise < void > {
431493 // 1. 创建树视图(如果不存在)
@@ -444,16 +506,12 @@ export class PawSQLTreeProvider
444506 private registerConfigurationChangeListener ( ) : void {
445507 vscode . workspace . onDidChangeConfiguration ( async ( event ) => {
446508 if ( this . isApiConfigChanged ( event ) ) {
447- await this . registerProviders ( ) ;
509+ await this . refresh ( true ) ;
448510 }
449511 } ) ;
450512 }
451513 public isApiConfigChanged ( e : vscode . ConfigurationChangeEvent ) : boolean {
452- return (
453- e . affectsConfiguration ( "pawsql.apiKey" ) ||
454- e . affectsConfiguration ( "pawsql.frontendUrl" ) ||
455- e . affectsConfiguration ( "pawsql.backendUrl" )
456- ) ;
514+ return e . affectsConfiguration ( "pawsql.apiKey" ) ;
457515 }
458516 public async validateConfig ( ) : Promise < boolean > {
459517 const config = vscode . workspace . getConfiguration ( "pawsql" ) ;
@@ -650,6 +708,62 @@ export class PawSQLTreeProvider
650708 }
651709 }
652710
711+ // Rest of the methods remain unchanged...
712+ private async loadWorkspaceData ( ) : Promise < void > {
713+ this . isWorkspaceLoading = true ;
714+ this . _onDidChangeTreeData . fire ( undefined ) ;
715+
716+ const apiKey = vscode . workspace
717+ . getConfiguration ( "pawsql" )
718+ . get < string > ( "apiKey" ) ;
719+
720+ if ( ! apiKey ) {
721+ vscode . window . showErrorMessage (
722+ `${ LanguageService . getMessage (
723+ "error.config.validate.failed"
724+ ) } : ${ LanguageService . getMessage ( "license.code.not.valid" ) } `
725+ ) ;
726+ return ;
727+ }
728+
729+ try {
730+ const [ workspacesResponse ] = await Promise . all ( [
731+ ApiService . getWorkspaces ( apiKey ) ,
732+ ] ) ;
733+
734+ this . workspaces = workspacesResponse . data . records . map (
735+ ( workspace ) =>
736+ new WorkspaceItem (
737+ workspace . workspaceName ,
738+ workspace . workspaceId ,
739+ workspace . workspaceName ,
740+ workspace . workspaceDefinitionId ,
741+ workspace . dbType ,
742+ workspace . dbHost ,
743+ workspace . dbPort ,
744+ vscode . TreeItemCollapsibleState . Collapsed
745+ )
746+ ) ;
747+ vscode . commands . executeCommand (
748+ "setContext" ,
749+ "hasNoWorkspace" ,
750+ this . workspaces . length === 0
751+ ) ;
752+ } catch ( error : any ) {
753+ console . log ( error ) ;
754+ this . isConfigValid = false ;
755+ vscode . commands . executeCommand (
756+ "setContext" ,
757+ "isConfigured" ,
758+ this . isConfigValid
759+ ) ;
760+ this . workspaces = [ ] ;
761+ } finally {
762+ this . isWorkspaceLoading = false ;
763+ this . _onDidChangeTreeData . fire ( undefined ) ;
764+ }
765+ }
766+
653767 private async getAnalysisItems (
654768 workspace : WorkspaceItem
655769 ) : Promise < AnalysisItem [ ] | EmptyItem [ ] > {
@@ -843,7 +957,15 @@ export class PawSQLTreeProvider
843957 } ) {
844958 const result = await ApiService . getUserKey ( config . email , config . password ) ;
845959 if ( ! result ) {
846- throw Error ( "error.login.invalidCredentials" ) ;
960+ await vscode . workspace
961+ . getConfiguration ( "pawsql" )
962+ . update ( "frontendUrl" , "" , true ) ;
963+
964+ await vscode . workspace
965+ . getConfiguration ( "pawsql" )
966+ . update ( "apiKey" , "" , true ) ;
967+
968+ return ;
847969 }
848970 const { apikey, frontendUrl } = result ;
849971
0 commit comments