mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-07 01:25:38 -05:00
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:
14
extensions/data-workspace/src/common/constants.ts
Normal file
14
extensions/data-workspace/src/common/constants.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { EOL } from 'os';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export const ExtensionActivationErrorMessage = (extensionId: string, err: any): string => { return localize('activateExtensionFailed', "Failed to load the project provider extension '{0}'. Error message: {1}", extensionId, err.message ?? err); };
|
||||
export const UnknownProjectsErrorMessage = (projectFiles: string[]): string => { return localize('UnknownProjectsError', "No provider was found for the following projects: {0}", projectFiles.join(EOL)); };
|
||||
|
||||
export const SelectProjectFileActionName = localize('SelectProjectFileActionName', "Select");
|
||||
|
||||
@@ -45,13 +45,19 @@ export interface IWorkspaceService {
|
||||
/**
|
||||
* Gets the project files in current workspace
|
||||
*/
|
||||
getProjectsInWorkspace(): Promise<string[]>;
|
||||
getProjectsInWorkspace(): Promise<vscode.Uri[]>;
|
||||
|
||||
/**
|
||||
* Gets the project provider by project file
|
||||
* @param projectFilePath The full path of the project file
|
||||
* @param projectFileUri The Uri of the project file
|
||||
*/
|
||||
getProjectProvider(projectFilePath: string): Promise<IProjectProvider | undefined>;
|
||||
getProjectProvider(projectFileUri: vscode.Uri): Promise<IProjectProvider | undefined>;
|
||||
|
||||
/**
|
||||
* Adds the projects to workspace, if a project is not in the workspace folder, its containing folder will be added to the workspace
|
||||
* @param projectFiles the list of project files to be added, the project file should be absolute path.
|
||||
*/
|
||||
addProjectsToWorkspace(projectFiles: vscode.Uri[]): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { IWorkspaceService, WorkspaceTreeItem as WorkspaceTreeItem } from './interfaces';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { EOL } from 'os';
|
||||
const localize = nls.loadMessageBundle();
|
||||
import { UnknownProjectsErrorMessage } from './constants';
|
||||
|
||||
/**
|
||||
* Tree data provider for the workspace main view
|
||||
@@ -36,11 +34,10 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<Worksp
|
||||
const projects = await this._workspaceService.getProjectsInWorkspace();
|
||||
const unknownProjects: string[] = [];
|
||||
const treeItems: WorkspaceTreeItem[] = [];
|
||||
let project: string;
|
||||
for (project of projects) {
|
||||
for (const project of projects) {
|
||||
const projectProvider = await this._workspaceService.getProjectProvider(project);
|
||||
if (projectProvider === undefined) {
|
||||
unknownProjects.push(project);
|
||||
unknownProjects.push(project.path);
|
||||
continue;
|
||||
}
|
||||
const treeDataProvider = await projectProvider.getProjectTreeDataProvider(project);
|
||||
@@ -58,7 +55,7 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<Worksp
|
||||
});
|
||||
}
|
||||
if (unknownProjects.length > 0) {
|
||||
vscode.window.showErrorMessage(localize('UnknownProjectsError', "No provider was found for the following projects: {0}", unknownProjects.join(EOL)));
|
||||
vscode.window.showErrorMessage(UnknownProjectsErrorMessage(unknownProjects));
|
||||
}
|
||||
return treeItems;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user