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 Oct 29, 2017
1 parent 116222a commit 0ea4773
Show file tree
Hide file tree
Showing 28 changed files with 1,695 additions and 5 deletions.
100 changes: 100 additions & 0 deletions .theia/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
// comment
"tasks": [
{
"label": "workspace: failing task",
"processType": "terminal",
"processOptions": {
"command": "/bin/false",
"args": []
},
"windowsProcessOptions": {
"command": "packages/task/src/node/test-resources/task.bat",
"args": [
"foo"
]
},
"cwd": "$workspace",
"errorMatcherName": "",
"errorMatcherOptions": ""
},
{
"label": "workspace: test task",
"processType": "terminal",
"processOptions": {
"command": "packages/task/src/node/test-resources/task",
"args": [
"foo"
]
},
"windowsProcessOptions": {
"command": "packages/task/src/node/test-resources/task.bat",
"args": [
"foo"
]
},
"cwd": "$workspace",
"errorMatcherName": "",
"errorMatcherOptions": ""
},
{
"label": "workspace: list workspace",
"processType": "terminal",
"processOptions": {
"command": "ls",
"args": [
"-al"
]
},
"windowsProcessOptions": {
"command": "dir",
"args": []
},
"cwd": "$workspace",
"errorMatcherName": "",
"errorMatcherOptions": ""
},
{
"label": "workspace: list all filez2",
"processType": "terminal",
"processOptions": {
"command": "ls",
"args": [
"-alR",
"/"
]
},
"cwd": "$workspace",
"errorMatcherName": "",
"errorMatcherOptions": ""
},
{
"label": "workspace: theia tsc watch in terminal",
"processType": "terminal",
"processOptions": {
"command": "yarn",
"args": [
"run",
"watch"
]
},
"cwd": "$workspace",
"errorMatcherName": "tsc",
"errorMatcherOptions": ""
},
{
"label": "workspace: theia tsc watch no terminal",
"processType": "raw",
"processOptions": {
"command": "yarn",
"args": [
"run",
"watch"
]
},
"cwd": "$workspace",
"errorMatcherName": "tsc",
"errorMatcherOptions": ""
}
]
}
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
4 changes: 3 additions & 1 deletion examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"@theia/python": "0.2.0",
"@theia/terminal": "0.2.0",
"@theia/typescript": "0.2.0",
"@theia/workspace": "0.2.0"
"@theia/workspace": "0.2.0",
"@theia/outline-view": "^0.2.0",
"@theia/task": "^0.2.0"
},
"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 @@ -23,7 +23,8 @@
"@theia/python": "0.2.0",
"@theia/terminal": "0.2.0",
"@theia/typescript": "0.2.0",
"@theia/workspace": "0.2.0"
"@theia/workspace": "0.2.0",
"@theia/task": "^0.2.0"
},
"scripts": {
"prepare": "yarn run clean && yarn build",
Expand Down
63 changes: 63 additions & 0 deletions examples/electron/package.json.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"private": true,
"name": "@theia/example-electron",
"version": "0.2.0",
"theia": {
"target": "electron"
},
"dependencies": {
<<<<<<< HEAD
"@theia/core": "0.2.0",
"@theia/cpp": "0.2.0",
"@theia/editor": "0.2.0",
"@theia/extension-manager": "0.2.0",
"@theia/filesystem": "0.2.0",
"@theia/git": "0.2.0",
"@theia/go": "0.2.0",
"@theia/java": "0.2.0",
"@theia/languages": "0.2.0",
"@theia/markers": "0.2.0",
"@theia/monaco": "0.2.0",
"@theia/navigator": "0.2.0",
"@theia/preferences": "0.2.0",
"@theia/process": "0.2.0",
"@theia/python": "0.2.0",
"@theia/terminal": "0.2.0",
"@theia/typescript": "0.2.0",
"@theia/workspace": "0.2.0"
=======
"@theia/core": "^0.1.1",
"@theia/cpp": "^0.1.1",
"@theia/editor": "^0.1.1",
"@theia/extension-manager": "^0.1.1",
"@theia/filesystem": "^0.1.1",
"@theia/git": "^0.1.1",
"@theia/go": "^0.1.1",
"@theia/java": "^0.1.1",
"@theia/languages": "^0.1.1",
"@theia/markers": "^0.1.1",
"@theia/monaco": "^0.1.1",
"@theia/navigator": "^0.1.1",
"@theia/preferences": "^0.1.1",
"@theia/process": "^0.1.1",
"@theia/python": "^0.1.1",
"@theia/terminal": "^0.1.1",
"@theia/typescript": "^0.1.1",
"@theia/workspace": "^0.1.1",
"@theia/task": "^0.1.1"
>>>>>>> add task extension
},
"scripts": {
"prepare": "yarn run clean && yarn build",
"clean": "theia clean",
"build": "theia build",
"watch": "yarn build --watch",
"start": "theia start",
"start:debug": "yarn start --loglevel=debug",
"test": "electron-mocha --timeout 60000 --require ts-node/register \"./test/**/*.espec.ts\"",
"test:ui": "wdio wdio.conf.js"
},
"devDependencies": {
"@theia/cli": "0.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/process/src/node/raw-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const RawProcessOptions = Symbol("RawProcessOptions");
export interface RawProcessOptions {
command: string,
args?: string[],
options?: object
options?: child.SpawnOptions
}

export const RawProcessFactory = Symbol("RawProcessFactory");
Expand Down
3 changes: 2 additions & 1 deletion packages/process/src/node/terminal-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import * as stream from 'stream';
import { ILogger } from '@theia/core/lib/common';
import { Process } from './process';
import { ProcessManager } from './process-manager';
import * as child from 'child_process';

const pty = require("node-pty");

export const TerminalProcessOptions = Symbol("TerminalProcessOptions");
export interface TerminalProcessOptions {
command: string,
args?: string[],
options?: object
options?: child.SpawnOptions
}

export const TerminalProcessFactory = Symbol("TerminalProcessFactory");
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"
]
}
51 changes: 51 additions & 0 deletions packages/task/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@theia/task",
"version": "0.2.0",
"description": "Theia - Task extension",
"dependencies": {
"@theia/core": "^0.2.0",
"@theia/process": "^0.2.0",
"@theia/terminal": "^0.2.0",
"@theia/workspace": "^0.2.0",
"@theia/markers": "^0.2.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"
}
}
9 changes: 9 additions & 0 deletions packages/task/src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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-frontend-module';
export * from './task-service';
70 changes: 70 additions & 0 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 { 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 TaskQuickOpenItem(task, this.taskService));
}
this.quickOpenService.open(this, {
placeholder: 'Type the name of a task you want to execute',
fuzzyMatchLabel: true,
fuzzySort: true
});
});

}

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

}

export class TaskQuickOpenItem 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;
}
}
Loading

0 comments on commit 0ea4773

Please sign in to comment.