diff --git a/packages/plugin-ext/src/plugin/type-converters.spec.ts b/packages/plugin-ext/src/plugin/type-converters.spec.ts index 996cb71926f3f..f286831244000 100644 --- a/packages/plugin-ext/src/plugin/type-converters.spec.ts +++ b/packages/plugin-ext/src/plugin/type-converters.spec.ts @@ -169,7 +169,8 @@ describe('Type converters:', () => { }); describe('convert tasks:', () => { - const type = 'shell'; + const customType = 'custom'; + const shellType = 'shell'; const label = 'yarn build'; const source = 'source'; const command = 'yarn'; @@ -178,7 +179,7 @@ describe('Type converters:', () => { const additionalProperty = 'some property'; const shellTaskDto: ProcessTaskDto = { - type, + type: shellType, label, source, scope: undefined, @@ -193,7 +194,7 @@ describe('Type converters:', () => { name: label, source, definition: { - type, + type: shellType, additionalProperty }, execution: { @@ -206,7 +207,7 @@ describe('Type converters:', () => { }; const taskDtoWithCommandLine: ProcessTaskDto = { - type, + type: shellType, label, source, scope: undefined, @@ -220,7 +221,7 @@ describe('Type converters:', () => { name: label, source, definition: { - type + type: shellType }, execution: { commandLine: 'yarn run build', @@ -230,6 +231,34 @@ describe('Type converters:', () => { } }; + const customTaskDto: ProcessTaskDto = { + type: customType, + label, + source, + scope: undefined, + command, + args, + cwd, + options: {}, + additionalProperty + }; + + const customPluginTask: theia.Task = { + name: label, + source, + definition: { + type: customType, + additionalProperty + }, + execution: { + command, + args, + options: { + cwd + } + } + }; + it('should convert to task dto', () => { // when const result: TaskDto | undefined = Converter.fromTask(shellPluginTask); @@ -256,6 +285,24 @@ describe('Type converters:', () => { assert.notEqual(result, undefined); assert.deepEqual(result, taskDtoWithCommandLine); }); + + it('should convert task with custom type to dto', () => { + // when + const result: TaskDto | undefined = Converter.fromTask(customPluginTask); + + // then + assert.notEqual(result, undefined); + assert.deepEqual(result, customTaskDto); + }); + + it('should convert task with custom type from dto', () => { + // when + const result: theia.Task = Converter.toTask(customTaskDto); + + // then + assert.notEqual(result, undefined); + assert.deepEqual(result, customPluginTask); + }); }); describe('Webview Panel Show Options:', () => { diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index 8219cc0778132..0c2ecac21f765 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -651,7 +651,8 @@ export function toTask(taskDto: TaskDto): theia.Task { result.execution = getProcessExecution(taskDto as ProcessTaskDto); } - if (taskType === 'shell') { + const execution = { command, args, options }; + if (taskType === 'shell' || types.ShellExecution.is(execution)) { result.execution = getShellExecution(taskDto as ProcessTaskDto); } diff --git a/packages/task/src/browser/quick-open-task.ts b/packages/task/src/browser/quick-open-task.ts index 330481da74c55..428cd968aba1d 100644 --- a/packages/task/src/browser/quick-open-task.ts +++ b/packages/task/src/browser/quick-open-task.ts @@ -62,9 +62,9 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { async init(): Promise { const recentTasks = this.taskService.recentTasks; const configuredTasks = this.taskService.getConfiguredTasks(); - const providedTasks = await this.taskService.getProvidedTasks(); + const detectedTasks = await this.taskService.getProvidedTasks(); - const { filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, providedTasks); + const { filteredRecentTasks, filteredConfiguredTasks, filteredDetectedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, detectedTasks); const stat = this.workspaceService.workspace; const isMulti = stat ? !stat.isDirectory : false; this.items = []; @@ -83,7 +83,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { : index === 0 ? true : false ) })), - ...filteredProvidedTasks.map((task, index) => + ...filteredDetectedTasks.map((task, index) => new TaskRunQuickOpenItem(task, this.taskService, isMulti, { groupLabel: index === 0 ? 'detected tasks' : undefined, showBorder: ( @@ -186,36 +186,44 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { return `Task id: ${task.taskId}, label: ${task.config.label}`; } - private getFilteredTasks(recentTasks: TaskConfiguration[], configuredTasks: TaskConfiguration[], providedTasks: TaskConfiguration[]) - : { filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredProvidedTasks: TaskConfiguration[] } { + private getFilteredTasks(recentTasks: TaskConfiguration[], configuredTasks: TaskConfiguration[], detectedTasks: TaskConfiguration[]) + : { filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredDetectedTasks: TaskConfiguration[] } { const filteredRecentTasks: TaskConfiguration[] = []; - recentTasks.forEach(recent => { - const exist = [...configuredTasks, ...providedTasks].some(t => TaskConfiguration.equals(recent, t)); - if (exist) { - filteredRecentTasks.push(recent); + for (const recent of recentTasks) { + const taskConfig = this.findConfig(recent.label, configuredTasks) || this.findConfig(recent.label, detectedTasks); + if (!taskConfig) { + continue; } - }); - const filteredProvidedTasks: TaskConfiguration[] = []; - providedTasks.forEach(provided => { - const exist = [...filteredRecentTasks, ...configuredTasks].some(t => TaskConfiguration.equals(provided, t)); + const exist = filteredRecentTasks.some(task => TaskConfiguration.equals(task, taskConfig)); if (!exist) { - filteredProvidedTasks.push(provided); + filteredRecentTasks.push(taskConfig); } - }); + } const filteredConfiguredTasks: TaskConfiguration[] = []; configuredTasks.forEach(configured => { - const exist = filteredRecentTasks.some(t => TaskConfiguration.equals(configured, t)); + const exist = filteredRecentTasks.some(recent => TaskConfiguration.equals(configured, recent)); if (!exist) { filteredConfiguredTasks.push(configured); } }); - return { - filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks - }; + const filteredDetectedTasks: TaskConfiguration[] = []; + detectedTasks.forEach(detected => { + const exist = filteredRecentTasks.some(recent => TaskConfiguration.equals(detected, recent)) || + configuredTasks.some(configured => configured.label === detected.label); + if (!exist) { + filteredDetectedTasks.push(detected); + } + }); + + return { filteredRecentTasks, filteredConfiguredTasks, filteredDetectedTasks }; + } + + private findConfig(label: string, configs: TaskConfiguration[]): TaskConfiguration | undefined { + return configs.find(task => label === task.label); } } diff --git a/packages/task/src/browser/task-configurations.ts b/packages/task/src/browser/task-configurations.ts index 43e097cda2627..d57080c431dbb 100644 --- a/packages/task/src/browser/task-configurations.ts +++ b/packages/task/src/browser/task-configurations.ts @@ -234,7 +234,7 @@ export class TaskConfigurations implements Disposable { console.error(`Error parsing ${uri}: error: ${e.error}, length: ${e.length}, offset: ${e.offset}`); } } else { - return this.filterDuplicates(tasks['tasks']).map(t => Object.assign(t, { _source: t.source || this.getSourceFolderFromConfigUri(uri) })); + return this.filterDuplicates(tasks['tasks']).map(t => Object.assign(t, { _source: this.getSourceFolderFromConfigUri(uri) })); } } catch (err) { console.error(`Error(s) reading config file: ${uri}`); @@ -267,7 +267,7 @@ export class TaskConfigurations implements Disposable { await this.fileSystem.createFile(configFileUri); } - const { _source, $ident, ...preparedTask } = task; + const { source, _source, _scope, $ident, ...preparedTask } = task; try { const response = await this.fileSystem.resolveContent(configFileUri); const content = response.content;