Skip to content

Commit

Permalink
Fix relative links in the terminal
Browse files Browse the repository at this point in the history
Fixes #58256
  • Loading branch information
Tyriar committed Sep 10, 2018
1 parent 2241bcb commit befd9d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ export class TerminalInstance implements ITerminalInstance {
this._processManager.onProcessData(data => this._onProcessData(data));
this._xterm.on('data', data => this._processManager.write(data));
// TODO: How does the cwd work on detached processes?
this._linkHandler = this._instantiationService.createInstance(TerminalLinkHandler, this._xterm, platform.platform, this._processManager.initialCwd);
this._linkHandler = this._instantiationService.createInstance(TerminalLinkHandler, this._xterm, platform.platform);
this.processReady.then(() => {
this._linkHandler.initialCwd = this._processManager.initialCwd;
});
}
this._xterm.on('focus', () => this._onFocus.fire(this));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export class TerminalLinkHandler {
private _hoverDisposables: IDisposable[] = [];
private _mouseMoveDisposable: IDisposable;
private _widgetManager: TerminalWidgetManager;
private _initialCwd: string;

private _localLinkPattern: RegExp;

constructor(
private _xterm: any,
private _platform: platform.Platform,
private _initialCwd: string,
@IOpenerService private readonly _openerService: IOpenerService,
@IEditorService private readonly _editorService: IEditorService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
Expand All @@ -84,6 +84,10 @@ export class TerminalLinkHandler {
this._widgetManager = widgetManager;
}

public set initialCwd(initialCwd: string) {
this._initialCwd = initialCwd;
}

public registerCustomLinkHandler(regex: RegExp, handler: (uri: string) => void, matchIndex?: number, validationCallback?: XtermLinkMatcherValidationCallback): number {
return this._xterm.registerLinkMatcher(regex, this._wrapLinkHandler(handler), {
matchIndex,
Expand Down Expand Up @@ -147,10 +151,6 @@ export class TerminalLinkHandler {

private _handleLocalLink(link: string): TPromise<any> {
return this._resolvePath(link).then(resolvedLink => {
if (!resolvedLink) {
return void 0;
}

const normalizedPath = path.normalize(path.resolve(resolvedLink));
const normalizedUrl = this.extractLinkUrl(normalizedPath);
const resource = Uri.file(normalizedUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface LinkFormatInfo {
suite('Workbench - TerminalLinkHandler', () => {
suite('localLinkRegex', () => {
test('Windows', () => {
const terminalLinkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Windows, null, null, null, null, null);
const terminalLinkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Windows, null, null, null, null);
function testLink(link: string, linkUrl: string, lineNo?: string, columnNo?: string) {
assert.equal(terminalLinkHandler.extractLinkUrl(link), linkUrl);
assert.equal(terminalLinkHandler.extractLinkUrl(`:${link}:`), linkUrl);
Expand Down Expand Up @@ -103,7 +103,7 @@ suite('Workbench - TerminalLinkHandler', () => {
});

test('Linux', () => {
const terminalLinkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null, null, null, null, null);
const terminalLinkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null, null, null, null);
function testLink(link: string, linkUrl: string, lineNo?: string, columnNo?: string) {
assert.equal(terminalLinkHandler.extractLinkUrl(link), linkUrl);
assert.equal(terminalLinkHandler.extractLinkUrl(`:${link}:`), linkUrl);
Expand Down Expand Up @@ -167,7 +167,8 @@ suite('Workbench - TerminalLinkHandler', () => {

suite('preprocessPath', () => {
test('Windows', () => {
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Windows, 'C:\\base', null, null, null, null);
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Windows, null, null, null, null);
linkHandler.initialCwd = 'C:\\base';

let stub = sinon.stub(path, 'join', function (arg1: string, arg2: string) {
return arg1 + '\\' + arg2;
Expand All @@ -180,7 +181,8 @@ suite('Workbench - TerminalLinkHandler', () => {
});

test('Linux', () => {
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, '/base', null, null, null, null);
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null, null, null, null);
linkHandler.initialCwd = '/base';

let stub = sinon.stub(path, 'join', function (arg1: string, arg2: string) {
return arg1 + '/' + arg2;
Expand All @@ -193,7 +195,7 @@ suite('Workbench - TerminalLinkHandler', () => {
});

test('No Workspace', () => {
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null, null, null, null, null);
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null, null, null, null);

assert.equal(linkHandler.preprocessPath('./src/file1'), null);
assert.equal(linkHandler.preprocessPath('src/file2'), null);
Expand Down

0 comments on commit befd9d2

Please sign in to comment.