@@ -19,6 +19,9 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
19
19
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
20
20
import { PeekContext } from 'vs/editor/contrib/referenceSearch/peekViewWidget' ;
21
21
import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
22
+ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
23
+ import { Range } from 'vs/editor/common/core/range' ;
24
+ import { IPosition } from 'vs/editor/common/core/position' ;
22
25
23
26
const _ctxHasCompletionItemProvider = new RawContextKey < boolean > ( 'editorHasCallHierarchyProvider' , false ) ;
24
27
const _ctxCallHierarchyVisible = new RawContextKey < boolean > ( 'callHierarchyVisible' , false ) ;
@@ -44,6 +47,7 @@ class CallHierarchyController implements IEditorContribution {
44
47
private readonly _editor : ICodeEditor ,
45
48
@IContextKeyService private readonly _contextKeyService : IContextKeyService ,
46
49
@IStorageService private readonly _storageService : IStorageService ,
50
+ @ICodeEditorService private readonly _editorService : ICodeEditorService ,
47
51
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
48
52
) {
49
53
this . _ctxIsVisible = _ctxCallHierarchyVisible . bindTo ( this . _contextKeyService ) ;
@@ -60,7 +64,7 @@ class CallHierarchyController implements IEditorContribution {
60
64
this . _dispoables . dispose ( ) ;
61
65
}
62
66
63
- async startCallHierarchy ( ) : Promise < void > {
67
+ async startCallHierarchyFromEditor ( ) : Promise < void > {
64
68
this . _sessionDisposables . clear ( ) ;
65
69
66
70
if ( ! this . _editor . hasModel ( ) ) {
@@ -73,42 +77,65 @@ class CallHierarchyController implements IEditorContribution {
73
77
return ;
74
78
}
75
79
80
+ const cts = new CancellationTokenSource ( ) ;
81
+ const model = CallHierarchyModel . create ( document , position , cts . token ) ;
76
82
const direction = this . _storageService . getNumber ( CallHierarchyController . _StorageDirection , StorageScope . GLOBAL , < number > CallHierarchyDirection . CallsFrom ) ;
77
83
78
- Event . any < any > ( this . _editor . onDidChangeModel , this . _editor . onDidChangeModelLanguage ) ( this . endCallHierarchy , this , this . _sessionDisposables ) ;
79
- this . _widget = this . _instantiationService . createInstance (
80
- CallHierarchyTreePeekWidget ,
81
- this . _editor ,
82
- position ,
83
- direction
84
+ this . _showCallHierarchyWidget ( position , direction , model , cts ) ;
85
+ }
86
+
87
+ async startCallHierarchyFromCallHierarchy ( ) : Promise < void > {
88
+ if ( ! this . _widget ) {
89
+ return ;
90
+ }
91
+ const model = this . _widget . getModel ( ) ;
92
+ const call = this . _widget . getFocused ( ) ;
93
+ if ( ! call || ! model ) {
94
+ return ;
95
+ }
96
+ const newEditor = await this . _editorService . openCodeEditor ( { resource : call . item . uri } , this . _editor ) ;
97
+ if ( ! newEditor ) {
98
+ return ;
99
+ }
100
+ const newModel = model . fork ( call . item ) ;
101
+ this . _sessionDisposables . clear ( ) ;
102
+
103
+ CallHierarchyController . get ( newEditor ) . _showCallHierarchyWidget (
104
+ Range . lift ( newModel . root . selectionRange ) . getStartPosition ( ) ,
105
+ this . _widget . direction ,
106
+ Promise . resolve ( newModel ) ,
107
+ new CancellationTokenSource ( )
84
108
) ;
109
+ }
85
110
111
+ private _showCallHierarchyWidget ( position : IPosition , direction : number , model : Promise < CallHierarchyModel | undefined > , cts : CancellationTokenSource ) {
112
+
113
+ Event . any < any > ( this . _editor . onDidChangeModel , this . _editor . onDidChangeModelLanguage ) ( this . endCallHierarchy , this , this . _sessionDisposables ) ;
114
+ this . _widget = this . _instantiationService . createInstance ( CallHierarchyTreePeekWidget , this . _editor , position , direction ) ;
86
115
this . _widget . showLoading ( ) ;
87
116
this . _ctxIsVisible . set ( true ) ;
88
-
89
- const cts = new CancellationTokenSource ( ) ;
90
-
91
117
this . _sessionDisposables . add ( this . _widget . onDidClose ( ( ) => {
92
118
this . endCallHierarchy ( ) ;
93
119
this . _storageService . store ( CallHierarchyController . _StorageDirection , this . _widget ! . direction , StorageScope . GLOBAL ) ;
94
120
} ) ) ;
95
121
this . _sessionDisposables . add ( { dispose ( ) { cts . dispose ( true ) ; } } ) ;
96
122
this . _sessionDisposables . add ( this . _widget ) ;
97
123
98
- try {
99
- const model = await CallHierarchyModel . create ( document , position , cts . token ) ;
124
+ model . then ( model => {
100
125
if ( cts . token . isCancellationRequested ) {
101
126
return ; // nothing
102
- } else if ( model ) {
127
+ }
128
+ if ( model ) {
103
129
this . _sessionDisposables . add ( model ) ;
104
- this . _widget . showModel ( model ) ;
105
- } else {
106
- this . _widget . showMessage ( localize ( 'no.item' , "No results" ) ) ;
130
+ this . _widget ! . showModel ( model ) ;
107
131
}
108
- } catch ( e ) {
109
- this . _widget . showMessage ( localize ( 'error' , "Failed to show call hierarchy" ) ) ;
132
+ else {
133
+ this . _widget ! . showMessage ( localize ( 'no.item' , "No results" ) ) ;
134
+ }
135
+ } ) . catch ( e => {
136
+ this . _widget ! . showMessage ( localize ( 'error' , "Failed to show call hierarchy" ) ) ;
110
137
console . error ( e ) ;
111
- }
138
+ } ) ;
112
139
}
113
140
114
141
toggleCallHierarchyDirection ( ) : void {
@@ -151,7 +178,7 @@ registerEditorAction(class extends EditorAction {
151
178
}
152
179
153
180
async run ( _accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
154
- return CallHierarchyController . get ( editor ) . startCallHierarchy ( ) ;
181
+ return CallHierarchyController . get ( editor ) . startCallHierarchyFromEditor ( ) ;
155
182
}
156
183
} ) ;
157
184
@@ -175,6 +202,26 @@ registerEditorAction(class extends EditorAction {
175
202
}
176
203
} ) ;
177
204
205
+ registerEditorAction ( class extends EditorAction {
206
+
207
+ constructor ( ) {
208
+ super ( {
209
+ id : 'editor.refocusCallHierarchy' ,
210
+ label : localize ( 'title.refocus' , "Refocus Call Hierarchy" ) ,
211
+ alias : 'Refocus Call Hierarchy' ,
212
+ kbOpts : {
213
+ weight : KeybindingWeight . WorkbenchContrib ,
214
+ primary : KeyMod . Shift + KeyCode . Enter
215
+ } ,
216
+ precondition : _ctxCallHierarchyVisible
217
+ } ) ;
218
+ }
219
+
220
+ async run ( _accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
221
+ return CallHierarchyController . get ( editor ) . startCallHierarchyFromCallHierarchy ( ) ;
222
+ }
223
+ } ) ;
224
+
178
225
179
226
registerEditorCommand ( new class extends EditorCommand {
180
227
0 commit comments