Skip to content

Rename terminal instance on enter in Windows - #30732

Merged
Daniel Imms (Tyriar) merged 12 commits into
masterfrom
amqi/update-window-shellname
Jul 20, 2017
Merged

Daniel Imms (Tyriar) merged 12 commits into
masterfrom
amqi/update-window-shellname

Conversation

@Lixire

@Lixire Amy Qiu (Lixire) commented Jul 14, 2017 •

Copy link
Copy Markdown
Contributor

Fix part of #30152

  • Renames shell on enter in Windows (debounced)
  • Takes the lowest first child of the pid tree

Noted flaws:

  • Since it only updates on enter, it will not change from ie node to powershell if npm install is run and finishes

* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why there are diffs on this line? You might have committed the wrong line endings or something

* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this adds anything in a file compiled by strict TS

* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also not have a diff

this._pidStack.push(this._processId);
}
return new TPromise<string>((resolve) => {
// wait 100ms before running getChildProcesses

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should explain why the wait is needed here

}
}

private static executeWMIC(pid: number): TPromise<{ executable: string, pid: number }[]> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more general name for what the function is actually doing here, is this accurate? getFirstWindowsChildProcess

});
}

private getChildProcesses(pid: number): TPromise<string> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better name might be refreshWindowsShellProcessTree?


this._pidStack = [];
this._checkWindowShell = new Emitter<string>();
debounceEvent(this._checkWindowShell.event, (l, e) => e, 100, true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be called on Windows, otherwise we're still doing a lot of work on enter for nothing on macOS/Linux.

}

if (platform.isWindows && event.keyCode === 13 /* ENTER */) {
this._checkWindowShell.fire();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


this._pidStack = [];
this._checkWindowShell = new Emitter<string>();
debounceEvent(this._checkWindowShell.event, (l, e) => e, 100, true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should pull all this code out into another file so we don't clutter TerminalInstance? This would also simplify the function names as we can have Windows in the new class name.

}
resolve(this._shellLaunchConfig.executable);
}, error => { return error; });
}, 100);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this to a named constant (especially because the comment explaining is so far from this line.

private _preLaunchInputQueue: string;
private _initialCwd: string;
private _windowsShellService: WindowsShellService;
private _checkWindowShell: Emitter<string>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this _onCheckWindowsShell to be consistent with other Emitters.

}
}

public eventuallyGetShellName(): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's return the promise here. Also a better name would be updateShellName (or updateWindowsShellName if it's in TerminalInstance. Since TerminalInstance.setTitle is on the interface let's move this whole function into WindowsShellService.

/** The amount of time to wait before getting the shell process name */
const WAIT_FOR_SHELL_UPDATE = 100;

export class WindowsShellService {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this WindowsShellHelper because it is not a "registered service" like TerminalService is.


export class WindowsShellService {
private _pidStack: number[];
private _processId: number;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_rootProcessId to differentiate from _pidStack

export class WindowsShellService {
private _pidStack: number[];
private _processId: number;
private _shellLaunchConfig: IShellLaunchConfig;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pass in the executable instead (_rootProcessExecutable) as that's all this class cares about.

this._shellLaunchConfig = shell;
}

private static getFirstWindowsChildProcess(pid: number): TPromise<{ executable: string, pid: number }[]> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove Windows from the name here since we're in a class containing "Windows" now. Also doesn't need to be static.

});
}

private refreshWindowsShellProcessTree(pid: number, flag: boolean): TPromise<string> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, remove "Windows"

private refreshWindowsShellProcessTree(pid: number, flag: boolean): TPromise<string> {
return WindowsShellService.getFirstWindowsChildProcess(pid).then(result => {
if (result.length === 0) {
if (flag) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what flag does?

*/
public getShellName(): TPromise<string> {
if (platform.platform !== platform.Platform.Windows) {
throw null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to the constructor.

throw new Error(`WindowsShellHelper cannot be instantiated on ${platform.platform}`);

import { TPromise } from 'vs/base/common/winjs.base';

/** The amount of time to wait before getting the shell process name */
const WAIT_FOR_SHELL_UPDATE = 100;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WAIT_AFTER_ENTER_TIME is a little more descriptive.

@Lixire
Amy Qiu (Lixire) force-pushed the amqi/update-window-shellname branch from 0c1d2e9 to a737109 Compare July 17, 2017 21:40
@Lixire
Amy Qiu (Lixire) force-pushed the amqi/update-window-shellname branch from a737109 to a2a61b1 Compare July 17, 2017 21:42
@Tyriar

Copy link
Copy Markdown
Contributor

Woo! 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants