Make project workspace selectable if no workspace is open yet (#13508)

* allow new workspace location to be editable

* fix workspace inputbox not showing up after toggling open workspace radio buttons

* add a few tests

* cleanup

* fix errors

* addressing comments

* fix filter for windows

* add error message if existing workspace file is selected and change picker to be folder only

* address comments

* fix typos and update tests
This commit is contained in:
Kim Santiago
2020-12-14 13:24:36 -08:00
committed by GitHub
parent c2de462955
commit 1aaf80c3ab
8 changed files with 186 additions and 41 deletions

View File

@@ -40,17 +40,16 @@ export class WorkspaceService implements IWorkspaceService {
}
/**
* Creates a new workspace in the same folder as the project. Because the extension host gets restared when
* Creates a new workspace in the same folder as the project. Because the extension host gets restarted when
* a new workspace is created and opened, the project needs to be saved as the temp project that will be loaded
* when the extension gets restarted
* @param projectFileFsPath project to add to the workspace
*/
async CreateNewWorkspaceForProject(projectFileFsPath: string): Promise<void> {
async CreateNewWorkspaceForProject(projectFileFsPath: string, workspaceFile: vscode.Uri | undefined): Promise<void> {
// save temp project
await this._context.globalState.update(TempProject, [projectFileFsPath]);
// create a new workspace - the workspace file will be created in the same folder as the project
const workspaceFile = vscode.Uri.file(path.join(path.dirname(projectFileFsPath), `${path.parse(projectFileFsPath).name}.code-workspace`));
// create a new workspace
const projectFolder = vscode.Uri.file(path.dirname(projectFileFsPath));
await azdata.workspace.createWorkspace(projectFolder, workspaceFile);
}
@@ -95,14 +94,14 @@ export class WorkspaceService implements IWorkspaceService {
}
}
async addProjectsToWorkspace(projectFiles: vscode.Uri[]): Promise<void> {
async addProjectsToWorkspace(projectFiles: vscode.Uri[], workspaceFilePath?: vscode.Uri): Promise<void> {
if (!projectFiles || projectFiles.length === 0) {
return;
}
// a workspace needs to be open to add projects
if (!vscode.workspace.workspaceFile) {
await this.CreateNewWorkspaceForProject(projectFiles[0].fsPath);
await this.CreateNewWorkspaceForProject(projectFiles[0].fsPath, workspaceFilePath);
// this won't get hit since the extension host will get restarted, but helps with testing
return;
@@ -171,11 +170,11 @@ export class WorkspaceService implements IWorkspaceService {
}
}
async createProject(name: string, location: vscode.Uri, projectTypeId: string): Promise<vscode.Uri> {
async createProject(name: string, location: vscode.Uri, projectTypeId: string, workspaceFile?: vscode.Uri): Promise<vscode.Uri> {
const provider = ProjectProviderRegistry.getProviderByProjectType(projectTypeId);
if (provider) {
const projectFile = await provider.createProject(name, location, projectTypeId);
this.addProjectsToWorkspace([projectFile]);
this.addProjectsToWorkspace([projectFile], workspaceFile);
this._onDidWorkspaceProjectsChange.fire();
return projectFile;
} else {