diff --git a/CHANGELOG.md b/CHANGELOG.md index fdbd26c011c20..ece52bb97ed03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## v0.9.0 +- [task] allowed running existing tasks with temporary, one-time changes + Breaking changes: - [plugin] fixed typo in 'HostedInstanceState' enum from RUNNNING to RUNNING in `plugin-dev` extension diff --git a/packages/plugin-ext/src/plugin/tasks/task-provider.ts b/packages/plugin-ext/src/plugin/tasks/task-provider.ts index 0a1e12cb8a34f..6fc22fad22019 100644 --- a/packages/plugin-ext/src/plugin/tasks/task-provider.ts +++ b/packages/plugin-ext/src/plugin/tasks/task-provider.ts @@ -16,12 +16,9 @@ import * as theia from '@theia/plugin'; import * as Converter from '../type-converters'; -import { ObjectIdentifier } from '../../common/object-identifier'; import { TaskDto } from '../../common'; export class TaskProviderAdapter { - private cacheId = 0; - private cache = new Map(); constructor(private readonly provider: theia.TaskProvider) { } @@ -37,9 +34,6 @@ export class TaskProviderAdapter { continue; } - const id = this.cacheId++; - ObjectIdentifier.mixin(data, id); - this.cache.set(id, task); result.push(data); } return result; @@ -50,9 +44,7 @@ export class TaskProviderAdapter { if (typeof this.provider.resolveTask !== 'function') { return Promise.resolve(undefined); } - const id = ObjectIdentifier.of(task); - const cached = this.cache.get(id); - const item = cached ? cached : Converter.toTask(task); + const item = Converter.toTask(task); if (!item) { return Promise.resolve(undefined); } diff --git a/packages/task/package.json b/packages/task/package.json index f38b00a10b9ec..358634eaaeeac 100644 --- a/packages/task/package.json +++ b/packages/task/package.json @@ -11,6 +11,7 @@ "@theia/terminal": "^0.8.0", "@theia/variable-resolver": "^0.8.0", "@theia/workspace": "^0.8.0", + "deepmerge": "2.0.1", "jsonc-parser": "^2.0.2" }, "publishConfig": { diff --git a/packages/task/src/browser/task-frontend-contribution.ts b/packages/task/src/browser/task-frontend-contribution.ts index ae4fe3eb082e8..d2c09f7566d33 100644 --- a/packages/task/src/browser/task-frontend-contribution.ts +++ b/packages/task/src/browser/task-frontend-contribution.ts @@ -179,9 +179,9 @@ export class TaskFrontendContribution implements CommandContribution, MenuContri isEnabled: () => true, // tslint:disable-next-line:no-any execute: (...args: any[]) => { - const [source, label] = args; + const [source, label, overrides] = args; if (source && label) { - return this.taskService.run(source, label); + return this.taskService.run(source, label, overrides); } return this.quickOpenTask.open(); } diff --git a/packages/task/src/browser/task-service.ts b/packages/task/src/browser/task-service.ts index 45c445b1744ca..e3ac0567e7bb9 100644 --- a/packages/task/src/browser/task-service.ts +++ b/packages/task/src/browser/task-service.ts @@ -32,6 +32,8 @@ import { ProvidedTaskConfigurations } from './provided-task-configurations'; import { Range } from 'vscode-languageserver-types'; import URI from '@theia/core/lib/common/uri'; +const deepmerge: (args: object[]) => object = require('deepmerge').default.all; + @injectable() export class TaskService implements TaskConfigurationClient { /** @@ -250,8 +252,11 @@ export class TaskService implements TaskConfigurationClient { /** * Runs a task, by the source and label of the task configuration. * It looks for configured and provided tasks. + * The last parameter may contain additional task type specific properties + * which are used only for this request over persistent configuration of the task. */ - async run(source: string, taskLabel: string): Promise { + // tslint:disable-next-line:no-any + async run(source: string, taskLabel: string, overrides?: { [key: string]: any }): Promise { let task = await this.getProvidedTask(source, taskLabel); if (!task) { task = this.taskConfigurations.getTask(source, taskLabel); @@ -261,6 +266,10 @@ export class TaskService implements TaskConfigurationClient { } } + if (overrides) { + task = deepmerge([task, overrides]); + } + this.runTask(task); }