add existing project to workspace feature (#12249)

* add existing project to workspace feature

* update file name

* new test and use URI

* handle workspace with no folder

* add more validation

* and more tests

* use forward slash
This commit is contained in:
Alan Ren
2020-09-14 15:43:29 -07:00
committed by GitHub
parent 7a524d7a35
commit 23c16ebfb3
13 changed files with 530 additions and 30 deletions

View File

@@ -4,16 +4,40 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as path from 'path';
import * as dataworkspace from 'dataworkspace';
import { WorkspaceTreeDataProvider } from './common/workspaceTreeDataProvider';
import { WorkspaceService } from './services/workspaceService';
import { DataWorkspaceExtension } from './dataWorkspaceExtension';
import { SelectProjectFileActionName } from './common/constants';
export async function activate(context: vscode.ExtensionContext): Promise<dataworkspace.IExtension> {
const workspaceService = new WorkspaceService();
const workspaceTreeDataProvider = new WorkspaceTreeDataProvider(workspaceService);
context.subscriptions.push(vscode.window.registerTreeDataProvider('dataworkspace.views.main', workspaceTreeDataProvider));
context.subscriptions.push(vscode.commands.registerCommand('projects.addProject', () => {
context.subscriptions.push(vscode.commands.registerCommand('projects.addProject', async () => {
// To Sakshi - You can replace the implementation with your complete dialog implementation
// but all the code here should be reusable by you
if (vscode.workspace.workspaceFile) {
const filter: { [name: string]: string[] } = {};
const projectTypes = await workspaceService.getAllProjectTypes();
projectTypes.forEach(type => {
filter[type.displayName] = projectTypes.map(projectType => projectType.projectFileExtension);
});
let fileUris = await vscode.window.showOpenDialog({
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
defaultUri: vscode.Uri.file(path.dirname(vscode.workspace.workspaceFile.path)),
openLabel: SelectProjectFileActionName,
filters: filter
});
if (!fileUris || fileUris.length === 0) {
return;
}
await workspaceService.addProjectsToWorkspace(fileUris);
workspaceTreeDataProvider.refresh();
}
}));
context.subscriptions.push(vscode.commands.registerCommand('dataworkspace.refresh', () => {