Skip to content

Commit df21e0b

Browse files
Rework asset generation prompt to all user to specify 'Don't Ask Again'
1 parent 26cc04a commit df21e0b

File tree

2 files changed

+79
-41
lines changed

2 files changed

+79
-41
lines changed

src/assets.ts

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ interface Operations {
7676

7777
function hasOperations(operations: Operations) {
7878
return operations.addLaunchJson ||
79-
operations.updateTasksJson ||
80-
operations.addLaunchJson;
79+
operations.updateTasksJson ||
80+
operations.addLaunchJson;
8181
}
8282

8383
function getOperations() {
8484
const paths = getPaths();
8585

8686
return getBuildOperations(paths.tasksJsonPath).then(operations =>
87-
getLaunchOperations(paths.launchJsonPath, operations));
87+
getLaunchOperations(paths.launchJsonPath, operations));
8888
}
8989

9090
function getBuildOperations(tasksJsonPath: string) {
@@ -120,15 +120,27 @@ function getLaunchOperations(launchJsonPath: string, operations: Operations) {
120120
});
121121
}
122122

123+
enum PromptResult {
124+
Yes,
125+
No,
126+
Disable
127+
}
128+
129+
interface PromptItem extends vscode.MessageItem {
130+
result: PromptResult
131+
}
132+
123133
function promptToAddAssets() {
124-
return new Promise<boolean>((resolve, reject) => {
125-
const item = { title: 'Yes' }
134+
return new Promise<PromptResult>((resolve, reject) => {
135+
const yesItem: PromptItem = { title: 'Yes', result: PromptResult.Yes };
136+
const noItem: PromptItem = { title: 'Not Now', result: PromptResult.No, isCloseAffordance: true }
137+
const disableItem: PromptItem = { title: "Don't Ask Again", result: PromptResult.Disable };
126138

127-
vscode.window.showInformationMessage('Required assets to build and debug are missing from your project. Add them?', item).then(selection => {
128-
return selection
129-
? resolve(true)
130-
: resolve(false);
131-
});
139+
const projectName = path.basename(vscode.workspace.rootPath);
140+
141+
vscode.window.showWarningMessage(
142+
`Required assets to build and debug are missing from '${projectName}'. Add them?`, disableItem, noItem, yesItem)
143+
.then(selection => resolve(selection.result));
132144
});
133145
}
134146

@@ -208,8 +220,8 @@ function createAttachConfiguration(): AttachConfiguration {
208220
}
209221

210222
function createLaunchJson(projectData: TargetProjectData, isWebProject: boolean): any {
211-
let version = '0.2.0';
212-
if (!isWebProject) {
223+
let version = '0.2.0';
224+
if (!isWebProject) {
213225
return {
214226
version: version,
215227
configurations: [
@@ -249,7 +261,7 @@ function createTasksConfiguration(projectData: TargetProjectData): tasks.TaskCon
249261
command: 'dotnet',
250262
isShellCommand: true,
251263
args: [],
252-
tasks: [ createBuildTaskDescription(projectData) ]
264+
tasks: [createBuildTaskDescription(projectData)]
253265
};
254266
}
255267

@@ -365,35 +377,55 @@ function addLaunchJsonIfNecessary(projectData: TargetProjectData, paths: Paths,
365377
});
366378
}
367379

368-
export function addAssetsIfNecessary(server: OmnisharpServer) {
369-
if (!vscode.workspace.rootPath) {
370-
return;
371-
}
380+
function addAssets(data: TargetProjectData, paths: Paths, operations: Operations) {
381+
const promises = [
382+
addTasksJsonIfNecessary(data, paths, operations),
383+
addLaunchJsonIfNecessary(data, paths, operations)
384+
];
372385

373-
return serverUtils.requestWorkspaceInformation(server).then(info => {
374-
// If there are no .NET Core projects, we won't bother offering to add assets.
375-
if ('DotNet' in info && info.DotNet.Projects.length > 0) {
376-
return getOperations().then(operations => {
377-
if (!hasOperations(operations)) {
378-
return;
379-
}
386+
return Promise.all(promises);
387+
}
380388

381-
promptToAddAssets().then(addAssets => {
382-
if (!addAssets) {
383-
return;
389+
export enum AddAssetResult {
390+
NotApplicable,
391+
Done,
392+
Disable,
393+
Cancelled
394+
}
395+
396+
export function addAssetsIfNecessary(server: OmnisharpServer): Promise<AddAssetResult> {
397+
return new Promise<AddAssetResult>((resolve, reject) => {
398+
if (!vscode.workspace.rootPath) {
399+
return resolve(AddAssetResult.NotApplicable);
400+
}
401+
402+
serverUtils.requestWorkspaceInformation(server).then(info => {
403+
// If there are no .NET Core projects, we won't bother offering to add assets.
404+
if (info.DotNet && info.DotNet.Projects.length > 0) {
405+
return getOperations().then(operations => {
406+
if (!hasOperations(operations)) {
407+
return resolve(AddAssetResult.NotApplicable);
384408
}
385409

386-
const data = findTargetProjectData(info.DotNet.Projects);
387-
const paths = getPaths();
410+
promptToAddAssets().then(result => {
411+
if (result === PromptResult.Disable) {
412+
return resolve(AddAssetResult.Disable);
413+
}
388414

389-
return fs.ensureDirAsync(paths.vscodeFolder).then(() => {
390-
return Promise.all([
391-
addTasksJsonIfNecessary(data, paths, operations),
392-
addLaunchJsonIfNecessary(data, paths, operations)
393-
]);
415+
if (result !== PromptResult.Yes) {
416+
return resolve(AddAssetResult.Cancelled);
417+
}
418+
419+
const data = findTargetProjectData(info.DotNet.Projects);
420+
const paths = getPaths();
421+
422+
return fs.ensureDirAsync(paths.vscodeFolder).then(() =>
423+
addAssets(data, paths, operations).then(() =>
424+
resolve(AddAssetResult.Done)));
394425
});
395426
});
396-
});
397-
}
427+
}
428+
}).catch(err =>
429+
reject(err));
398430
});
399431
}

src/main.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {readOptions} from './omnisharp/options';
2424
import forwardChanges from './features/changeForwarding';
2525
import reportStatus from './features/status';
2626
import * as coreclrdebug from './coreclr-debug/activate';
27-
import {addAssetsIfNecessary} from './assets';
27+
import {addAssetsIfNecessary, AddAssetResult} from './assets';
2828
import * as vscode from 'vscode';
2929
import TelemetryReporter from 'vscode-extension-telemetry';
3030
import {DefinitionMetadataDocumentProvider} from './features/definitionMetadataDocumentProvider';
@@ -81,10 +81,16 @@ export function activate(context: vscode.ExtensionContext): any {
8181
disposables.push(registerCommands(server, context.extensionPath));
8282
disposables.push(reportStatus(server));
8383

84-
disposables.push(server.onServerStart(() => {
85-
// Update or add tasks.json and launch.json
86-
addAssetsIfNecessary(server);
87-
}));
84+
if (!context.workspaceState.get<boolean>('assetPromptDisabled')) {
85+
disposables.push(server.onServerStart(() => {
86+
// Update or add tasks.json and launch.json
87+
addAssetsIfNecessary(server).then(result => {
88+
if (result === AddAssetResult.Disable) {
89+
context.workspaceState.update('assetPromptDisabled', true);
90+
}
91+
});
92+
}));
93+
}
8894

8995
// read and store last solution or folder path
9096
disposables.push(server.onBeforeServerStart(path => context.workspaceState.update('lastSolutionPathOrFolder', path)));

0 commit comments

Comments
 (0)