Skip to content

Commit ead69d5

Browse files
authored
Fix open to work for non text documents (#9994)
* Fix open to support more than just text documents on link clicks * Update selection too
1 parent 513d479 commit ead69d5

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/client/common/application/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
8686
['revealLine']: [{ lineNumber: number; at: 'top' | 'center' | 'bottom' }];
8787
['python._loadLanguageServerExtension']: {}[];
8888
['python.SelectAndInsertDebugConfiguration']: [TextDocument, Position, CancellationToken];
89+
['vscode.open']: [Uri];
8990
['python.viewLanguageServerOutput']: [];
9091
[Commands.Build_Workspace_Symbols]: [boolean, CancellationToken];
9192
[Commands.Sort_Imports]: [undefined, Uri];

src/client/datascience/interactive-common/linkProvider.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import '../../common/extensions';
55

66
import { inject, injectable } from 'inversify';
7-
import { Event, EventEmitter, Position, Range, TextEditorRevealType, Uri } from 'vscode';
7+
import { Event, EventEmitter, Position, Range, Selection, TextEditorRevealType, Uri } from 'vscode';
88

9-
import { IApplicationShell, IDocumentManager } from '../../common/application/types';
9+
import { IApplicationShell, ICommandManager, IDocumentManager } from '../../common/application/types';
1010
import { IFileSystem } from '../../common/platform/types';
1111
import * as localize from '../../common/utils/localize';
1212
import { noop } from '../../common/utils/misc';
@@ -22,7 +22,8 @@ export class LinkProvider implements IInteractiveWindowListener {
2222
constructor(
2323
@inject(IApplicationShell) private applicationShell: IApplicationShell,
2424
@inject(IFileSystem) private fileSystem: IFileSystem,
25-
@inject(IDocumentManager) private documentManager: IDocumentManager
25+
@inject(IDocumentManager) private documentManager: IDocumentManager,
26+
@inject(ICommandManager) private commandManager: ICommandManager
2627
) {
2728
noop();
2829
}
@@ -85,13 +86,22 @@ export class LinkProvider implements IInteractiveWindowListener {
8586
}
8687

8788
// Show the matching editor if there is one
88-
const editor = this.documentManager.visibleTextEditors.find(e => this.fileSystem.arePathsSame(e.document.fileName, uri.fsPath));
89+
let editor = this.documentManager.visibleTextEditors.find(e => this.fileSystem.arePathsSame(e.document.fileName, uri.fsPath));
8990
if (editor) {
90-
this.documentManager.showTextDocument(editor.document, { selection, viewColumn: editor.viewColumn }).then(() => {
91-
editor.revealRange(selection, TextEditorRevealType.InCenter);
91+
this.documentManager.showTextDocument(editor.document, { selection, viewColumn: editor.viewColumn }).then(e => {
92+
e.revealRange(selection, TextEditorRevealType.InCenter);
9293
});
9394
} else {
94-
this.documentManager.showTextDocument(uri, { selection });
95+
// Not a visible editor, try opening otherwise
96+
this.commandManager.executeCommand('vscode.open', uri).then(() => {
97+
// See if that opened a text document
98+
editor = this.documentManager.visibleTextEditors.find(e => this.fileSystem.arePathsSame(e.document.fileName, uri.fsPath));
99+
if (editor) {
100+
// Force the selection to change
101+
editor.revealRange(selection);
102+
editor.selection = new Selection(selection.start, selection.start);
103+
}
104+
});
95105
}
96106
}
97107
}

0 commit comments

Comments
 (0)