forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes eclipse-theia#686 Signed-off-by: Marc Dumais <[email protected]>
- Loading branch information
1 parent
c6e1247
commit 6ca04f9
Showing
27 changed files
with
1,810 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.