@@ -9,7 +9,7 @@ import { CancellationTokenSource } from 'vs/base/common/cancellation';
99import { IInstantiationService , ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
1010import { CallHierarchyTreePeekWidget } from 'vs/workbench/contrib/callHierarchy/browser/callHierarchyPeek' ;
1111import { Event } from 'vs/base/common/event' ;
12- import { registerEditorContribution , registerEditorAction , EditorAction , registerEditorCommand , EditorCommand } from 'vs/editor/browser/editorExtensions' ;
12+ import { registerEditorContribution , EditorAction2 } from 'vs/editor/browser/editorExtensions' ;
1313import { IEditorContribution } from 'vs/editor/common/editorCommon' ;
1414import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
1515import { IContextKeyService , RawContextKey , IContextKey , ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey' ;
@@ -22,10 +22,18 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
2222import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
2323import { Range } from 'vs/editor/common/core/range' ;
2424import { IPosition } from 'vs/editor/common/core/position' ;
25- import { MenuId } from 'vs/platform/actions/common/actions' ;
25+ import { MenuId , registerAction2 } from 'vs/platform/actions/common/actions' ;
26+ import { registerIcon , Codicon } from 'vs/base/common/codicons' ;
2627
2728const _ctxHasCallHierarchyProvider = new RawContextKey < boolean > ( 'editorHasCallHierarchyProvider' , false ) ;
2829const _ctxCallHierarchyVisible = new RawContextKey < boolean > ( 'callHierarchyVisible' , false ) ;
30+ const _ctxCallHierarchyDirection = new RawContextKey < string > ( 'callHierarchyDirection' , undefined ) ;
31+
32+ function sanitizedDirection ( candidate : string ) : CallHierarchyDirection {
33+ return candidate === CallHierarchyDirection . CallsFrom || candidate === CallHierarchyDirection . CallsTo
34+ ? candidate
35+ : CallHierarchyDirection . CallsTo ;
36+ }
2937
3038class CallHierarchyController implements IEditorContribution {
3139
@@ -39,6 +47,7 @@ class CallHierarchyController implements IEditorContribution {
3947
4048 private readonly _ctxHasProvider : IContextKey < boolean > ;
4149 private readonly _ctxIsVisible : IContextKey < boolean > ;
50+ private readonly _ctxDirection : IContextKey < string > ;
4251 private readonly _dispoables = new DisposableStore ( ) ;
4352 private readonly _sessionDisposables = new DisposableStore ( ) ;
4453
@@ -53,6 +62,7 @@ class CallHierarchyController implements IEditorContribution {
5362 ) {
5463 this . _ctxIsVisible = _ctxCallHierarchyVisible . bindTo ( this . _contextKeyService ) ;
5564 this . _ctxHasProvider = _ctxHasCallHierarchyProvider . bindTo ( this . _contextKeyService ) ;
65+ this . _ctxDirection = _ctxCallHierarchyDirection . bindTo ( this . _contextKeyService ) ;
5666 this . _dispoables . add ( Event . any < any > ( _editor . onDidChangeModel , _editor . onDidChangeModelLanguage , CallHierarchyProviderRegistry . onDidChange ) ( ( ) => {
5767 this . _ctxHasProvider . set ( _editor . hasModel ( ) && CallHierarchyProviderRegistry . has ( _editor . getModel ( ) ) ) ;
5868 } ) ) ;
@@ -80,7 +90,7 @@ class CallHierarchyController implements IEditorContribution {
8090
8191 const cts = new CancellationTokenSource ( ) ;
8292 const model = CallHierarchyModel . create ( document , position , cts . token ) ;
83- const direction = this . _storageService . getNumber ( CallHierarchyController . _StorageDirection , StorageScope . GLOBAL , < number > CallHierarchyDirection . CallsFrom ) ;
93+ const direction = sanitizedDirection ( this . _storageService . get ( CallHierarchyController . _StorageDirection , StorageScope . GLOBAL , CallHierarchyDirection . CallsTo ) ) ;
8494
8595 this . _showCallHierarchyWidget ( position , direction , model , cts ) ;
8696 }
@@ -109,12 +119,13 @@ class CallHierarchyController implements IEditorContribution {
109119 ) ;
110120 }
111121
112- private _showCallHierarchyWidget ( position : IPosition , direction : number , model : Promise < CallHierarchyModel | undefined > , cts : CancellationTokenSource ) {
122+ private _showCallHierarchyWidget ( position : IPosition , direction : CallHierarchyDirection , model : Promise < CallHierarchyModel | undefined > , cts : CancellationTokenSource ) {
113123
124+ this . _ctxIsVisible . set ( true ) ;
125+ this . _ctxDirection . set ( direction ) ;
114126 Event . any < any > ( this . _editor . onDidChangeModel , this . _editor . onDidChangeModelLanguage ) ( this . endCallHierarchy , this , this . _sessionDisposables ) ;
115127 this . _widget = this . _instantiationService . createInstance ( CallHierarchyTreePeekWidget , this . _editor , position , direction ) ;
116128 this . _widget . showLoading ( ) ;
117- this . _ctxIsVisible . set ( true ) ;
118129 this . _sessionDisposables . add ( this . _widget . onDidClose ( ( ) => {
119130 this . endCallHierarchy ( ) ;
120131 this . _storageService . store ( CallHierarchyController . _StorageDirection , this . _widget ! . direction , StorageScope . GLOBAL ) ;
@@ -139,10 +150,14 @@ class CallHierarchyController implements IEditorContribution {
139150 } ) ;
140151 }
141152
142- toggleCallHierarchyDirection ( ) : void {
143- if ( this . _widget ) {
144- this . _widget . toggleDirection ( ) ;
145- }
153+ showOutgoingCalls ( ) : void {
154+ this . _widget ?. updateDirection ( CallHierarchyDirection . CallsFrom ) ;
155+ this . _ctxDirection . set ( CallHierarchyDirection . CallsFrom ) ;
156+ }
157+
158+ showIncomingCalls ( ) : void {
159+ this . _widget ?. updateDirection ( CallHierarchyDirection . CallsTo ) ;
160+ this . _ctxDirection . set ( CallHierarchyDirection . CallsTo ) ;
146161 }
147162
148163 endCallHierarchy ( ) : void {
@@ -154,20 +169,19 @@ class CallHierarchyController implements IEditorContribution {
154169
155170registerEditorContribution ( CallHierarchyController . Id , CallHierarchyController ) ;
156171
157- registerEditorAction ( class extends EditorAction {
172+ registerAction2 ( class extends EditorAction2 {
158173
159174 constructor ( ) {
160175 super ( {
161176 id : 'editor.showCallHierarchy' ,
162- label : localize ( 'title' , "Peek Call Hierarchy" ) ,
163- alias : 'Peek Call Hierarchy' ,
164- contextMenuOpts : {
165- menuId : MenuId . EditorContextPeek ,
177+ title : { value : localize ( 'title' , "Peek Call Hierarchy" ) , original : 'Peek Call Hierarchy' } ,
178+ menu : {
179+ id : MenuId . EditorContextPeek ,
166180 group : 'navigation' ,
167181 order : 1000
168182 } ,
169- kbOpts : {
170- kbExpr : EditorContextKeys . editorTextFocus ,
183+ keybinding : {
184+ when : EditorContextKeys . editorTextFocus ,
171185 weight : KeybindingWeight . WorkbenchContrib ,
172186 primary : KeyMod . Shift + KeyMod . Alt + KeyCode . KEY_H
173187 } ,
@@ -178,65 +192,101 @@ registerEditorAction(class extends EditorAction {
178192 } ) ;
179193 }
180194
181- async run ( _accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
195+ async runEditorCommand ( _accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
182196 return CallHierarchyController . get ( editor ) . startCallHierarchyFromEditor ( ) ;
183197 }
184198} ) ;
185199
186- registerEditorAction ( class extends EditorAction {
200+ registerAction2 ( class extends EditorAction2 {
187201
188202 constructor ( ) {
189203 super ( {
190- id : 'editor.toggleCallHierarchy' ,
191- label : localize ( 'title.toggle' , "Toggle Call Hierarchy" ) ,
192- alias : 'Toggle Call Hierarchy' ,
193- kbOpts : {
204+ id : 'editor.showIncomingCalls' ,
205+ title : { value : localize ( 'title.incoming' , "Show Incoming Calls" ) , original : 'Show Incoming Calls' } ,
206+ icon : registerIcon ( 'callhierarchy-incoming' , Codicon . callIncoming ) ,
207+ precondition : ContextKeyExpr . and ( _ctxCallHierarchyVisible , _ctxCallHierarchyDirection . isEqualTo ( CallHierarchyDirection . CallsFrom ) ) ,
208+ keybinding : {
194209 weight : KeybindingWeight . WorkbenchContrib ,
195- primary : KeyMod . Shift + KeyMod . Alt + KeyCode . KEY_H
210+ primary : KeyMod . Shift + KeyMod . Alt + KeyCode . KEY_H ,
196211 } ,
197- precondition : _ctxCallHierarchyVisible
212+ menu : {
213+ id : CallHierarchyTreePeekWidget . TitleMenu ,
214+ when : _ctxCallHierarchyDirection . isEqualTo ( CallHierarchyDirection . CallsFrom ) ,
215+ order : 1 ,
216+ }
198217 } ) ;
199218 }
200219
201- async run ( _accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
202- return CallHierarchyController . get ( editor ) . toggleCallHierarchyDirection ( ) ;
220+ runEditorCommand ( _accessor : ServicesAccessor , editor : ICodeEditor ) {
221+ return CallHierarchyController . get ( editor ) . showIncomingCalls ( ) ;
203222 }
204223} ) ;
205224
206- registerEditorAction ( class extends EditorAction {
225+ registerAction2 ( class extends EditorAction2 {
226+
227+ constructor ( ) {
228+ super ( {
229+ id : 'editor.showOutgoingCalls' ,
230+ title : { value : localize ( 'title.outgoing' , "Show Outgoing Calls" ) , original : 'Show Outgoing Calls' } ,
231+ icon : registerIcon ( 'callhierarchy-outgoing' , Codicon . callOutgoing ) ,
232+ precondition : ContextKeyExpr . and ( _ctxCallHierarchyVisible , _ctxCallHierarchyDirection . isEqualTo ( CallHierarchyDirection . CallsTo ) ) ,
233+ keybinding : {
234+ weight : KeybindingWeight . WorkbenchContrib ,
235+ primary : KeyMod . Shift + KeyMod . Alt + KeyCode . KEY_H ,
236+ } ,
237+ menu : {
238+ id : CallHierarchyTreePeekWidget . TitleMenu ,
239+ when : _ctxCallHierarchyDirection . isEqualTo ( CallHierarchyDirection . CallsTo ) ,
240+ order : 1
241+ }
242+ } ) ;
243+ }
244+
245+ runEditorCommand ( _accessor : ServicesAccessor , editor : ICodeEditor ) {
246+ return CallHierarchyController . get ( editor ) . showOutgoingCalls ( ) ;
247+ }
248+ } ) ;
249+
250+
251+ registerAction2 ( class extends EditorAction2 {
207252
208253 constructor ( ) {
209254 super ( {
210255 id : 'editor.refocusCallHierarchy' ,
211- label : localize ( 'title.refocus' , "Refocus Call Hierarchy" ) ,
212- alias : 'Refocus Call Hierarchy' ,
213- kbOpts : {
256+ title : { value : localize ( 'title.refocus' , "Refocus Call Hierarchy" ) , original : 'Refocus Call Hierarchy' } ,
257+ precondition : _ctxCallHierarchyVisible ,
258+ keybinding : {
214259 weight : KeybindingWeight . WorkbenchContrib ,
215260 primary : KeyMod . Shift + KeyCode . Enter
216- } ,
217- precondition : _ctxCallHierarchyVisible
261+ }
218262 } ) ;
219263 }
220264
221- async run ( _accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
265+ async runEditorCommand ( _accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
222266 return CallHierarchyController . get ( editor ) . startCallHierarchyFromCallHierarchy ( ) ;
223267 }
224268} ) ;
225269
226270
227- registerEditorCommand ( new class extends EditorCommand {
271+ registerAction2 ( class extends EditorAction2 {
228272
229273 constructor ( ) {
230274 super ( {
231275 id : 'editor.closeCallHierarchy' ,
232- kbOpts : {
233- weight : KeybindingWeight . WorkbenchContrib + 10 ,
234- primary : KeyCode . Escape
235- } ,
276+ title : localize ( 'close' , 'Close' ) ,
277+ icon : Codicon . close ,
236278 precondition : ContextKeyExpr . and (
237279 _ctxCallHierarchyVisible ,
238280 ContextKeyExpr . not ( 'config.editor.stablePeek' )
239- )
281+ ) ,
282+ keybinding : {
283+ weight : KeybindingWeight . WorkbenchContrib + 10 ,
284+ primary : KeyCode . Escape
285+ } ,
286+ menu : {
287+ id : CallHierarchyTreePeekWidget . TitleMenu ,
288+ order : 1000
289+ }
240290 } ) ;
241291 }
242292
0 commit comments