Skip to content

Commit

Permalink
Move terminalLinkHandler, electron-browser->browser
Browse files Browse the repository at this point in the history
Part of #69115
  • Loading branch information
Tyriar committed Mar 5, 2019
1 parent 47977b9 commit fe169ce
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
"./vs/workbench/contrib/surveys/electron-browser/nps.contribution.ts",

"./vs/workbench/contrib/terminal/browser/terminalFindWidget.ts",
"./vs/workbench/contrib/terminal/browser/terminalLinkHandler.ts",
"./vs/workbench/contrib/terminal/browser/terminalQuickOpen.ts",
"./vs/workbench/contrib/terminal/browser/terminalTab.ts",
"./vs/workbench/contrib/terminal/browser/terminalWidgetManager.ts",
Expand All @@ -290,7 +291,6 @@
"./vs/workbench/contrib/terminal/electron-browser/terminalActions.ts",
"./vs/workbench/contrib/terminal/electron-browser/terminalConfigHelper.ts",
"./vs/workbench/contrib/terminal/electron-browser/terminalInstance.ts",
"./vs/workbench/contrib/terminal/electron-browser/terminalLinkHandler.ts",
"./vs/workbench/contrib/terminal/electron-browser/terminalPanel.ts",
"./vs/workbench/contrib/terminal/electron-browser/terminalProcessManager.ts",
"./vs/workbench/contrib/terminal/node/terminal.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,61 @@
import * as nls from 'vs/nls';
import * as path from 'vs/base/common/path';
import * as platform from 'vs/base/common/platform';
import * as pfs from 'vs/base/node/pfs';
import { URI as Uri } from 'vs/base/common/uri';
import { URI } from 'vs/base/common/uri';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/terminalWidgetManager';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ITerminalService } from 'vs/workbench/contrib/terminal/common/terminal';
import { ITextEditorSelection } from 'vs/platform/editor/common/editor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ILinkMatcherOptions } from 'vscode-xterm';
import { IFileService } from 'vs/platform/files/common/files';

// Since importing from vscode-xterm would be a layer breakage here the type is copied inline
// import { ILinkMatcherOptions } from 'vscode-xterm';

/**
* An object containing options for a link matcher.
*/
export interface ILinkMatcherOptions {
/**
* The index of the link from the regex.match(text) call. This defaults to 0
* (for regular expressions without capture groups).
*/
matchIndex?: number;

/**
* A callback that validates whether to create an individual link, pass
* whether the link is valid to the callback.
*/
validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void;

/**
* A callback that fires when the mouse hovers over a link for a moment.
*/
tooltipCallback?: (event: MouseEvent, uri: string) => boolean | void;

/**
* A callback that fires when the mouse leaves a link. Note that this can
* happen even when tooltipCallback hasn't fired for the link yet.
*/
leaveCallback?: (event: MouseEvent, uri: string) => boolean | void;

/**
* The priority of the link matcher, this defines the order in which the link
* matcher is evaluated relative to others, from highest to lowest. The
* default value is 0.
*/
priority?: number;

/**
* A callback that fires when the mousedown and click events occur that
* determines whether a link will be activated upon click. This enables
* only activating a link when a certain modifier is held down, if not the
* mouse event will continue propagation (eg. double click to select word).
*/
willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
}

