mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 17:23:40 -05:00
Corrects workspace project tree refresh behavior for adding new projects to the workspace (#16650)
* bugfix and updates * PR feedback * Deferred promise for project disk scan * fix casing * fixing race condition on extension activation, test failure
This commit is contained in:
@@ -13,8 +13,8 @@ export class DataWorkspaceExtension implements IExtension {
|
||||
constructor(private workspaceService: WorkspaceService) {
|
||||
}
|
||||
|
||||
getProjectsInWorkspace(ext?: string): Promise<vscode.Uri[]> {
|
||||
return this.workspaceService.getProjectsInWorkspace(ext);
|
||||
getProjectsInWorkspace(ext?: string, refreshFromDisk?: boolean): Promise<vscode.Uri[]> {
|
||||
return this.workspaceService.getProjectsInWorkspace(ext, refreshFromDisk);
|
||||
}
|
||||
|
||||
addProjectsToWorkspace(projectFiles: vscode.Uri[]): Promise<void> {
|
||||
|
||||
@@ -50,8 +50,10 @@ export interface IWorkspaceService {
|
||||
|
||||
/**
|
||||
* Gets the project files in current workspace
|
||||
* @param ext project extension to filter on. If this is passed in, this will only return projects with this file extension
|
||||
* @param refreshFromDisk whether to rescan the folder for project files, or return the cached version. Defaults to false.
|
||||
*/
|
||||
getProjectsInWorkspace(): Promise<vscode.Uri[]>;
|
||||
getProjectsInWorkspace(ext?: string, refreshFromDisk?: boolean): Promise<vscode.Uri[]>;
|
||||
|
||||
/**
|
||||
* Gets the project provider by project file
|
||||
|
||||
25
extensions/data-workspace/src/common/promise.ts
Normal file
25
extensions/data-workspace/src/common/promise.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Deferred promise
|
||||
*/
|
||||
export class Deferred<T = void> {
|
||||
promise: Promise<T>;
|
||||
resolve!: (value: T | PromiseLike<T>) => void;
|
||||
reject!: (reason?: any) => void;
|
||||
constructor() {
|
||||
this.promise = new Promise<T>((resolve, reject) => {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
});
|
||||
}
|
||||
|
||||
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
|
||||
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
|
||||
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult> {
|
||||
return this.promise.then(onfulfilled, onrejected);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,8 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<Worksp
|
||||
private _onDidChangeTreeData: vscode.EventEmitter<void | WorkspaceTreeItem | null | undefined> | undefined = new vscode.EventEmitter<WorkspaceTreeItem | undefined | void>();
|
||||
readonly onDidChangeTreeData?: vscode.Event<void | WorkspaceTreeItem | null | undefined> | undefined = this._onDidChangeTreeData?.event;
|
||||
|
||||
refresh(): void {
|
||||
async refresh(): Promise<void> {
|
||||
await this._workspaceService.getProjectsInWorkspace(undefined, true);
|
||||
this._onDidChangeTreeData?.fire();
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<Worksp
|
||||
}
|
||||
else {
|
||||
// if the element is undefined return the project tree items
|
||||
const projects = await this._workspaceService.getProjectsInWorkspace();
|
||||
const projects = await this._workspaceService.getProjectsInWorkspace(undefined, false);
|
||||
await vscode.commands.executeCommand('setContext', 'isProjectsViewEmpty', projects.length === 0);
|
||||
const unknownProjects: string[] = [];
|
||||
const treeItems: WorkspaceTreeItem[] = [];
|
||||
|
||||
Reference in New Issue
Block a user