aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands/cargo_watch.ts17
-rw-r--r--editors/code/src/commands/watch_status.ts1
-rw-r--r--editors/code/src/utils/processes.ts40
-rw-r--r--editors/code/src/utils/terminateProcess.sh12
4 files changed, 62 insertions, 8 deletions
diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts
index 037f1e302..e51cac78a 100644
--- a/editors/code/src/commands/cargo_watch.ts
+++ b/editors/code/src/commands/cargo_watch.ts
@@ -1,9 +1,10 @@
1import * as child_process from 'child_process'; 1import * as child_process from 'child_process';
2import * as path from 'path'; 2import * as path from 'path';
3import * as timers from 'timers';
4import * as vscode from 'vscode'; 3import * as vscode from 'vscode';
4import { terminate } from '../utils/processes';
5import { StatusDisplay } from './watch_status'; 5import { StatusDisplay } from './watch_status';
6 6
7
7export class CargoWatchProvider { 8export class CargoWatchProvider {
8 private diagnosticCollection?: vscode.DiagnosticCollection; 9 private diagnosticCollection?: vscode.DiagnosticCollection;
9 private cargoProcess?: child_process.ChildProcess; 10 private cargoProcess?: child_process.ChildProcess;
@@ -21,24 +22,25 @@ export class CargoWatchProvider {
21 // Start the cargo watch with json message 22 // Start the cargo watch with json message
22 this.cargoProcess = child_process.spawn( 23 this.cargoProcess = child_process.spawn(
23 'cargo', 24 'cargo',
24 ['watch', '-x', '"check --message-format json"'], 25 ['watch', '-x', '\"check --message-format json\"'],
25 { 26 {
26 // stdio: ['ignore', 'pipe', 'ignore'], 27 stdio: ['ignore', 'pipe', 'pipe'],
27 shell: true, 28 cwd: vscode.workspace.rootPath,
28 cwd: vscode.workspace.rootPath 29 windowsVerbatimArguments: true,
29 } 30 }
30 ); 31 );
31 32
32 this.cargoProcess.stdout.on('data', (s: string) => { 33 this.cargoProcess.stdout.on('data', (s: string) => {
33 this.processOutput(s); 34 this.processOutput(s);
35 console.log(s);
34 }); 36 });
35 37
36 this.cargoProcess.stderr.on('data', (s: string) => { 38 this.cargoProcess.stderr.on('data', (s: string) => {
37 // console.error('Error on cargo watch : ' + s); 39 console.error('Error on cargo watch : ' + s);
38 }); 40 });
39 41
40 this.cargoProcess.on('error', (err: Error) => { 42 this.cargoProcess.on('error', (err: Error) => {
41 // console.error('Error on spawn cargo process : ' + err); 43 console.error('Error on spawn cargo process : ' + err);
42 }); 44 });
43 } 45 }
44 46
@@ -50,6 +52,7 @@ export class CargoWatchProvider {
50 52
51 if (this.cargoProcess) { 53 if (this.cargoProcess) {
52 this.cargoProcess.kill(); 54 this.cargoProcess.kill();
55 terminate(this.cargoProcess);
53 } 56 }
54 } 57 }
55 58
diff --git a/editors/code/src/commands/watch_status.ts b/editors/code/src/commands/watch_status.ts
index 1b0611ce3..f027d7bbc 100644
--- a/editors/code/src/commands/watch_status.ts
+++ b/editors/code/src/commands/watch_status.ts
@@ -1,4 +1,3 @@
1import * as timers from 'timers';
2import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
3 2
4const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; 3const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
diff --git a/editors/code/src/utils/processes.ts b/editors/code/src/utils/processes.ts
new file mode 100644
index 000000000..09fdf6e24
--- /dev/null
+++ b/editors/code/src/utils/processes.ts
@@ -0,0 +1,40 @@
1'use strict';
2
3import * as cp from 'child_process';
4import ChildProcess = cp.ChildProcess;
5
6import { join } from 'path';
7
8const isWindows = (process.platform === 'win32');
9const isMacintosh = (process.platform === 'darwin');
10const isLinux = (process.platform === 'linux');
11export function terminate(process: ChildProcess, cwd?: string): boolean {
12 if (isWindows) {
13 try {
14 // This we run in Atom execFileSync is available.
15 // Ignore stderr since this is otherwise piped to parent.stderr
16 // which might be already closed.
17 const options: any = {
18 stdio: ['pipe', 'pipe', 'ignore']
19 };
20 if (cwd) {
21 options.cwd = cwd
22 }
23 (cp).execFileSync('taskkill', ['/T', '/F', '/PID', process.pid.toString()], options);
24 return true;
25 } catch (err) {
26 return false;
27 }
28 } else if (isLinux || isMacintosh) {
29 try {
30 const cmd = join(__dirname, 'terminateProcess.sh');
31 const result = cp.spawnSync(cmd, [process.pid.toString()]);
32 return result.error ? false : true;
33 } catch (err) {
34 return false;
35 }
36 } else {
37 process.kill('SIGKILL');
38 return true;
39 }
40} \ No newline at end of file
diff --git a/editors/code/src/utils/terminateProcess.sh b/editors/code/src/utils/terminateProcess.sh
new file mode 100644
index 000000000..2ec9e1c2e
--- /dev/null
+++ b/editors/code/src/utils/terminateProcess.sh
@@ -0,0 +1,12 @@
1#!/bin/bash
2
3terminateTree() {
4 for cpid in $(pgrep -P $1); do
5 terminateTree $cpid
6 done
7 kill -9 $1 > /dev/null 2>&1
8}
9
10for pid in $*; do
11 terminateTree $pid
12done \ No newline at end of file