Skip to content

Commit d9ea6bf

Browse files
authored
VsCode Tasks PR1 : Introducing default build property with create project quickpics (#26315)
* introducing default build property with create project quickpics * modified test
1 parent 39e075b commit d9ea6bf

File tree

7 files changed

+76
-6
lines changed

7 files changed

+76
-6
lines changed

extensions/data-workspace/src/common/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const SdkStyleProject = localize('dataworkspace.sdkStyleProject', "SDK-st
5757
export const LearnMore = localize('dataworkspace.learnMore', "Learn More");
5858
export const YesRecommended = localize('dataworkspace.yesRecommended', "Yes (Recommended)");
5959
export const No = localize('dataworkspace.no', "No");
60+
export const Yes = localize('dataworkspace.yes', "Yes");
6061
export const SdkLearnMorePlaceholder = localize('dataworkspace.sdkLearnMorePlaceholder', "Click \"Learn More\" button for more information about SDK-style projects");
6162
export const Default = localize('dataworkspace.default', "Default");
6263
export const SelectTargetPlatform = localize('dataworkspace.selectTargetPlatform', "Select Target Platform");
@@ -69,6 +70,7 @@ export const reservedWindowsFilenameErrorMessage = localize('reservedWindowsFile
6970
export const reservedValueErrorMessage = localize('reservedValueErrorMessage', "Reserved file name. Choose another name and try again");
7071
export const trailingWhitespaceErrorMessage = localize('trailingWhitespaceErrorMessage', "File name cannot start or end with whitespace");
7172
export const tooLongFilenameErrorMessage = localize('tooLongFilenameErrorMessage', "File name cannot be over 255 characters");
73+
export const confirmCreateProjectWithBuildTaskDialogName = localize('confirmCreateProjectWithBuildTaskDialogName', "Do you want to configure SQL project build as the default build configuration for this folder?");
7274

7375
//Open Existing Dialog
7476
export const OpenExistingDialogTitle = localize('dataworkspace.openExistingDialogTitle', "Open Existing Project");

extensions/data-workspace/src/common/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ export interface IWorkspaceService {
7575
* @param projectTypeId The project type id
7676
* @param projectTargetPlatform The target platform of the project
7777
* @param sdkStyleProject Whether or not the project is SDK-style
78+
* @param configureDefaultBuild Whether or not to configure the default build
7879
*/
79-
createProject(name: string, location: vscode.Uri, projectTypeId: string, projectTargetPlatform?: string, sdkStyleProject?: boolean): Promise<vscode.Uri>;
80+
createProject(name: string, location: vscode.Uri, projectTypeId: string, projectTargetPlatform?: string, sdkStyleProject?: boolean, configureDefaultBuild?: boolean): Promise<vscode.Uri>;
8081

8182
/**
8283
* Clones git repository and adds projects to workspace

extensions/data-workspace/src/dataworkspace.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ declare module 'dataworkspace' {
9999
* @param projectTypeId the identifier of the selected project type
100100
* @param projectTargetPlatform the target platform of the project
101101
* @param sdkStyleProject whether or not a project is SDK-style
102+
* @param configureDefaultBuild whether or not to configure default build
102103
*/
103-
createProject(name: string, location: vscode.Uri, projectTypeId: string, projectTargetPlatform?: string, sdkStyleProject?: boolean): Promise<vscode.Uri>;
104+
createProject(name: string, location: vscode.Uri, projectTypeId: string, projectTargetPlatform?: string, sdkStyleProject?: boolean, configureDefaultBuild?: boolean): Promise<vscode.Uri>;
104105

105106
/**
106107
* Gets the project data corresponding to the project file, to be placed in the dashboard container
@@ -189,6 +190,11 @@ declare module 'dataworkspace' {
189190
* Location where clicking on the Learn More to know more about project type will go
190191
*/
191192
readonly learnMoreUrl?: string
193+
194+
/**
195+
* Whether or not the project has a default build configuration
196+
*/
197+
readonly configureDefaultBuild?: boolean;
192198
}
193199

194200
/**

extensions/data-workspace/src/dialogs/newProjectDialog.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class NewProjectDialogModel {
2424
location: string = '';
2525
targetPlatform?: string;
2626
sdkStyleProject?: boolean;
27+
configureDefaultBuild: boolean = false;
2728
}
2829

2930
export async function openSpecificProjectNewProjectDialog(projectType: IProjectType, workspaceService: WorkspaceService): Promise<vscode.Uri | undefined> {
@@ -90,7 +91,7 @@ export class NewProjectDialog extends DialogBase {
9091
.withAdditionalProperties({ projectFileExtension: this.model.projectFileExtension, projectTemplateId: this.model.projectTypeId })
9192
.send();
9293

93-
this.projectUri = await this.workspaceService.createProject(this.model.name, vscode.Uri.file(this.model.location), this.model.projectTypeId, this.model.targetPlatform, this.model.sdkStyleProject);
94+
this.projectUri = await this.workspaceService.createProject(this.model.name, vscode.Uri.file(this.model.location), this.model.projectTypeId, this.model.targetPlatform, this.model.sdkStyleProject, this.model.configureDefaultBuild);
9495
this.newProjectDialogComplete?.resolve();
9596
}
9697
catch (err) {

extensions/data-workspace/src/dialogs/newProjectQuickpick.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,17 @@ export async function createNewProjectWithQuickpick(workspaceService: WorkspaceS
175175
}
176176
}
177177

178-
await workspaceService.createProject(projectName, vscode.Uri.file(projectLocation), projectType.id, targetPlatform, sdkStyle);
178+
// 8. Configure Sql project default build or not
179+
let configureDefaultBuild = await vscode.window.showQuickPick(
180+
[constants.Yes, constants.No],
181+
{ title: constants.confirmCreateProjectWithBuildTaskDialogName, ignoreFocusOut: true }
182+
);
183+
184+
if (!configureDefaultBuild) {
185+
// User cancelled
186+
return;
187+
}
188+
await workspaceService.createProject(projectName, vscode.Uri.file(projectLocation), projectType.id, targetPlatform, sdkStyle, configureDefaultBuild === constants.Yes);
179189

180190
// Add info message with 'learn more' button if project type has a link
181191
// for user to learn more about the project type

extensions/data-workspace/src/services/workspaceService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ export class WorkspaceService implements IWorkspaceService {
227227
return ProjectProviderRegistry.getProviderByProjectExtension(projectType);
228228
}
229229

230-
async createProject(name: string, location: vscode.Uri, projectTypeId: string, projectTargetVersion?: string, sdkStyleProject?: boolean): Promise<vscode.Uri> {
230+
async createProject(name: string, location: vscode.Uri, projectTypeId: string, projectTargetVersion?: string, sdkStyleProject?: boolean, configureDefaultBuild?: boolean): Promise<vscode.Uri> {
231231
const provider = ProjectProviderRegistry.getProviderByProjectType(projectTypeId);
232232
if (provider) {
233-
const projectFile = await provider.createProject(name, location, projectTypeId, projectTargetVersion, sdkStyleProject);
233+
const projectFile = await provider.createProject(name, location, projectTypeId, projectTargetVersion, sdkStyleProject, configureDefaultBuild);
234234
await this.addProjectsToWorkspace([projectFile]);
235235
this._onDidWorkspaceProjectsChange.fire();
236236
return projectFile;

extensions/data-workspace/src/test/workspaceService.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,54 @@ suite('WorkspaceService', function (): void {
323323
should.strictEqual(updateWorkspaceFoldersStub.calledOnce, true, 'updateWorkspaceFolders should have been called');
324324
onWorkspaceProjectsChangedDisposable.dispose();
325325
});
326+
327+
test('createProject uses values from QuickPick', async () => {
328+
// Arrange: Create a new instance of WorkspaceService
329+
const service = new WorkspaceService();
330+
331+
// Arrange: Stub createProject to observe its call and return a fixed URI
332+
const createProjectStub = sinon.stub(service, 'createProject').resolves(vscode.Uri.file('/tmp/TestProject'));
333+
334+
// Arrange: Prepare the QuickPick items to simulate user selections
335+
const quickPickItems = [
336+
{ label: 'Select Database Project Type', value: 'SQL Server Database', picked: true },
337+
{ label: 'Enter Project Name', value: 'TestProject', picked: true },
338+
{ label: 'Select Project Location', value: '/tmp/TestProject', picked: true },
339+
{ label: 'Select Target Platform', value: 'SQL Server', picked: true },
340+
{ label: 'SDK-style project', value: constants.YesRecommended, picked: true },
341+
{ label: constants.confirmCreateProjectWithBuildTaskDialogName, value: constants.Yes, picked: true },
342+
];
343+
344+
// Arrange: Stub showQuickPick to return each item in order for each call
345+
const quickPickStub = sinon.stub(vscode.window, 'showQuickPick');
346+
quickPickItems.forEach((item, idx) => {
347+
quickPickStub.onCall(idx).resolves(item);
348+
});
349+
350+
// Act: Call createProject directly with values from the simulated QuickPick selections
351+
const projectUri = await service.createProject(
352+
quickPickItems[1].value, // Project name
353+
vscode.Uri.file(quickPickItems[2].value), // Project location as URI
354+
quickPickItems[0].value, // Project type ID
355+
quickPickItems[3].value, // Target platform
356+
quickPickItems[4].picked, // SDK-style project flag
357+
quickPickItems[5].picked // Configure default build flag
358+
);
359+
360+
// Assert: createProject should have been called once
361+
should.strictEqual(createProjectStub.calledOnce, true, 'createProject should have been called once');
362+
// Assert: The returned URI path should match the expected path
363+
should.strictEqual(projectUri.path, '/tmp/TestProject', 'project URI should match the expected path');
364+
// Assert: The arguments passed to createProject should match the simulated QuickPick selections
365+
const callArgs = createProjectStub.getCall(0).args;
366+
should.strictEqual(callArgs[0], quickPickItems[1].value, 'name should match');
367+
should.strictEqual(callArgs[1].path, quickPickItems[2].value, 'location should match');
368+
should.strictEqual(callArgs[2], quickPickItems[0].value, 'projectTypeId should match QuickPick label');
369+
should.strictEqual(callArgs[3], quickPickItems[3].value, 'projectTargetVersion should match');
370+
should.strictEqual(callArgs[4], true, 'sdkStyleProject should match');
371+
should.strictEqual(callArgs[5], true, 'configureDefaultBuild should be true');
372+
373+
// Cleanup: Restore the stubbed showQuickPick method
374+
quickPickStub.restore();
375+
});
326376
});

0 commit comments

Comments
 (0)