diff --git a/packages/databricks-vscode/src/vscode-objs/WorkspaceFolderManager.ts b/packages/databricks-vscode/src/vscode-objs/WorkspaceFolderManager.ts index 72db2e78c..b9c68ef15 100644 --- a/packages/databricks-vscode/src/vscode-objs/WorkspaceFolderManager.ts +++ b/packages/databricks-vscode/src/vscode-objs/WorkspaceFolderManager.ts @@ -4,6 +4,7 @@ import { QuickPickItem, QuickPickItemKind, StatusBarAlignment, + TextEditor, WorkspaceFolder, window, workspace, @@ -34,6 +35,8 @@ export class WorkspaceFolderManager implements Disposable { this.button.show(); } + this.setIsActiveFileInActiveWorkspace(window.activeTextEditor); + this.disposables.push( this.button, workspace.onDidChangeWorkspaceFolders((e) => { @@ -51,20 +54,27 @@ export class WorkspaceFolderManager implements Disposable { return; } }), - window.onDidChangeActiveTextEditor((e) => { - const isActiveFileInActiveWorkspace = - this.activeWorkspaceFolder !== undefined && - e !== undefined && - e.document.uri.fsPath.startsWith( - this.activeWorkspaceFolder?.uri.fsPath - ); - customWhenContext.setIsActiveFileInActiveWorkspace( - isActiveFileInActiveWorkspace - ); + window.onDidChangeActiveTextEditor((editor) => { + this.setIsActiveFileInActiveWorkspace(editor); + }), + this.onDidChangeActiveWorkspaceFolder(() => { + this.setIsActiveFileInActiveWorkspace(window.activeTextEditor); }) ); } + private setIsActiveFileInActiveWorkspace(activeEditor?: TextEditor) { + const isActiveFileInActiveWorkspace = + this.activeWorkspaceFolder !== undefined && + activeEditor !== undefined && + activeEditor.document.uri.fsPath.startsWith( + this.activeWorkspaceFolder?.uri.fsPath + ); + this.customWhenContext.setIsActiveFileInActiveWorkspace( + isActiveFileInActiveWorkspace + ); + } + get activeWorkspaceFolder() { if (this._activeWorkspaceFolder === undefined) { throw new Error("No active workspace folder");