4
4
import '../../common/extensions' ;
5
5
6
6
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' ;
8
8
9
- import { IApplicationShell , IDocumentManager } from '../../common/application/types' ;
9
+ import { IApplicationShell , ICommandManager , IDocumentManager } from '../../common/application/types' ;
10
10
import { IFileSystem } from '../../common/platform/types' ;
11
11
import * as localize from '../../common/utils/localize' ;
12
12
import { noop } from '../../common/utils/misc' ;
@@ -22,7 +22,8 @@ export class LinkProvider implements IInteractiveWindowListener {
22
22
constructor (
23
23
@inject ( IApplicationShell ) private applicationShell : IApplicationShell ,
24
24
@inject ( IFileSystem ) private fileSystem : IFileSystem ,
25
- @inject ( IDocumentManager ) private documentManager : IDocumentManager
25
+ @inject ( IDocumentManager ) private documentManager : IDocumentManager ,
26
+ @inject ( ICommandManager ) private commandManager : ICommandManager
26
27
) {
27
28
noop ( ) ;
28
29
}
@@ -85,13 +86,22 @@ export class LinkProvider implements IInteractiveWindowListener {
85
86
}
86
87
87
88
// 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 ) ) ;
89
90
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 ) ;
92
93
} ) ;
93
94
} 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
+ } ) ;
95
105
}
96
106
}
97
107
}
0 commit comments