aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-04-01 18:11:22 +0100
committerEdwin Cheng <[email protected]>2019-04-02 08:03:31 +0100
commitb84d0fc1a307f6103ea2c2620a106db821696434 (patch)
tree99d158e992a58a07cbf51676add9784583b401c8 /editors
parentc894a3e19b0e658622a03a7d0539a78a433b42ae (diff)
Add proper process teminate method
Diffstat (limited to 'editors')
-rw-r--r--editors/code/package-lock.json51
-rw-r--r--editors/code/package.json5
-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
6 files changed, 116 insertions, 10 deletions
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json
index 5a0d21e78..008df6f52 100644
--- a/editors/code/package-lock.json
+++ b/editors/code/package-lock.json
@@ -607,6 +607,12 @@
607 "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", 607 "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==",
608 "dev": true 608 "dev": true
609 }, 609 },
610 "es6-object-assign": {
611 "version": "1.1.0",
612 "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz",
613 "integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw=",
614 "dev": true
615 },
610 "escape-string-regexp": { 616 "escape-string-regexp": {
611 "version": "1.0.5", 617 "version": "1.0.5",
612 "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 618 "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
@@ -1121,6 +1127,12 @@
1121 "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", 1127 "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
1122 "dev": true 1128 "dev": true
1123 }, 1129 },
1130 "interpret": {
1131 "version": "1.2.0",
1132 "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz",
1133 "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==",
1134 "dev": true
1135 },
1124 "is": { 1136 "is": {
1125 "version": "3.3.0", 1137 "version": "3.3.0",
1126 "resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz", 1138 "resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz",
@@ -1791,6 +1803,15 @@
1791 "util-deprecate": "^1.0.1" 1803 "util-deprecate": "^1.0.1"
1792 } 1804 }
1793 }, 1805 },
1806 "rechoir": {
1807 "version": "0.6.2",
1808 "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
1809 "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=",
1810 "dev": true,
1811 "requires": {
1812 "resolve": "^1.1.6"
1813 }
1814 },
1794 "remove-bom-buffer": { 1815 "remove-bom-buffer": {
1795 "version": "3.0.0", 1816 "version": "3.0.0",
1796 "resolved": "https://registry.npmjs.org/remove-bom-buffer/-/remove-bom-buffer-3.0.0.tgz", 1817 "resolved": "https://registry.npmjs.org/remove-bom-buffer/-/remove-bom-buffer-3.0.0.tgz",
@@ -1902,6 +1923,36 @@
1902 "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", 1923 "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
1903 "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==" 1924 "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg=="
1904 }, 1925 },
1926 "shelljs": {
1927 "version": "0.8.3",
1928 "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz",
1929 "integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==",
1930 "dev": true,
1931 "requires": {
1932 "glob": "^7.0.0",
1933 "interpret": "^1.0.0",
1934 "rechoir": "^0.6.2"
1935 }
1936 },
1937 "shx": {
1938 "version": "0.3.2",
1939 "resolved": "https://registry.npmjs.org/shx/-/shx-0.3.2.tgz",
1940 "integrity": "sha512-aS0mWtW3T2sHAenrSrip2XGv39O9dXIFUqxAEWHEOS1ePtGIBavdPJY1kE2IHl14V/4iCbUiNDPGdyYTtmhSoA==",
1941 "dev": true,
1942 "requires": {
1943 "es6-object-assign": "^1.0.3",
1944 "minimist": "^1.2.0",
1945 "shelljs": "^0.8.1"
1946 },
1947 "dependencies": {
1948 "minimist": {
1949 "version": "1.2.0",
1950 "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
1951 "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
1952 "dev": true
1953 }
1954 }
1955 },
1905 "source-map": { 1956 "source-map": {
1906 "version": "0.6.1", 1957 "version": "0.6.1",
1907 "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", 1958 "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
diff --git a/editors/code/package.json b/editors/code/package.json
index 240aff6c9..ba9c9433a 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -18,7 +18,7 @@
18 "scripts": { 18 "scripts": {
19 "vscode:prepublish": "npm run compile", 19 "vscode:prepublish": "npm run compile",
20 "package": "vsce package", 20 "package": "vsce package",
21 "compile": "tsc -p ./", 21 "compile": "tsc -p ./ && shx cp src/utils/terminateProcess.sh out/utils/terminateProcess.sh",
22 "watch": "tsc -watch -p ./", 22 "watch": "tsc -watch -p ./",
23 "postinstall": "node ./node_modules/vscode/bin/install", 23 "postinstall": "node ./node_modules/vscode/bin/install",
24 "fix": "prettier **/*.{json,ts} --write && tslint --project . --fix", 24 "fix": "prettier **/*.{json,ts} --write && tslint --project . --fix",
@@ -41,7 +41,8 @@
41 "tslint-config-prettier": "^1.18.0", 41 "tslint-config-prettier": "^1.18.0",
42 "typescript": "^3.3.1", 42 "typescript": "^3.3.1",
43 "vsce": "^1.57.0", 43 "vsce": "^1.57.0",
44 "vscode": "^1.1.29" 44 "vscode": "^1.1.29",
45 "shx": "^0.3.1"
45 }, 46 },
46 "activationEvents": [ 47 "activationEvents": [
47 "onLanguage:rust", 48 "onLanguage:rust",
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