Add back "Remove Project" (#17178)

* remove project working with full paths

* use relative paths

* const

* addressing comments
This commit is contained in:
Kim Santiago
2021-09-28 17:09:21 -07:00
committed by GitHub
parent 1c112689b1
commit ee8285bf38
4 changed files with 59 additions and 4 deletions

View File

@@ -16,6 +16,9 @@ import { TelemetryReporter, TelemetryViews, TelemetryActions } from '../common/t
import { Deferred } from '../common/promise';
import { getAzdataApi } from '../common/utils';
const WorkspaceConfigurationName = 'dataworkspace';
const ExcludedProjectsConfigurationName = 'excludedProjects';
export class WorkspaceService implements IWorkspaceService {
private _onDidWorkspaceProjectsChange: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
readonly onDidWorkspaceProjectsChange: vscode.Event<void> = this._onDidWorkspaceProjectsChange?.event;
@@ -93,8 +96,14 @@ export class WorkspaceService implements IWorkspaceService {
}
}
// 3. If any new projects are detected, fire event to refresh projects tree
// 3. Check if the project was previously excluded and remove it from the list of excluded projects if it was
const excludedProjects = this.getWorkspaceConfigurationValue<string[]>(ExcludedProjectsConfigurationName);
const updatedExcludedProjects = excludedProjects.filter(excludedProj => !projectFiles.find(newProj => vscode.workspace.asRelativePath(newProj) === excludedProj));
if (excludedProjects.length !== updatedExcludedProjects.length) {
await this.setWorkspaceConfigurationValue(ExcludedProjectsConfigurationName, updatedExcludedProjects);
}
// 4. If any new projects are detected, fire event to refresh projects tree
if (newProjectAdded) {
this._onDidWorkspaceProjectsChange.fire();
}
@@ -127,6 +136,10 @@ export class WorkspaceService implements IWorkspaceService {
throw new Error(constants.openedProjectsUndefinedAfterRefresh);
}
// remove excluded projects specified in workspace file
const excludedProjects = this.getWorkspaceConfigurationValue<string[]>(ExcludedProjectsConfigurationName);
this.openedProjects = this.openedProjects.filter(project => !excludedProjects.find(excludedProject => excludedProject === vscode.workspace.asRelativePath(project)));
// filter by specified extension
if (ext) {
return this.openedProjects.filter(p => p.fsPath.toLowerCase().endsWith(ext.toLowerCase()));
@@ -257,4 +270,28 @@ export class WorkspaceService implements IWorkspaceService {
ProjectProviderRegistry.registerProvider(extension.exports, extension.id);
}
}
/**
* Adds the specified project to list of projects to hide in projects viewlet. This list is kept track of in the workspace file
* @param projectFile uri of project to remove from projects viewlet
*/
async removeProject(projectFile: vscode.Uri): Promise<void> {
TelemetryReporter.createActionEvent(TelemetryViews.WorkspaceTreePane, TelemetryActions.ProjectRemovedFromWorkspace)
.withAdditionalProperties({
projectType: path.extname(projectFile.fsPath)
}).send();
const excludedProjects = this.getWorkspaceConfigurationValue<string[]>(ExcludedProjectsConfigurationName);
excludedProjects.push(vscode.workspace.asRelativePath(projectFile.fsPath));
await this.setWorkspaceConfigurationValue(ExcludedProjectsConfigurationName, [...new Set(excludedProjects)]);
this._onDidWorkspaceProjectsChange.fire();
}
getWorkspaceConfigurationValue<T>(configurationName: string): T {
return vscode.workspace.getConfiguration(WorkspaceConfigurationName).get(configurationName) as T;
}
async setWorkspaceConfigurationValue(configurationName: string, value: any): Promise<void> {
await vscode.workspace.getConfiguration(WorkspaceConfigurationName).update(configurationName, value, vscode.ConfigurationTarget.Workspace);
}
}