Properly format file path on when dragging and dropping a tab into the integrated terminal in Windows (version 2)#31234
Conversation
| // List of regular expressions, for matching shells, functions to format a path, and booleans indicating whether the shell uses Windows-style paths | ||
| const WIN_PATH_FORMATTERS: [RegExp, (path: string) => string, boolean][] = [ | ||
| // WSL bash | ||
| [/^C:\\Windows\\(System32|sysnative)\\bash(.exe)?$/i, path => '/mnt/' + path[1] + path.substring(3), false], |
There was a problem hiding this comment.
Not sure if WSL bash is available in WoW64, might want to add |SysWoW64 too?
| import URI from 'vs/base/common/uri'; | ||
|
|
||
| // List of regular expressions, for matching shells, functions to format a path, and booleans indicating whether the shell uses Windows-style paths | ||
| const WIN_PATH_FORMATTERS: [RegExp, (path: string) => string, boolean][] = [ |
There was a problem hiding this comment.
Let's use an interface instead of an array so it's nicer to use:
interface IPathFormatter {
regex: RegExp,
format: (path: string) =>string,
usesWindowsStylePaths: boolean
}
const WIN_PATH_FORMATTERS: IPathFormatter[] = [...]There was a problem hiding this comment.
An interface would be nicer but it does add some verbosity to WIN_PATH_FORMATTERS as the array elements would be switched from arrays to objects. Would doing something like:
type PathFormatter = [Regexp, (path: string) => string, boolean];
const WIN_PATH_FORMATTERS: PathFormatter[] = [...]be any better? Or given I haven't really seen this used in VS Code would it be better to stick with interfaces?
| if (platform.isWindows) { | ||
| const terminal = this._terminalService.getActiveInstance(); | ||
| const shell = terminal.getShellName(); | ||
| for (const [format, formatter, isWinPath] of WIN_PATH_FORMATTERS) { |
There was a problem hiding this comment.
Let's use WIN_PATH_FORMATTERS.forEach( to keep it consistent with the rest of the code.
There was a problem hiding this comment.
Okay.
Is the following pattern used at all?
WIN_PATH_FORMATTERS.forEach(formatArray => {
const [format, formatter, isWinPath] = formatArray;
...
}Or if I switched to interfaces I wouldn't have to worry about this.
There was a problem hiding this comment.
Actually never mind. The regular expression for WSL bash is becoming quite long, so I may as well use an interface to split up the line.
There was a problem hiding this comment.
I don't think using forEach will work because I need to break out of the loop. Either I would need to nest an if inside of it which would get ugly or use some other method (such as Array.prototype.find, but it seems the typescript target is set to es5 so that's not an option).
| // We only go one level deep when checking for children of processes other then shells | ||
| if (SHELL_EXECUTABLES.indexOf(path.basename(result[0].executable)) === -1) { | ||
| return TPromise.as(result[0].executable); | ||
| return TPromise.as({ program: result[0].executable, shell: parent }); |
|
|
||
| /** | ||
| * Returns the innermost shell executable running in the terminal | ||
| * Updates innermost shell executable and innermost shell running in the terminal |
There was a problem hiding this comment.
This comment is a little vague, something like this might be better:
Queries the OS and gets the inner-most shell running in the terminal as well as the program the shell is running if it exists.
There was a problem hiding this comment.
Yeah that sounds better.
| /** | ||
| * Returns the innermost program executable running in the terminal | ||
| */ | ||
| public getProgramName(): string { |
There was a problem hiding this comment.
Let's make these getters:
public get programName(): string { return this._programName; }You can then refer to them as if they were properties.
There was a problem hiding this comment.
Oh yeah I forgot that was a thing! Is having this on a single line or multiple lines preferred?
| this.refreshShellProcessTree(this._childProcessIdStack[this._childProcessIdStack.length - 1], null).then(result => { | ||
| resolve(result); | ||
| return new TPromise<void>((resolve) => { | ||
| this.refreshShellProcessTree(this._childProcessIdStack[this._childProcessIdStack.length - 1], this._shellName !== this._programName ? this._shellName : null).then(result => { |
There was a problem hiding this comment.
Let's pull this._shellName !== this._programName ? this._shellName : null into a variable so it's easier to read
|
@Tyriar I'm not sure if you received any notifications from me responding to your comments or have seen them yet, but if you haven't I'm letting you know that I responded to them and had a few questions 😃. |
|
I've revised the PR do use the new native module. However the module only gives the executable name and not the full path so it can't differentiate between WSL bash and Git bash. |
|
@rianadon sorry about the delay, I'll try get to this over the next couple of weeks 😃 |
|
No problem. Since this is anyways going to have to be ported over to use |
|
Unfortunately this has become a bit too slate (my fault) so I'll have to close it. I am planning on improving WSL/Windows in general in the coming months so maybe this could be tackled then too. |
This is a rewrite of #30070 to make use of the new changes to the codebase since the previous PR.