Skip to content

Commit

Permalink
fix cpp task labels and ensure they can be run
Browse files Browse the repository at this point in the history
This pull request fixes the following problems:
- cpp task labels are displayed as "undefined: xxxx" and it is wrong
- Theia always fails to run tasks defined in cpp extension. When they are started from the "Run Task", users either get "launch config not found" error, or an exception that says "Error attaching to terminal".

fixed #6204
  • Loading branch information
Liang Huang committed Oct 20, 2019
1 parent f255f5a commit c85db14
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cpp/src/browser/cpp-task-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('CppTaskProvider', function (): void {

const resolvedTask = await taskProvider.resolveTask(tasks[0]);
expect(resolvedTask.type === 'shell');
expect((<ProcessTaskConfiguration>resolvedTask).cwd).to.be.equal('/tmp/build2');
expect((<ProcessTaskConfiguration>resolvedTask).options!.cwd).to.be.equal('/tmp/build2');
expect((<ProcessTaskConfiguration>resolvedTask).command).to.be.equal('very');
expect((<ProcessTaskConfiguration>resolvedTask).args).to.deep.equal(['complex', 'command']);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/cpp/src/browser/cpp-task-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ export class CppTaskProvider implements TaskContribution, TaskProvider, TaskReso
type: 'shell',
command,
args,
cwd: task.config.directory,
options: {
cwd: task.config.directory,
}
};
return resolver.resolveTask(resolvedTask);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class TaskRunQuickOpenItem extends QuickOpenGroupItem {
}

if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(this.task)) {
this.taskService.run(this.task.source, this.task.label);
this.taskService.run(this.task.source || this.task._source, this.task.label);
} else {
this.taskService.run(this.task._source, this.task.label);
}
Expand Down
10 changes: 7 additions & 3 deletions packages/task/src/browser/task-name-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { inject, injectable } from 'inversify';
import { TaskConfiguration } from '../common';
import { TaskConfiguration, ContributedTaskConfiguration } from '../common';
import { TaskDefinitionRegistry } from './task-definition-registry';

@injectable()
Expand All @@ -28,11 +28,15 @@ export class TaskNameResolver {
* It is aligned with VS Code.
*/
resolve(task: TaskConfiguration): string {
if (this.taskDefinitionRegistry.getDefinition(task)) {
return `${task.source}: ${task.label}`;
if (this.isDetectedTask(task)) {
return `${task.source || task._source}: ${task.label}`;
}

// it is a hack, when task is customized but extension is absent
return task.label || `${task.type}: ${task.task}`;
}

private isDetectedTask(task: TaskConfiguration): task is ContributedTaskConfiguration {
return !!this.taskDefinitionRegistry.getDefinition(task);
}
}

0 comments on commit c85db14

Please sign in to comment.