const pathPrefix = '(\\.\\.?|\\~)';
const pathSeparatorClause = '\\/';
Expand Down Expand Up @@ -74,6 +119,7 @@ export class TerminalLinkHandler {
@IEditorService private readonly _editorService: IEditorService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@ITerminalService private readonly _terminalService: ITerminalService,
@IFileService private readonly _fileService: IFileService
) {
const baseLocalLinkClause = _platform === platform.Platform.Windows ? winLocalLinkClause : unixLocalLinkClause;
// Append line and column number regex
Expand Down Expand Up @@ -203,7 +249,7 @@ export class TerminalLinkHandler {
if (!normalizedUrl) {
return Promise.resolve(null);
}
const resource = Uri.file(normalizedUrl);
const resource = URI.file(normalizedUrl);
const lineColumnInfo: LineColumnInfo = this.extractLineColumnInfo(link);
const selection: ITextEditorSelection = {
startLineNumber: lineColumnInfo.lineNumber,
Expand All @@ -223,7 +269,7 @@ export class TerminalLinkHandler {
}

private _handleHypertextLink(url: string): void {
const uri = Uri.parse(url);
const uri = URI.parse(url);
this._openerService.open(uri);
}

Expand Down Expand Up @@ -288,7 +334,7 @@ export class TerminalLinkHandler {
}

// Ensure the file exists on disk, so an editor can be opened after clicking it
return pfs.fileExists(linkUrl).then(isFile => {
return this._fileService.existsFile(URI.file(linkUrl)).then(isFile => {
if (!isFile) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { IShellLaunchConfig, ITerminalDimensions, ITerminalInstance, ITerminalPr
import { ansiColorIdentifiers, TERMINAL_BACKGROUND_COLOR, TERMINAL_CURSOR_BACKGROUND_COLOR, TERMINAL_CURSOR_FOREGROUND_COLOR, TERMINAL_FOREGROUND_COLOR, TERMINAL_SELECTION_BACKGROUND_COLOR } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
import { TERMINAL_COMMAND_ID } from 'vs/workbench/contrib/terminal/common/terminalCommands';
import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/electron-browser/terminalConfigHelper';
import { TerminalLinkHandler } from 'vs/workbench/contrib/terminal/electron-browser/terminalLinkHandler';
import { TerminalLinkHandler } from 'vs/workbench/contrib/terminal/browser/terminalLinkHandler';
import { TerminalProcessManager } from 'vs/workbench/contrib/terminal/electron-browser/terminalProcessManager';
import { TerminalCommandTracker } from 'vs/workbench/contrib/terminal/node/terminalCommandTracker';
import { WindowsShellHelper } from 'vs/workbench/contrib/terminal/node/windowsShellHelper';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as assert from 'assert';
import { Platform } from 'vs/base/common/platform';
import { TerminalLinkHandler, LineColumnInfo } from 'vs/workbench/contrib/terminal/electron-browser/terminalLinkHandler';
import { TerminalLinkHandler, LineColumnInfo } from 'vs/workbench/contrib/terminal/browser/terminalLinkHandler';
import * as strings from 'vs/base/common/strings';
import * as path from 'vs/base/common/path';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -39,7 +39,7 @@ interface LinkFormatInfo {
suite('Workbench - TerminalLinkHandler', () => {
suite('localLinkRegex', () => {
test('Windows', () => {
const terminalLinkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Windows, null!, null!, null!, null!);
const terminalLinkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Windows, null!, 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 @@ -111,7 +111,7 @@ suite('Workbench - TerminalLinkHandler', () => {
});

test('Linux', () => {
const terminalLinkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null!, null!, null!, null!);
const terminalLinkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null!, 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 @@ -175,7 +175,7 @@ suite('Workbench - TerminalLinkHandler', () => {

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

let stub = sinon.stub(path, 'join', function (arg1: string, arg2: string) {
Expand All @@ -188,7 +188,7 @@ suite('Workbench - TerminalLinkHandler', () => {
stub.restore();
});
test('Windows - spaces', () => {
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Windows, null!, null!, null!, null!);
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Windows, null!, null!, null!, null!, null!);
linkHandler.processCwd = 'C:\\base dir';

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

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

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

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

assert.equal(linkHandler.preprocessPath('./src/file1'), null);
assert.equal(linkHandler.preprocessPath('src/file2'), null);
Expand All @@ -226,7 +226,7 @@ suite('Workbench - TerminalLinkHandler', () => {

test('gitDiffLinkRegex', () => {
// The platform is irrelevant because the links generated by Git are the same format regardless of platform
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null!, null!, null!, null!);
const linkHandler = new TestTerminalLinkHandler(new TestXterm(), Platform.Linux, null!, null!, null!, null!, null!);

function assertAreGoodMatches(matches: RegExpMatchArray | null) {
if (matches) {
Expand Down

0 comments on commit fe169ce

Please sign in to comment.