Skip to content

Commit 0298970

Browse files
committed
🔨 Update handling of sequence: OSC 7; scheme://cwd ST
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 39c3fce commit 0298970

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import type { ITerminalAddon, Terminal } from 'xterm-headless';
1717
import { ISerializedCommandDetectionCapability } from 'vs/platform/terminal/common/terminalProcess';
1818
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1919
import { Emitter } from 'vs/base/common/event';
20+
import { URI } from 'vs/base/common/uri';
21+
2022

2123
/**
2224
* Shell integration is a feature that enhances the terminal's understanding of what's happening
@@ -420,20 +422,24 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
420422
return false;
421423
}
422424

425+
/**
426+
* Handles the sequence: `OSC 7 ; scheme://cwd ST`
427+
*/
423428
private _doHandleSetCwd(data: string): boolean {
424429
if (!this._terminal) {
425430
return false;
426431
}
427432

428433
const [command] = data.split(';');
429434

430-
// Checking for: `OSC 7 ; scheme://cwd ST`
431-
if (command.startsWith('scheme://')) {
432-
// TODO: I'm not sure `scheme` here is literal or can be `file` or something else.
433-
// TODO: Possibly the path is URL-encoded, but I have no means to test it.
434-
const cwd = command.substring(9);
435-
this._updateCwd(cwd);
436-
return true;
435+
// We need to manually make sure the given URI is not merely `file://` because The `URI.parse` handles it
436+
// exactly as it handles `file:///` (which is a valid URI for us here).
437+
if (command.startsWith('file://') && command.length > 7) {
438+
const uri = URI.parse(command);
439+
if (uri.path && uri.path.length > 0) {
440+
this._updateCwd(uri.path);
441+
return true;
442+
}
437443
}
438444

439445
// Unrecognized sequence
@@ -499,3 +505,4 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
499505
return { key, value };
500506
}
501507
}
508+

0 commit comments

Comments
 (0)