Skip to content

Commit 6cf558d

Browse files
authored
make task setting keys into an enum (microsoft#154322)
1 parent d68ae55 commit 6cf558d

File tree

5 files changed

+57
-31
lines changed

5 files changed

+57
-31
lines changed

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ import {
5353
ITaskSet, TaskGroup, ExecutionEngine, JsonSchemaVersion, TaskSourceKind,
5454
TaskSorter, ITaskIdentifier, TASK_RUNNING_STATE, TaskRunSource,
5555
KeyedTaskIdentifier as KeyedTaskIdentifier, TaskDefinition, RuntimeType,
56-
USER_TASKS_GROUP_KEY
56+
USER_TASKS_GROUP_KEY,
57+
TaskSettingId,
58+
TasksSchemaProperties
5759
} from 'vs/workbench/contrib/tasks/common/tasks';
5860
import { ITaskService, ITaskProvider, IProblemMatcherRunOptions, ICustomizationProperties, ITaskFilter, IWorkspaceFolderTaskResult, CustomExecutionSupportedContext, ShellExecutionSupportedContext, ProcessExecutionSupportedContext } from 'vs/workbench/contrib/tasks/common/taskService';
5961
import { getTemplates as getTaskTemplates } from 'vs/workbench/contrib/tasks/common/taskTemplates';
@@ -1093,7 +1095,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
10931095
}
10941096

10951097
private _isProvideTasksEnabled(): boolean {
1096-
const settingValue = this._configurationService.getValue('task.autoDetect');
1098+
const settingValue = this._configurationService.getValue(TaskSettingId.AutoDetect);
10971099
return settingValue === 'on';
10981100
}
10991101

@@ -1688,7 +1690,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
16881690
Prompt = 'prompt'
16891691
}
16901692

1691-
const saveBeforeRunTaskConfig: SaveBeforeRunConfigOptions = this._configurationService.getValue('task.saveBeforeRun');
1693+
const saveBeforeRunTaskConfig: SaveBeforeRunConfigOptions = this._configurationService.getValue(TaskSettingId.SaveBeforeRun);
16921694

16931695
if (saveBeforeRunTaskConfig === SaveBeforeRunConfigOptions.Never) {
16941696
return false;
@@ -3523,11 +3525,11 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
35233525
}
35243526

