Skip to content

Commit abff373

Browse files
committed
Fix hyperlinks (#5766)
1 parent 67c38d7 commit abff373

10 files changed

Lines changed: 87 additions & 40 deletions

File tree

news/2 Fixes/5630.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for opening hyperlinks from the interactive window.

package-lock.json

Lines changed: 21 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/datascience/history/historyTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export namespace HistoryMessages {
5353
export const LoadOnigasmAssemblyResponse = 'load_onigasm_assembly_response';
5454
export const LoadTmLanguageRequest = 'load_tmlanguage_request';
5555
export const LoadTmLanguageResponse = 'load_tmlanguage_response';
56+
export const OpenLink = 'open_link';
5657
}
5758

5859
// These are the messages that will mirror'd to guest/hosts in
@@ -198,4 +199,5 @@ export class IHistoryMapping {
198199
public [HistoryMessages.LoadOnigasmAssemblyResponse]: Buffer;
199200
public [HistoryMessages.LoadTmLanguageRequest]: never | undefined;
200201
public [HistoryMessages.LoadTmLanguageResponse]: string | undefined;
202+
public [HistoryMessages.OpenLink]: string | undefined;
201203
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
'use strict';
4+
import '../../common/extensions';
5+
6+
import { inject, injectable } from 'inversify';
7+
import { Event, EventEmitter } from 'vscode';
8+
9+
import { IApplicationShell } from '../../common/application/types';
10+
import { noop } from '../../common/utils/misc';
11+
import { IHistoryListener } from '../types';
12+
import { HistoryMessages } from './historyTypes';
13+
14+
// tslint:disable: no-any
15+
@injectable()
16+
export class LinkProvider implements IHistoryListener {
17+
private postEmitter: EventEmitter<{message: string; payload: any}> = new EventEmitter<{message: string; payload: any}>();
18+
constructor(@inject(IApplicationShell) private applicationShell: IApplicationShell) {
19+
noop();
20+
}
21+
22+
public get postMessage(): Event<{ message: string; payload: any }> {
23+
return this.postEmitter.event;
24+
}
25+
26+
public onMessage(message: string, payload?: any): void {
27+
switch (message) {
28+
case HistoryMessages.OpenLink:
29+
if (payload) {
30+
this.applicationShell.openUrl(payload.toString());
31+
}
32+
break;
33+
default:
34+
break;
35+
}
36+
}
37+
public dispose(): void | undefined {
38+
noop();
39+
}
40+
}

src/client/datascience/serviceRegistry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { HistoryCommandListener } from './history/historycommandlistener';
1515
import { HistoryProvider } from './history/historyProvider';
1616
import { DotNetIntellisenseProvider } from './history/intellisense/dotNetIntellisenseProvider';
1717
import { JediIntellisenseProvider } from './history/intellisense/jediIntellisenseProvider';
18+
import { LinkProvider } from './history/linkProvider';
1819
import { JupyterCommandFactory } from './jupyter/jupyterCommand';
1920
import { JupyterExecutionFactory } from './jupyter/jupyterExecutionFactory';
2021
import { JupyterExporter } from './jupyter/jupyterExporter';
@@ -68,4 +69,5 @@ export function registerTypes(serviceManager: IServiceManager) {
6869
serviceManager.addSingleton<IExtensionActivationService>(IExtensionActivationService, Decorator);
6970
serviceManager.add<IHistoryListener>(IHistoryListener, DotNetIntellisenseProvider);
7071
serviceManager.add<IHistoryListener>(IHistoryListener, JediIntellisenseProvider);
72+
serviceManager.add<IHistoryListener>(IHistoryListener, LinkProvider);
7173
}

src/datascience-ui/history-react/MainPanel.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
314314
onCodeCreated={this.editableCodeCreated}
315315
onCodeChange={this.codeChange}
316316
monacoTheme={this.state.monacoTheme}
317+
openLink={this.openLink}
317318
/>
318319
</ErrorBoundary>
319320
</div>
@@ -400,7 +401,8 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
400401
skipNextScroll: this.state.skipNextScroll ? true : false,
401402
monacoTheme: this.state.monacoTheme,
402403
onCodeCreated: this.readOnlyCodeCreated,
403-
onCodeChange: this.codeChange
404+
onCodeChange: this.codeChange,
405+
openLink: this.openLink
404406
};
405407
}
406408
private getToolbarProps = (baseTheme: string): IToolbarPanelProps => {
@@ -481,6 +483,10 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
481483
this.postOffice.sendMessage<M, T>(type, payload);
482484
}
483485

486+
private openLink = (uri: monacoEditor.Uri) => {
487+
this.sendMessage(HistoryMessages.OpenLink, uri.toString());
488+
}
489+
484490
private getAllCells = () => {
485491
// Send all of our cells back to the other side
486492
const cells = this.state.cellVMs.map((cellVM : ICellViewModel) => {

src/datascience-ui/history-react/cell.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ interface ICellProps {
4646
submitNewCode(code: string): void;
4747
onCodeChange(changes: monacoEditor.editor.IModelContentChange[], cellId: string, modelId: string): void;
4848
onCodeCreated(code: string, file: string, cellId: string, modelId: string): void;
49+
openLink(uri: monacoEditor.Uri): void;
4950
}
5051

5152
export interface ICellViewModel {
@@ -228,6 +229,7 @@ export class Cell extends React.Component<ICellProps> {
228229
onCreated={this.onCodeCreated}
229230
outermostParentClass='cell-wrapper'
230231
monacoTheme={this.props.monacoTheme}
232+
openLink={this.props.openLink}
231233
/>
232234
</div>
233235
);

src/datascience-ui/history-react/code.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ICodeProps {
2626
onSubmit(code: string): void;
2727
onCreated(code: string, modelId: string): void;
2828
onChange(changes: monacoEditor.editor.IModelContentChange[], modelId: string): void;
29+
openLink(uri: monacoEditor.Uri): void;
2930
}
3031

3132
interface ICodeState {
@@ -100,6 +101,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
100101
language='python'
101102
editorMounted={this.editorDidMount}
102103
options={options}
104+
openLink={this.props.openLink}
103105
/>
104106
<div className={waterMarkClass}>{this.getWatermarkString()}</div>
105107
</div>

0 commit comments

Comments
 (0)