提交 c96f5d12 编写于 作者: D Daniel Imms

Import and type windows-process-tree

Fixes #43287
上级 7d9ccca1
...@@ -11,4 +11,4 @@ declare module 'windows-mutex' { ...@@ -11,4 +11,4 @@ declare module 'windows-mutex' {
} }
export function isActive(name: string): boolean; export function isActive(name: string): boolean;
} }
\ No newline at end of file
...@@ -9,6 +9,8 @@ declare module 'windows-process-tree' { ...@@ -9,6 +9,8 @@ declare module 'windows-process-tree' {
name: string, name: string,
children: ProcessTreeNode[] children: ProcessTreeNode[]
} }
function get(rootPid: number, callback: (tree: ProcessTreeNode) => void): void; function get(rootPid: number, callback: (tree: ProcessTreeNode) => void): void;
export = get; export = get;
} }
\ No newline at end of file
...@@ -8,10 +8,11 @@ import { TPromise } from 'vs/base/common/winjs.base'; ...@@ -8,10 +8,11 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { Emitter, debounceEvent } from 'vs/base/common/event'; import { Emitter, debounceEvent } from 'vs/base/common/event';
import { ITerminalInstance } from 'vs/workbench/parts/terminal/common/terminal'; import { ITerminalInstance } from 'vs/workbench/parts/terminal/common/terminal';
import { Terminal as XTermTerminal } from 'vscode-xterm'; import { Terminal as XTermTerminal } from 'vscode-xterm';
import WindowsProcessTreeType = require('windows-process-tree');
const SHELL_EXECUTABLES = ['cmd.exe', 'powershell.exe', 'bash.exe']; const SHELL_EXECUTABLES = ['cmd.exe', 'powershell.exe', 'bash.exe'];
let windowsProcessTree; let windowsProcessTree: typeof WindowsProcessTreeType;
export class WindowsShellHelper { export class WindowsShellHelper {
private _onCheckShell: Emitter<TPromise<string>>; private _onCheckShell: Emitter<TPromise<string>>;
...@@ -28,34 +29,38 @@ export class WindowsShellHelper { ...@@ -28,34 +29,38 @@ export class WindowsShellHelper {
throw new Error(`WindowsShellHelper cannot be instantiated on ${platform.platform}`); throw new Error(`WindowsShellHelper cannot be instantiated on ${platform.platform}`);
} }
if (!windowsProcessTree) {
windowsProcessTree = require.__$__nodeRequire('windows-process-tree');
}
this._isDisposed = false; this._isDisposed = false;
this._onCheckShell = new Emitter<TPromise<string>>();
// The debounce is necessary to prevent multiple processes from spawning when
// the enter key or output is spammed
debounceEvent(this._onCheckShell.event, (l, e) => e, 150, true)(() => {
setTimeout(() => {
this.checkShell();
}, 50);
});
// We want to fire a new check for the shell on a linefeed, but only (import('windows-process-tree')).then(mod => {
// when parsing has finished which is indicated by the cursormove event. if (this._isDisposed) {
// If this is done on every linefeed, parsing ends up taking return;
// significantly longer due to resetting timers. Note that this is
// private API.
this._xterm.on('linefeed', () => this._newLineFeed = true);
this._xterm.on('cursormove', () => {
if (this._newLineFeed) {
this._onCheckShell.fire();
} }
});
// Fire a new check for the shell when any key is pressed. windowsProcessTree = mod;
this._xterm.on('keypress', () => this._onCheckShell.fire()); this._onCheckShell = new Emitter<TPromise<string>>();
// The debounce is necessary to prevent multiple processes from spawning when
// the enter key or output is spammed
debounceEvent(this._onCheckShell.event, (l, e) => e, 150, true)(() => {
setTimeout(() => {
this.checkShell();
}, 50);
});
// We want to fire a new check for the shell on a linefeed, but only
// when parsing has finished which is indicated by the cursormove event.
// If this is done on every linefeed, parsing ends up taking
// significantly longer due to resetting timers. Note that this is
// private API.
this._xterm.on('linefeed', () => this._newLineFeed = true);
this._xterm.on('cursormove', () => {
if (this._newLineFeed) {
this._onCheckShell.fire();
}
});
// Fire a new check for the shell when any key is pressed.
this._xterm.on('keypress', () => this._onCheckShell.fire());
});
} }
private checkShell(): void { private checkShell(): void {
...@@ -118,4 +123,4 @@ export class WindowsShellHelper { ...@@ -118,4 +123,4 @@ export class WindowsShellHelper {
}); });
return this._currentRequest; return this._currentRequest;
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册