35253527
const configTasks: (TaskConfig.ICustomTask | TaskConfig.IConfiguringTask)[] = [];
3526-
const suppressTaskName = !!this._configurationService.getValue('tasks.suppressTaskName', { resource: folder.uri });
3528+
const suppressTaskName = !!this._configurationService.getValue(TasksSchemaProperties.SuppressTaskName, { resource: folder.uri });
35273529
const globalConfig = {
3528-
windows: <ICommandUpgrade>this._configurationService.getValue('tasks.windows', { resource: folder.uri }),
3529-
osx: <ICommandUpgrade>this._configurationService.getValue('tasks.osx', { resource: folder.uri }),
3530-
linux: <ICommandUpgrade>this._configurationService.getValue('tasks.linux', { resource: folder.uri })
3530+
windows: <ICommandUpgrade>this._configurationService.getValue(TasksSchemaProperties.Windows, { resource: folder.uri }),
3531+
osx: <ICommandUpgrade>this._configurationService.getValue(TasksSchemaProperties.Osx, { resource: folder.uri }),
3532+
linux: <ICommandUpgrade>this._configurationService.getValue(TasksSchemaProperties.Linux, { resource: folder.uri })
35313533
};
35323534
tasks.get(folder).forEach(task => {
35333535
const configTask = this._upgradeTask(task, suppressTaskName, globalConfig);
@@ -3539,14 +3541,14 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
35393541
this._workspaceTasksPromise = undefined;
35403542
await this._writeConfiguration(folder, 'tasks.tasks', configTasks);
35413543
await this._writeConfiguration(folder, 'tasks.version', '2.0.0');
3542-
if (this._configurationService.getValue('tasks.showOutput', { resource: folder.uri })) {
3543-
await this._configurationService.updateValue('tasks.showOutput', undefined, { resource: folder.uri });
3544+
if (this._configurationService.getValue(TasksSchemaProperties.ShowOutput, { resource: folder.uri })) {
3545+
await this._configurationService.updateValue(TasksSchemaProperties.ShowOutput, undefined, { resource: folder.uri });
35443546
}
3545-
if (this._configurationService.getValue('tasks.isShellCommand', { resource: folder.uri })) {
3546-
await this._configurationService.updateValue('tasks.isShellCommand', undefined, { resource: folder.uri });
3547+
if (this._configurationService.getValue(TasksSchemaProperties.IsShellCommand, { resource: folder.uri })) {
3548+
await this._configurationService.updateValue(TasksSchemaProperties.IsShellCommand, undefined, { resource: folder.uri });
35473549
}
3548-
if (this._configurationService.getValue('tasks.suppressTaskName', { resource: folder.uri })) {
3549-
await this._configurationService.updateValue('tasks.suppressTaskName', undefined, { resource: folder.uri });
3550+
if (this._configurationService.getValue(TasksSchemaProperties.SuppressTaskName, { resource: folder.uri })) {
3551+
await this._configurationService.updateValue(TasksSchemaProperties.SuppressTaskName, undefined, { resource: folder.uri });
35503552
}
35513553
}
35523554
this._updateSetup();

src/vs/workbench/contrib/tasks/browser/task.contribution.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { StatusbarAlignment, IStatusbarService, IStatusbarEntryAccessor, IStatus
2020

2121
import { IOutputChannelRegistry, Extensions as OutputExt } from 'vs/workbench/services/output/common/output';
2222

23-
import { ITaskEvent, TaskEventKind, TaskGroup, TASKS_CATEGORY, TASK_RUNNING_STATE } from 'vs/workbench/contrib/tasks/common/tasks';
23+
import { ITaskEvent, TaskEventKind, TaskGroup, TaskSettingId, TASKS_CATEGORY, TASK_RUNNING_STATE } from 'vs/workbench/contrib/tasks/common/tasks';
2424
import { ITaskService, ProcessExecutionSupportedContext, ShellExecutionSupportedContext } from 'vs/workbench/contrib/tasks/common/taskService';
2525

2626
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions';
@@ -431,7 +431,7 @@ configurationRegistry.registerConfiguration({
431431
title: nls.localize('tasksConfigurationTitle', "Tasks"),
432432
type: 'object',
433433
properties: {
434-
'task.problemMatchers.neverPrompt': {
434+
[TaskSettingId.ProblemMatchersNeverPrompt]: {
435435
markdownDescription: nls.localize('task.problemMatchers.neverPrompt', "Configures whether to show the problem matcher prompt when running a task. Set to `true` to never prompt, or use a dictionary of task types to turn off prompting only for specific task types."),
436436
'oneOf': [
437437
{
@@ -453,13 +453,13 @@ configurationRegistry.registerConfiguration({
453453
],
454454
default: false
455455
},
456-
'task.autoDetect': {
456+
[TaskSettingId.AutoDetect]: {
457457
markdownDescription: nls.localize('task.autoDetect', "Controls enablement of `provideTasks` for all task provider extension. If the Tasks: Run Task command is slow, disabling auto detect for task providers may help. Individual extensions may also provide settings that disable auto detection."),
458458
type: 'string',
459459
enum: ['on', 'off'],
460460
default: 'on'
461461
},
462-
'task.slowProviderWarning': {
462+
[TaskSettingId.SlowProviderWarning]: {
463463
markdownDescription: nls.localize('task.slowProviderWarning', "Configures whether a warning is shown when a provider is slow"),
464464
'oneOf': [
465465
{
@@ -476,32 +476,32 @@ configurationRegistry.registerConfiguration({
476476
],
477477
default: true
478478
},
479-
'task.quickOpen.history': {
479+
[TaskSettingId.QuickOpenHistory]: {
480480
markdownDescription: nls.localize('task.quickOpen.history', "Controls the number of recent items tracked in task quick open dialog."),
481481
type: 'number',
482482
default: 30, minimum: 0, maximum: 30
483483
},
484-
'task.quickOpen.detail': {
484+
[TaskSettingId.QuickOpenDetail]: {
485485
markdownDescription: nls.localize('task.quickOpen.detail', "Controls whether to show the task detail for tasks that have a detail in task quick picks, such as Run Task."),
486486
type: 'boolean',
487487
default: true
488488
},
489-
'task.quickOpen.skip': {
489+
[TaskSettingId.QuickOpenSkip]: {
490490
type: 'boolean',
491491
description: nls.localize('task.quickOpen.skip', "Controls whether the task quick pick is skipped when there is only one task to pick from."),
492492
default: false
493493
},
494-
'task.quickOpen.showAll': {
494+
[TaskSettingId.QuickOpenShowAll]: {
495495
type: 'boolean',
496496
description: nls.localize('task.quickOpen.showAll', "Causes the Tasks: Run Task command to use the slower \"show all\" behavior instead of the faster two level picker where tasks are grouped by provider."),
497497
default: false
498498
},
499-
'task.showDecorations': {
499+
[TaskSettingId.ShowDecorations]: {
500500
type: 'boolean',
501501
description: nls.localize('task.showDecorations', "Shows decorations at points of interest in the terminal buffer such as the first problem found via a watch task. Note that this will only take effect for future tasks."),
502502
default: true
503503
},
504-
'task.saveBeforeRun': {
504+
[TaskSettingId.SaveBeforeRun]: {
505505
markdownDescription: nls.localize(
506506
'task.saveBeforeRun',
507507
'Save all dirty editors before running a task.'

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { IOutputService } from 'vs/workbench/services/output/common/output';
3131
import { StartStopProblemCollector, WatchingProblemCollector, ProblemCollectorEventKind, ProblemHandlingStrategy } from 'vs/workbench/contrib/tasks/common/problemCollectors';
3232
import {
3333
Task, CustomTask, ContributedTask, RevealKind, CommandOptions, IShellConfiguration, RuntimeType, PanelKind,
34-
TaskEvent, TaskEventKind, IShellQuotingOptions, ShellQuoting, CommandString, ICommandConfiguration, IExtensionTaskSource, TaskScope, RevealProblemKind, DependsOrder, TaskSourceKind, InMemoryTask, ITaskEvent
34+
TaskEvent, TaskEventKind, IShellQuotingOptions, ShellQuoting, CommandString, ICommandConfiguration, IExtensionTaskSource, TaskScope, RevealProblemKind, DependsOrder, TaskSourceKind, InMemoryTask, ITaskEvent, TaskSettingId
3535
} from 'vs/workbench/contrib/tasks/common/tasks';
3636
import {
3737
ITaskSystem, ITaskSummary, ITaskExecuteResult, TaskExecuteKind, TaskError, TaskErrors, ITaskResolver,
@@ -209,10 +209,10 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
209209
private readonly _onDidStateChange: Emitter<ITaskEvent>;
210210

211211
get taskShellIntegrationStartSequence(): string {
212-
return this._configurationService.getValue('task.showDecorations') ? VSCodeSequence(VSCodeOscPt.PromptStart) + VSCodeSequence(VSCodeOscPt.Property, `${VSCodeOscProperty.Task}=True`) + VSCodeSequence(VSCodeOscPt.CommandStart) : '';
212+
return this._configurationService.getValue(TaskSettingId.ShowDecorations) ? VSCodeSequence(VSCodeOscPt.PromptStart) + VSCodeSequence(VSCodeOscPt.Property, `${VSCodeOscProperty.Task}=True`) + VSCodeSequence(VSCodeOscPt.CommandStart) : '';
213213
}
214214
get taskShellIntegrationOutputSequence(): string {
215-
return this._configurationService.getValue('task.showDecorations') ? VSCodeSequence(VSCodeOscPt.CommandExecuted) : '';
215+
return this._configurationService.getValue(TaskSettingId.ShowDecorations) ? VSCodeSequence(VSCodeOscPt.CommandExecuted) : '';
216216
}
217217

218218
constructor(

src/vs/workbench/contrib/tasks/common/tasks.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,29 @@ export namespace KeyedTaskIdentifier {
11901190
}
11911191
}
11921192

1193+
export const enum TaskSettingId {
1194+
AutoDetect = 'task.autoDetect',
1195+
SaveBeforeRun = 'task.saveBeforeRun',
1196+
ShowDecorations = 'task.showDecorations',
1197+
ProblemMatchersNeverPrompt = 'task.problemMatchers.neverPrompt',
1198+
SlowProviderWarning = 'task.slowProviderWarning',
1199+
QuickOpenHistory = 'task.quickOpen.history',
1200+
QuickOpenDetail = 'task.quickOpen.detail',
1201+
QuickOpenSkip = 'task.quickOpen.skip',
1202+
QuickOpenShowAll = 'task.quickOpen.showAll'
1203+
}
1204+
1205+
export const enum TasksSchemaProperties {
1206+
Tasks = 'tasks',
1207+
SuppressTaskName = 'tasks.suppressTaskName',
1208+
Windows = 'tasks.windows',
1209+
Osx = 'tasks.osx',
1210+
Linux = 'tasks.linux',
1211+
ShowOutput = 'tasks.showOutput',
1212+
IsShellCommand = 'tasks.isShellCommand',
1213+
ServiceTestSetting = 'tasks.service.testSetting',
1214+
}
1215+
11931216
export namespace TaskDefinition {
11941217
export function createTaskIdentifier(external: ITaskIdentifier, reporter: { error(message: string): void }): KeyedTaskIdentifier | undefined {
11951218
const definition = TaskDefinitionRegistry.get(external.type);

src/vs/workbench/services/configuration/test/browser/configurationService.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { FilePolicyService } from 'vs/platform/policy/common/filePolicyService';
5050
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
5151
import { UserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfileService';
5252
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
53+
import { TasksSchemaProperties } from 'vs/workbench/contrib/tasks/common/tasks';
5354

5455
function convertToWorkspacePayload(folder: URI): ISingleFolderWorkspaceIdentifier {
5556
return {
@@ -1096,7 +1097,7 @@ suite('WorkspaceConfigurationService - Folder', () => {
10961097

10971098
test('update workspace configuration', () => {
10981099
return testObject.updateValue('tasks.service.testSetting', 'value', ConfigurationTarget.WORKSPACE)
1099-
.then(() => assert.strictEqual(testObject.getValue('tasks.service.testSetting'), 'value'));
1100+
.then(() => assert.strictEqual(testObject.getValue(TasksSchemaProperties.ServiceTestSetting), 'value'));
11001101
});
11011102

11021103
test('update resource configuration', () => {
@@ -1150,7 +1151,7 @@ suite('WorkspaceConfigurationService - Folder', () => {
11501151

11511152
test('update tasks configuration', () => {
11521153
return testObject.updateValue('tasks', { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }, ConfigurationTarget.WORKSPACE)
1153-
.then(() => assert.deepStrictEqual(testObject.getValue('tasks'), { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }));
1154+
.then(() => assert.deepStrictEqual(testObject.getValue(TasksSchemaProperties.Tasks), { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }));
11541155
});
11551156

11561157
test('update user configuration should trigger change event before promise is resolve', () => {
@@ -1994,7 +1995,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
19941995
};
19951996
await jsonEditingServce.write((workspaceContextService.getWorkspace().configuration!), [{ path: ['tasks'], value: expectedTasksConfiguration }], true);
19961997
await testObject.reloadConfiguration();
1997-
const actual = testObject.getValue('tasks');
1998+
const actual = testObject.getValue(TasksSchemaProperties.Tasks);
19981999
assert.deepStrictEqual(actual, expectedTasksConfiguration);
19992000
});
20002001

@@ -2119,7 +2120,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
21192120
test('update tasks configuration in a folder', async () => {
21202121
const workspace = workspaceContextService.getWorkspace();
21212122
await testObject.updateValue('tasks', { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }, { resource: workspace.folders[0].uri }, ConfigurationTarget.WORKSPACE_FOLDER);
2122-
assert.deepStrictEqual(testObject.getValue('tasks', { resource: workspace.folders[0].uri }), { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] });
2123+
assert.deepStrictEqual(testObject.getValue(TasksSchemaProperties.Tasks, { resource: workspace.folders[0].uri }), { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] });
21232124
});
21242125

21252126
test('update launch configuration in a workspace', async () => {
@@ -2132,7 +2133,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
21322133
const workspace = workspaceContextService.getWorkspace();
21332134
const tasks = { 'version': '2.0.0', tasks: [{ 'label': 'myTask' }] };
21342135
await testObject.updateValue('tasks', tasks, { resource: workspace.folders[0].uri }, ConfigurationTarget.WORKSPACE, true);
2135-
assert.deepStrictEqual(testObject.getValue('tasks'), tasks);
2136+
assert.deepStrictEqual(testObject.getValue(TasksSchemaProperties.Tasks), tasks);
21362137
});
21372138

21382139
test('configuration of newly added folder is available on configuration change event', async () => {

0 commit comments

Comments
 (0)