|
5 | 5 |
|
6 | 6 | import * as nls from 'vs/nls'; |
7 | 7 | 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'; |
9 | 9 | import { IOpenerService } from 'vs/platform/opener/common/opener'; |
10 | 10 | import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/widgets/widgetManager'; |
11 | 11 | import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; |
12 | 12 | import { ITerminalProcessManager, ITerminalConfiguration, TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal'; |
13 | 13 | import { ITextEditorSelection } from 'vs/platform/editor/common/editor'; |
14 | 14 | import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; |
15 | 15 | import { IFileService } from 'vs/platform/files/common/files'; |
16 | | -import { Terminal, IViewportRange } from 'xterm'; |
| 16 | +import { Terminal, IViewportRange, ILinkProvider } from 'xterm'; |
17 | 17 | import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts'; |
18 | 18 | import { posix, win32 } from 'vs/base/common/path'; |
19 | 19 | import { ITerminalBeforeHandleLinkEvent, LINK_INTERCEPT_THRESHOLD, ITerminalExternalLinkProvider, ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal'; |
@@ -45,6 +45,8 @@ export class TerminalLinkManager extends DisposableStore { |
45 | 45 | private _widgetManager: TerminalWidgetManager | undefined; |
46 | 46 | private _processCwd: string | undefined; |
47 | 47 | private _hasBeforeHandleLinkListeners = false; |
| 48 | + private _standardLinkProviders: ILinkProvider[] = []; |
| 49 | + private _standardLinkProvidersDisposables: IDisposable[] = []; |
48 | 50 |
|
49 | 51 | protected static _LINK_INTERCEPT_THRESHOLD = LINK_INTERCEPT_THRESHOLD; |
50 | 52 | public static readonly LINK_INTERCEPT_THRESHOLD = TerminalLinkManager._LINK_INTERCEPT_THRESHOLD; |
@@ -72,6 +74,28 @@ export class TerminalLinkManager extends DisposableStore { |
72 | 74 | ) { |
73 | 75 | super(); |
74 | 76 |
|
| 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 | + |
75 | 99 | this._registerStandardLinkProviders(); |
76 | 100 | } |
77 | 101 |
|
@@ -124,32 +148,19 @@ export class TerminalLinkManager extends DisposableStore { |
124 | 148 | } |
125 | 149 |
|
126 | 150 | 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)); |
143 | 155 | } |
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); |
148 | 156 | } |
149 | 157 |
|
150 | 158 | public registerExternalLinkProvider(instance: ITerminalInstance, linkProvider: ITerminalExternalLinkProvider): IDisposable { |
151 | 159 | 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; |
153 | 164 | } |
154 | 165 |
|
155 | 166 | protected _wrapLinkHandler(handler: (event: MouseEvent | undefined, link: string) => void): XtermLinkMatcherHandler { |
|
0 commit comments