mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
filter data-workspace projects by ext (#14354)
* add filtering by project extension * Fix tests * addressing comments * convert to lowercase
This commit is contained in:
@@ -12,8 +12,8 @@ export class DataWorkspaceExtension implements IExtension {
|
|||||||
constructor(private workspaceService: WorkspaceService) {
|
constructor(private workspaceService: WorkspaceService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
getProjectsInWorkspace(): vscode.Uri[] {
|
getProjectsInWorkspace(ext?: string): vscode.Uri[] {
|
||||||
return this.workspaceService.getProjectsInWorkspace();
|
return this.workspaceService.getProjectsInWorkspace(ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
addProjectsToWorkspace(projectFiles: vscode.Uri[], workspaceFilePath?: vscode.Uri): Promise<void> {
|
addProjectsToWorkspace(projectFiles: vscode.Uri[], workspaceFilePath?: vscode.Uri): Promise<void> {
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ declare module 'dataworkspace' {
|
|||||||
export interface IExtension {
|
export interface IExtension {
|
||||||
/**
|
/**
|
||||||
* Returns all the projects in the workspace
|
* Returns all the projects in the workspace
|
||||||
|
* @param ext project extension to filter on. If this is passed in, this will only return projects with this file extension
|
||||||
*/
|
*/
|
||||||
getProjectsInWorkspace(): vscode.Uri[];
|
getProjectsInWorkspace(ext?: string): vscode.Uri[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add projects to the workspace
|
* Add projects to the workspace
|
||||||
|
|||||||
@@ -155,8 +155,15 @@ export class WorkspaceService implements IWorkspaceService {
|
|||||||
return projectTypes;
|
return projectTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
getProjectsInWorkspace(): vscode.Uri[] {
|
getProjectsInWorkspace(ext?: string): vscode.Uri[] {
|
||||||
return vscode.workspace.workspaceFile ? this.getWorkspaceConfigurationValue<string[]>(ProjectsConfigurationName).map(project => this.toUri(project)) : [];
|
let projects = vscode.workspace.workspaceFile ? this.getWorkspaceConfigurationValue<string[]>(ProjectsConfigurationName).map(project => this.toUri(project)) : [];
|
||||||
|
|
||||||
|
// filter by specified extension
|
||||||
|
if (ext) {
|
||||||
|
projects = projects.filter(p => p.fsPath.toLowerCase().endsWith(ext.toLowerCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ export async function getSqlProjectFilesInFolder(folderPath: string): Promise<st
|
|||||||
*/
|
*/
|
||||||
export function getSqlProjectsInWorkspace(): vscode.Uri[] {
|
export function getSqlProjectsInWorkspace(): vscode.Uri[] {
|
||||||
const api = getDataWorkspaceExtensionApi();
|
const api = getDataWorkspaceExtensionApi();
|
||||||
return api.getProjectsInWorkspace().filter((p: vscode.Uri) => path.extname(p.fsPath) === constants.sqlprojExtension);
|
return api.getProjectsInWorkspace(constants.sqlprojExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDataWorkspaceExtensionApi(): dataworkspace.IExtension {
|
export function getDataWorkspaceExtensionApi(): dataworkspace.IExtension {
|
||||||
|
|||||||
@@ -560,7 +560,7 @@ export class ProjectsController {
|
|||||||
if ((<IProjectReferenceSettings>settings).projectName !== undefined) {
|
if ((<IProjectReferenceSettings>settings).projectName !== undefined) {
|
||||||
// get project path and guid
|
// get project path and guid
|
||||||
const projectReferenceSettings = settings as IProjectReferenceSettings;
|
const projectReferenceSettings = settings as IProjectReferenceSettings;
|
||||||
const workspaceProjects = await utils.getSqlProjectsInWorkspace();
|
const workspaceProjects = utils.getSqlProjectsInWorkspace();
|
||||||
const referencedProject = await Project.openProject(workspaceProjects.filter(p => path.parse(p.fsPath).name === projectReferenceSettings.projectName)[0].fsPath);
|
const referencedProject = await Project.openProject(workspaceProjects.filter(p => path.parse(p.fsPath).name === projectReferenceSettings.projectName)[0].fsPath);
|
||||||
const relativePath = path.relative(project.projectFolderPath, referencedProject?.projectFilePath!);
|
const relativePath = path.relative(project.projectFolderPath, referencedProject?.projectFilePath!);
|
||||||
projectReferenceSettings.projectRelativePath = vscode.Uri.file(relativePath);
|
projectReferenceSettings.projectRelativePath = vscode.Uri.file(relativePath);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ describe('Add Database Reference Dialog', () => {
|
|||||||
|
|
||||||
beforeEach(function (): void {
|
beforeEach(function (): void {
|
||||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => []);
|
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace(TypeMoq.It.isAny())).returns(() => []);
|
||||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object });
|
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -550,7 +550,7 @@ describe('ProjectsController', function (): void {
|
|||||||
const project2 = await Project.openProject(vscode.Uri.file(projPath2).fsPath);
|
const project2 = await Project.openProject(vscode.Uri.file(projPath2).fsPath);
|
||||||
const showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
const showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => [vscode.Uri.file(project1.projectFilePath), vscode.Uri.file(project2.projectFilePath)]);
|
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace(TypeMoq.It.isAny())).returns(() => [vscode.Uri.file(project1.projectFilePath), vscode.Uri.file(project2.projectFilePath)]);
|
||||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object });
|
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object });
|
||||||
|
|
||||||
// add project reference from project1 to project2
|
// add project reference from project1 to project2
|
||||||
|
|||||||
Reference in New Issue
Block a user