Skip to content

Commit 439489f

Browse files
committed
Switch link priority so ext links are higher than builtin
1 parent 395b228 commit 439489f

1 file changed

Lines changed: 34 additions & 23 deletions

File tree

src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import * as nls from 'vs/nls';
77
import { URI } from 'vs/base/common/uri';
8-
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
8+
import { DisposableStore, IDisposable, dispose } from 'vs/base/common/lifecycle';
99
import { IOpenerService } from 'vs/platform/opener/common/opener';
1010
import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/widgets/widgetManager';
1111
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1212
import { ITerminalProcessManager, ITerminalConfiguration, TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal';
1313
import { ITextEditorSelection } from 'vs/platform/editor/common/editor';
1414
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1515
import { IFileService } from 'vs/platform/files/common/files';
16-
import { Terminal, IViewportRange } from 'xterm';
16+
import { Terminal, IViewportRange, ILinkProvider } from 'xterm';
1717
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
1818
import { posix, win32 } from 'vs/base/common/path';
1919
import { ITerminalBeforeHandleLinkEvent, LINK_INTERCEPT_THRESHOLD, ITerminalExternalLinkProvider, ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
@@ -45,6 +45,8 @@ export class TerminalLinkManager extends DisposableStore {
4545
private _widgetManager: TerminalWidgetManager | undefined;
4646
private _processCwd: string | undefined;
4747
private _hasBeforeHandleLinkListeners = false;
48+
private _standardLinkProviders: ILinkProvider[] = [];
49+
private _standardLinkProvidersDisposables: IDisposable[] = [];
4850

4951
protected static _LINK_INTERCEPT_THRESHOLD = LINK_INTERCEPT_THRESHOLD;
5052
public static readonly LINK_INTERCEPT_THRESHOLD = TerminalLinkManager._LINK_INTERCEPT_THRESHOLD;
@@ -72,6 +74,28 @@ export class TerminalLinkManager extends DisposableStore {
7274
) {
7375
super();
7476

77+
// Protocol links
78+
const wrappedActivateCallback = this._wrapLinkHandler((_, link) => this._handleProtocolLink(link));
79+
const protocolProvider = this._instantiationService.createInstance(TerminalProtocolLinkProvider, this._xterm, wrappedActivateCallback, this._tooltipCallback2.bind(this));
80+
this._standardLinkProviders.push(protocolProvider);
81+
82+
// Validated local links
83+
if (this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION).enableFileLinks) {
84+
const wrappedTextLinkActivateCallback = this._wrapLinkHandler((_, link) => this._handleLocalLink(link));
85+
const validatedProvider = this._instantiationService.createInstance(TerminalValidatedLocalLinkProvider,
86+
this._xterm,
87+
this._processManager.os || OS,
88+
wrappedTextLinkActivateCallback,
89+
this._wrapLinkHandler.bind(this),
90+
this._tooltipCallback2.bind(this),
91+
async (link, cb) => cb(await this._resolvePath(link)));
92+
this._standardLinkProviders.push(validatedProvider);
93+
}
94+
95+
// Word links
96+
const wordProvider = this._instantiationService.createInstance(TerminalWordLinkProvider, this._xterm, this._wrapLinkHandler.bind(this), this._tooltipCallback2.bind(this));
97+
this._standardLinkProviders.push(wordProvider);
98+
7599
this._registerStandardLinkProviders();
76100
}
77101

@@ -124,32 +148,19 @@ export class TerminalLinkManager extends DisposableStore {
124148
}
125149

126150
private _registerStandardLinkProviders(): void {
127-
// Protocol links
128-
const wrappedActivateCallback = this._wrapLinkHandler((_, link) => this._handleProtocolLink(link));
129-
const protocolProvider = this._instantiationService.createInstance(TerminalProtocolLinkProvider, this._xterm, wrappedActivateCallback, this._tooltipCallback2.bind(this));
130-
this._xterm.registerLinkProvider(protocolProvider);
131-
132-
// Validated local links
133-
if (this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION).enableFileLinks) {
134-
const wrappedTextLinkActivateCallback = this._wrapLinkHandler((_, link) => this._handleLocalLink(link));
135-
const validatedProvider = this._instantiationService.createInstance(TerminalValidatedLocalLinkProvider,
136-
this._xterm,
137-
this._processManager.os || OS,
138-
wrappedTextLinkActivateCallback,
139-
this._wrapLinkHandler.bind(this),
140-
this._tooltipCallback2.bind(this),
141-
async (link, cb) => cb(await this._resolvePath(link)));
142-
this._xterm.registerLinkProvider(validatedProvider);
151+
dispose(this._standardLinkProvidersDisposables);
152+
this._standardLinkProvidersDisposables = [];
153+
for (const p of this._standardLinkProviders) {
154+
this._standardLinkProvidersDisposables.push(this._xterm.registerLinkProvider(p));
143155
}
144-
145-
// Word links
146-
const wordProvider = this._instantiationService.createInstance(TerminalWordLinkProvider, this._xterm, this._wrapLinkHandler.bind(this), this._tooltipCallback2.bind(this));
147-
this._xterm.registerLinkProvider(wordProvider);
148156
}
149157

150158
public registerExternalLinkProvider(instance: ITerminalInstance, linkProvider: ITerminalExternalLinkProvider): IDisposable {
151159
const wrappedLinkProvider = this._instantiationService.createInstance(TerminalExternalLinkProviderAdapter, this._xterm, instance, linkProvider, this._tooltipCallback2.bind(this));
152-
return this._xterm.registerLinkProvider(wrappedLinkProvider);
160+
const newLinkProvider = this._xterm.registerLinkProvider(wrappedLinkProvider);
161+
// Re-register the standard link providers so they are a lower priority that the new one
162+
this._registerStandardLinkProviders();
163+
return newLinkProvider;
153164
}
154165

155166
protected _wrapLinkHandler(handler: (event: MouseEvent | undefined, link: string) => void): XtermLinkMatcherHandler {

0 commit comments

Comments
 (0)