diff --git a/src/context/context.ts b/src/context/context.ts index e2f4e9c..5db0a77 100644 --- a/src/context/context.ts +++ b/src/context/context.ts @@ -50,6 +50,7 @@ export class Context extends EventEmitter { // If there is no profile loaded skip, do not load a context. if (!profile) { + this.loaded = true; return; } @@ -242,20 +243,20 @@ export class Context extends EventEmitter { return this.config.getProfileName(); } - addAndSaveProfile(name: string, appPassword: AppPassword, region: string) { - this.config.addAndSaveProfile(name, appPassword, region); - this.loadContext(); + async addAndSaveProfile(name: string, appPassword: AppPassword, region: string) { + await this.config.addAndSaveProfile(name, appPassword, region); + await this.loadContext(); } - removeAndSaveProfile(name: string) { + async removeAndSaveProfile(name: string) { this.config.removeAndSaveProfile(name); - this.loadContext(); + await this.loadContext(); } - setProfile(name: string) { + async setProfile(name: string) { this.config.setProfile(name); this.environment = undefined; - this.loadContext(); + await this.loadContext(); } handleErr(err: Error) { diff --git a/src/extension.ts b/src/extension.ts index e4324cf..4801a0a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -43,6 +43,13 @@ export function activate(vsContext: vscode.ExtensionContext) { // Register the `Run SQL` command. let runDisposable = vscode.commands.registerCommand('materialize.run', async () => { console.log("[RunSQLCommand]", "Firing detected."); + + // Check for available profile before proceeding. + if (!context.getProfileName()) { + vscode.window.showErrorMessage('No available profile to run the query.'); + return; + } + const activeEditor = vscode.window.activeTextEditor; if (!activeEditor) { vscode.window.showErrorMessage('No active editor.'); diff --git a/src/providers/auth.ts b/src/providers/auth.ts index 24d87da..b112499 100644 --- a/src/providers/auth.ts +++ b/src/providers/auth.ts @@ -170,7 +170,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider { * @param name name of the profile. * @param webviewView webview of the provider. */ - checkLoginServerResponse( + async checkLoginServerResponse( appPasswordResponse: AppPasswordResponse | undefined, name: string, webviewView: vscode.WebviewView @@ -184,7 +184,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider { // Set the state loading to true. After the new context is loaded // loading will turn false. this.state.isLoading = true; - this.context.addAndSaveProfile(name, appPassword, region.toString()); + await this.context.addAndSaveProfile(name, appPassword, region.toString()); } else { // Cancel login process. webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); @@ -211,10 +211,14 @@ export default class AuthProvider implements vscode.WebviewViewProvider { webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); loginServer(name).then((appPasswordResponse) => { - this.checkLoginServerResponse(appPasswordResponse, name, webviewView); + this.checkLoginServerResponse(appPasswordResponse, name, webviewView).then(() => { + webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); + }); }).catch((err) => { console.error("Error setting up the server: ", err); vscode.window.showErrorMessage('Internal error while waiting for the credentials.'); + webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); + }); break; } @@ -261,7 +265,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider { const name = this.context.getProfileName(); if (name) { - this.context.removeAndSaveProfile(name); + await this.context.removeAndSaveProfile(name); } else { console.error("[Auth]", "Profile name is not available."); } @@ -332,9 +336,10 @@ export default class AuthProvider implements vscode.WebviewViewProvider { // Use a nonce to only allow a specific script to be run. const nonce = getNonce(); + console.log("Is loading: ", this.state.isLoading); let content = ( ` - Profile Name + Profile Name

Profile name must contain only ASCII letters, ASCII digits, underscores, and dashes.

Continue