From b84d0fc1a307f6103ea2c2620a106db821696434 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 2 Apr 2019 01:11:22 +0800 Subject: Add proper process teminate method --- editors/code/src/utils/processes.ts | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 editors/code/src/utils/processes.ts (limited to 'editors/code/src/utils/processes.ts') 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 @@ +'use strict'; + +import * as cp from 'child_process'; +import ChildProcess = cp.ChildProcess; + +import { join } from 'path'; + +const isWindows = (process.platform === 'win32'); +const isMacintosh = (process.platform === 'darwin'); +const isLinux = (process.platform === 'linux'); +export function terminate(process: ChildProcess, cwd?: string): boolean { + if (isWindows) { + try { + // This we run in Atom execFileSync is available. + // Ignore stderr since this is otherwise piped to parent.stderr + // which might be already closed. + const options: any = { + stdio: ['pipe', 'pipe', 'ignore'] + }; + if (cwd) { + options.cwd = cwd + } + (cp).execFileSync('taskkill', ['/T', '/F', '/PID', process.pid.toString()], options); + return true; + } catch (err) { + return false; + } + } else if (isLinux || isMacintosh) { + try { + const cmd = join(__dirname, 'terminateProcess.sh'); + const result = cp.spawnSync(cmd, [process.pid.toString()]); + return result.error ? false : true; + } catch (err) { + return false; + } + } else { + process.kill('SIGKILL'); + return true; + } +} \ No newline at end of file -- cgit v1.2.3 From 02e450f354ccd978c90425929c635139210843a3 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 2 Apr 2019 14:43:02 +0800 Subject: Add cargo-watch.check-arguments --- editors/code/src/utils/processes.ts | 68 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 32 deletions(-) (limited to 'editors/code/src/utils/processes.ts') diff --git a/editors/code/src/utils/processes.ts b/editors/code/src/utils/processes.ts index 09fdf6e24..d4c2c8778 100644 --- a/editors/code/src/utils/processes.ts +++ b/editors/code/src/utils/processes.ts @@ -5,36 +5,40 @@ import ChildProcess = cp.ChildProcess; import { join } from 'path'; -const isWindows = (process.platform === 'win32'); -const isMacintosh = (process.platform === 'darwin'); -const isLinux = (process.platform === 'linux'); +const isWindows = process.platform === 'win32'; +const isMacintosh = process.platform === 'darwin'; +const isLinux = process.platform === 'linux'; export function terminate(process: ChildProcess, cwd?: string): boolean { - if (isWindows) { - try { - // This we run in Atom execFileSync is available. - // Ignore stderr since this is otherwise piped to parent.stderr - // which might be already closed. - const options: any = { - stdio: ['pipe', 'pipe', 'ignore'] - }; - if (cwd) { - options.cwd = cwd - } - (cp).execFileSync('taskkill', ['/T', '/F', '/PID', process.pid.toString()], options); - return true; - } catch (err) { - return false; - } - } else if (isLinux || isMacintosh) { - try { - const cmd = join(__dirname, 'terminateProcess.sh'); - const result = cp.spawnSync(cmd, [process.pid.toString()]); - return result.error ? false : true; - } catch (err) { - return false; - } - } else { - process.kill('SIGKILL'); - return true; - } -} \ No newline at end of file + if (isWindows) { + try { + // This we run in Atom execFileSync is available. + // Ignore stderr since this is otherwise piped to parent.stderr + // which might be already closed. + const options: any = { + stdio: ['pipe', 'pipe', 'ignore'] + }; + if (cwd) { + options.cwd = cwd; + } + cp.execFileSync( + 'taskkill', + ['/T', '/F', '/PID', process.pid.toString()], + options + ); + return true; + } catch (err) { + return false; + } + } else if (isLinux || isMacintosh) { + try { + const cmd = join(__dirname, 'terminateProcess.sh'); + const result = cp.spawnSync(cmd, [process.pid.toString()]); + return result.error ? false : true; + } catch (err) { + return false; + } + } else { + process.kill('SIGKILL'); + return true; + } +} -- cgit v1.2.3 From 9d269849987fbe374b0f76a4893fdf9d867b8b84 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 2 Apr 2019 17:13:14 +0800 Subject: Add terminate process implemntation note --- editors/code/src/utils/processes.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'editors/code/src/utils/processes.ts') diff --git a/editors/code/src/utils/processes.ts b/editors/code/src/utils/processes.ts index d4c2c8778..f62e2a346 100644 --- a/editors/code/src/utils/processes.ts +++ b/editors/code/src/utils/processes.ts @@ -8,6 +8,13 @@ import { join } from 'path'; const isWindows = process.platform === 'win32'; const isMacintosh = process.platform === 'darwin'; const isLinux = process.platform === 'linux'; + +// this is very complex, but is basically copy-pased from VSCode implementation here: +// https://github.com/Microsoft/vscode-languageserver-node/blob/dbfd37e35953ad0ee14c4eeced8cfbc41697b47e/client/src/utils/processes.ts#L15 + +// And see discussion at +// https://github.com/rust-analyzer/rust-analyzer/pull/1079#issuecomment-478908109 + export function terminate(process: ChildProcess, cwd?: string): boolean { if (isWindows) { try { -- cgit v1.2.3 From b60e2f779b28f654dbd5a2657c668de8452933c6 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 2 Apr 2019 17:43:09 +0800 Subject: Fix prettier error --- editors/code/src/utils/processes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/utils/processes.ts') diff --git a/editors/code/src/utils/processes.ts b/editors/code/src/utils/processes.ts index f62e2a346..da8be9eb1 100644 --- a/editors/code/src/utils/processes.ts +++ b/editors/code/src/utils/processes.ts @@ -12,7 +12,7 @@ const isLinux = process.platform === 'linux'; // this is very complex, but is basically copy-pased from VSCode implementation here: // https://github.com/Microsoft/vscode-languageserver-node/blob/dbfd37e35953ad0ee14c4eeced8cfbc41697b47e/client/src/utils/processes.ts#L15 -// And see discussion at +// And see discussion at // https://github.com/rust-analyzer/rust-analyzer/pull/1079#issuecomment-478908109 export function terminate(process: ChildProcess, cwd?: string): boolean { -- cgit v1.2.3