Skip to content

Commit

Permalink
add task extension
Browse files Browse the repository at this point in the history
Fixes eclipse-theia#686

Signed-off-by: Marc Dumais <[email protected]>
  • Loading branch information
marcdumais-work committed Dec 5, 2017
1 parent c6e1247 commit 6ca04f9
Show file tree
Hide file tree
Showing 27 changed files with 1,810 additions and 6 deletions.
73 changes: 73 additions & 0 deletions .theia/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
// Some sample Theia development tasks
"tasks": [
{
"label": "[Task] short runnning test task (~3s)",
"processType": "terminal",
"cwd": "$workspace/packages/task/src/node/test-resources/",
"processOptions": {
"command": "./task",
"args": [
"1",
"2",
"3"
]
},
"windowsProcessOptions": {
"command": "cmd.exe",
"args": [
"/c",
"task.bat",
"abc"
]
}
},
{
"label": "[Task] long runnning test task (~300s)",
"processType": "terminal",
"cwd": "$workspace/packages/task/src/node/test-resources/",
"processOptions": {
"command": "./task-long-running",
"args": []
},
"windowsProcessOptions": {
"command": "cmd.exe",
"args": [
"/c",
"task-long-running.bat"
]
}
},
{
"label": "[Task] recursively list files from workspace root",
"processType": "terminal",
"cwd": "$workspace",
"processOptions": {
"command": "ls",
"args": [
"-alR"
]
},
"windowsProcessOptions": {
"command": "cmd.exe",
"args": [
"/c",
"dir",
"/s"
]
}
},
{
"label": "[Task] Echo a string",
"processType": "terminal",
"cwd": "$workspace",
"processOptions": {
"command": "bash",
"args": [
"-c",
"echo 1 2 3"
]
}
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"packages/process/coverage/lcov.info",
"packages/python/coverage/lcov.info",
"packages/terminal/coverage/lcov.info",
"packages/workspace/coverage/lcov.info"
"packages/workspace/coverage/lcov.info",
"packages/task/coverage/lcov.info"
],
"lcov.watch": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ module.exports = {
{
test: /\\.js$/,
enforce: 'pre',
loader: 'source-map-loader'
loader: 'source-map-loader',
exclude: /jsonc-parser/
},
{
test: /\\.woff(2)?(\\?v=[0-9]\\.[0-9]\\.[0-9])?$/,
loader: "url-loader?limit=10000&mimetype=application/font-woff"
}
],
noParse: /vscode-languageserver-types|vscode-uri/
noParse: /vscode-languageserver-types|vscode-uri|jsonc-parser/
},
resolve: {
extensions: ['.js']${this.ifMonaco(() => `,
Expand Down
3 changes: 2 additions & 1 deletion examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"@theia/terminal": "^0.2.4",
"@theia/typescript": "^0.2.4",
"@theia/userstorage": "^0.2.4",
"@theia/workspace": "^0.2.4"
"@theia/workspace": "^0.2.4",
"@theia/task": "^0.2.4"
},
"scripts": {
"prepare": "yarn run clean && yarn build",
Expand Down
3 changes: 2 additions & 1 deletion examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"@theia/terminal": "^0.2.4",
"@theia/typescript": "^0.2.4",
"@theia/userstorage": "^0.2.4",
"@theia/workspace": "^0.2.4"
"@theia/workspace": "^0.2.4",
"@theia/task": "^0.2.4"
},
"scripts": {
"prepare": "yarn run clean && yarn build",
Expand Down
4 changes: 3 additions & 1 deletion packages/process/src/node/terminal-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class TerminalProcess extends Process {
options.args,
options.options);

this.terminal.on('exit', this.emitOnExit.bind(this));
this.terminal.on('exit', (code: number, signal: number) => {
this.emitOnExit(code, signal.toString());
});

this.terminal.on('data', (data: string) => {
ringBuffer.enq(data);
Expand Down
10 changes: 10 additions & 0 deletions packages/task/compile.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../configs/base.tsconfig",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
]
}
52 changes: 52 additions & 0 deletions packages/task/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@theia/task",
"version": "0.2.4",
"description": "Theia - Task extension",
"dependencies": {
"@theia/core": "^0.2.4",
"@theia/markers": "^0.2.4",
"@theia/process": "^0.2.4",
"@theia/terminal": "^0.2.4",
"@theia/workspace": "^0.2.4",
"jsonc-parser": "^1.0.0"
},
"publishConfig": {
"access": "public"
},
"theiaExtensions": [
{
"frontend": "lib/browser/task-frontend-module",
"backend": "lib/node/task-backend-module"
}
],
"keywords": [
"theia-extension"
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/theia-ide/theia.git"
},
"bugs": {
"url": "https://github.com/theia-ide/theia/issues"
},
"homepage": "https://github.com/theia-ide/theia",
"files": [
"lib",
"src"
],
"scripts": {
"prepare": "yarn run clean && yarn run build",
"clean": "theiaext clean",
"build": "theiaext build",
"watch": "theiaext watch",
"test": "theiaext test",
"docs": "theiaext docs"
},
"devDependencies": {
"@theia/ext-scripts": "^0.2.0"
},
"nyc": {
"extends": "../../configs/nyc.json"
}
}
8 changes: 8 additions & 0 deletions packages/task/src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright (C) 2017 Ericsson and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

export * from './task-service';
133 changes: 133 additions & 0 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright (C) 2017 Ericsson and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { inject, injectable } from "inversify";
import { TaskService } from './task-service';
import { TaskInfo } from '../common/task-protocol';
import { QuickOpenService, QuickOpenModel, QuickOpenItem, QuickOpenMode } from '@theia/core/lib/browser/quick-open/';

@injectable()
export class QuickOpenTask implements QuickOpenModel {

private items: QuickOpenItem[];

constructor(
@inject(TaskService) protected readonly taskService: TaskService,
@inject(QuickOpenService) protected readonly quickOpenService: QuickOpenService
) { }

open(): void {
this.items = [];

this.taskService.getTasks().then(tasks => {
for (const task of tasks) {
this.items.push(new TaskRunQuickOpenItem(task, this.taskService));
}
this.quickOpenService.open(this, {
placeholder: 'Type the name of a task you want to execute',
fuzzyMatchLabel: true,
fuzzySort: true
});
});
}

attach(): void {
this.items = [];

this.taskService.getRunningTasks().then(tasks => {
for (const task of tasks) {
// can only attach to terminal processes
if (task.terminalId) {
this.items.push(
new TaskAttachQuickOpenItem(
task,
this.getRunningTaskLabel(task),
this.taskService
)
);
}
}
this.quickOpenService.open(this, {
placeholder: 'Choose task to open',
fuzzyMatchLabel: true,
fuzzySort: true
});
});
}

public getItems(lookFor: string): QuickOpenItem[] {
return this.items;
}

onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): void {
acceptor(this.items);
}

protected getRunningTaskLabel(task: TaskInfo): string {
return `Task id: ${task.taskId}, label: ${task.label}`;
}

}

export class TaskRunQuickOpenItem extends QuickOpenItem {

private activeElement: HTMLElement;

constructor(
protected readonly taskLabel: string,
protected taskService: TaskService
) {
super();
this.activeElement = window.document.activeElement as HTMLElement;
}

getLabel(): string {
return this.taskLabel!;
}

run(mode: QuickOpenMode): boolean {
if (mode !== QuickOpenMode.OPEN) {
return false;
}
// reset focus on the previously active element.
this.activeElement.focus();
this.taskService.run(this.taskLabel);

return true;
}
}

//
export class TaskAttachQuickOpenItem extends QuickOpenItem {

private activeElement: HTMLElement;

constructor(
protected readonly task: TaskInfo,
protected readonly taskLabel: string,
protected taskService: TaskService
) {
super();
this.activeElement = window.document.activeElement as HTMLElement;
}

getLabel(): string {
return this.taskLabel!;
}

run(mode: QuickOpenMode): boolean {
if (mode !== QuickOpenMode.OPEN) {
return false;
}
if (this.task.processId) {
// reset focus on the previously active element.
this.activeElement.focus();
this.taskService.attach(this.task.processId, this.task.taskId);
}
return true;
}
}
Loading

0 comments on commit 6ca04f9

Please sign in to comment.