@@ -17,6 +17,8 @@ import type { ITerminalAddon, Terminal } from 'xterm-headless';
17
17
import { ISerializedCommandDetectionCapability } from 'vs/platform/terminal/common/terminalProcess' ;
18
18
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
19
19
import { Emitter } from 'vs/base/common/event' ;
20
+ import { URI } from 'vs/base/common/uri' ;
21
+
20
22
21
23
/**
22
24
* 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
420
422
return false ;
421
423
}
422
424
425
+ /**
426
+ * Handles the sequence: `OSC 7 ; scheme://cwd ST`
427
+ */
423
428
private _doHandleSetCwd ( data : string ) : boolean {
424
429
if ( ! this . _terminal ) {
425
430
return false ;
426
431
}
427
432
428
433
const [ command ] = data . split ( ';' ) ;
429
434
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
+ }
437
443
}
438
444
439
445
// Unrecognized sequence
@@ -499,3 +505,4 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
499
505
return { key, value } ;
500
506
}
501
507
}
508
+
0 commit comments