mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Dynamically import WebLinksAddon
This commit is contained in:
parent
3740c2b482
commit
2997821694
|
@ -4,6 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Terminal as XTermTerminal } from 'xterm';
|
||||
import { WebLinksAddon as XTermWebLinksAddon } from 'xterm-addon-web-links';
|
||||
import { ITerminalInstance, IWindowsShellHelper, ITerminalConfigHelper, ITerminalChildProcess, IShellLaunchConfig } from 'vs/workbench/contrib/terminal/common/terminal';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IProcessEnvironment, Platform } from 'vs/base/common/platform';
|
||||
|
@ -14,6 +15,7 @@ export interface ITerminalInstanceService {
|
|||
_serviceBrand: any;
|
||||
|
||||
getXtermConstructor(): Promise<typeof XTermTerminal>;
|
||||
getXtermWebLinksConstructor(): Promise<typeof XTermWebLinksAddon>;
|
||||
createWindowsShellHelper(shellProcessId: number, instance: ITerminalInstance, xterm: XTermTerminal): IWindowsShellHelper;
|
||||
createTerminalProcess(shellLaunchConfig: IShellLaunchConfig, cwd: string, cols: number, rows: number, env: IProcessEnvironment, windowsEnableConpty: boolean): ITerminalChildProcess;
|
||||
getDefaultShell(p: Platform): string;
|
||||
|
|
|
@ -17,7 +17,7 @@ import { IFileService } from 'vs/platform/files/common/files';
|
|||
import { ILinkMatcherOptions } from 'xterm';
|
||||
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
|
||||
import { posix, win32 } from 'vs/base/common/path';
|
||||
import { WebLinksAddon } from 'xterm-addon-web-links';
|
||||
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
|
||||
const pathPrefix = '(\\.\\.?|\\~)';
|
||||
const pathSeparatorClause = '\\/';
|
||||
|
@ -82,6 +82,7 @@ export class TerminalLinkHandler {
|
|||
@IEditorService private readonly _editorService: IEditorService,
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService,
|
||||
@ITerminalService private readonly _terminalService: ITerminalService,
|
||||
@ITerminalInstanceService private readonly _terminalInstanceService: ITerminalInstanceService,
|
||||
@IFileService private readonly _fileService: IFileService
|
||||
) {
|
||||
// Matches '--- a/src/file1', capturing 'src/file1' in group 1
|
||||
|
@ -136,15 +137,17 @@ export class TerminalLinkHandler {
|
|||
}
|
||||
|
||||
public registerWebLinkHandler(): void {
|
||||
const wrappedHandler = this._wrapLinkHandler(uri => {
|
||||
this._handleHypertextLink(uri);
|
||||
this._terminalInstanceService.getXtermWebLinksConstructor().then((WebLinksAddon) => {
|
||||
const wrappedHandler = this._wrapLinkHandler(uri => {
|
||||
this._handleHypertextLink(uri);
|
||||
});
|
||||
this._xterm.loadAddon(new WebLinksAddon(wrappedHandler, {
|
||||
validationCallback: (uri: string, callback: (isValid: boolean) => void) => this._validateWebLink(uri, callback),
|
||||
tooltipCallback: this._tooltipCallback,
|
||||
leaveCallback: this._leaveCallback,
|
||||
willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e)
|
||||
}));
|
||||
});
|
||||
this._xterm.loadAddon(new WebLinksAddon(wrappedHandler, {
|
||||
validationCallback: (uri: string, callback: (isValid: boolean) => void) => this._validateWebLink(uri, callback),
|
||||
tooltipCallback: this._tooltipCallback,
|
||||
leaveCallback: this._leaveCallback,
|
||||
willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e)
|
||||
}));
|
||||
}
|
||||
|
||||
public registerLocalLinkHandler(): void {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { Terminal as XTermTerminal } from 'xterm';
|
||||
import { WebLinksAddon as XTermWebLinksAddon } from 'xterm-addon-web-links';
|
||||
import { ITerminalInstance, IWindowsShellHelper, IShellLaunchConfig, ITerminalChildProcess } from 'vs/workbench/contrib/terminal/common/terminal';
|
||||
import { WindowsShellHelper } from 'vs/workbench/contrib/terminal/node/windowsShellHelper';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
@ -13,6 +14,7 @@ import { TerminalProcess } from 'vs/workbench/contrib/terminal/node/terminalProc
|
|||
import { getDefaultShell } from 'vs/workbench/contrib/terminal/node/terminal';
|
||||
|
||||
let Terminal: typeof XTermTerminal;
|
||||
let WebLinksAddon: typeof XTermWebLinksAddon;
|
||||
|
||||
/**
|
||||
* A service used by TerminalInstance (and components owned by it) that allows it to break its
|
||||
|
@ -34,6 +36,13 @@ export class TerminalInstanceService implements ITerminalInstanceService {
|
|||
return Terminal;
|
||||
}
|
||||
|
||||
public async getXtermWebLinksConstructor(): Promise<typeof XTermWebLinksAddon> {
|
||||
if (!WebLinksAddon) {
|
||||
WebLinksAddon = (await import('xterm-addon-web-links')).WebLinksAddon;
|
||||
}
|
||||
return WebLinksAddon;
|
||||
}
|
||||
|
||||
public createWindowsShellHelper(shellProcessId: number, instance: ITerminalInstance, xterm: XTermTerminal): IWindowsShellHelper {
|
||||
return new WindowsShellHelper(shellProcessId, instance, xterm);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue