Skip to content

Commit

Permalink
calls - remember selected direction
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Sep 12, 2019
1 parent f089ce5 commit 3e87b24
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { PeekContext } from 'vs/editor/contrib/referenceSearch/peekViewWidget';
import { CallHierarchyRoot } from 'vs/workbench/contrib/callHierarchy/browser/callHierarchyTree';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';

const _ctxHasCompletionItemProvider = new RawContextKey<boolean>('editorHasCallHierarchyProvider', false);
const _ctxCallHierarchyVisible = new RawContextKey<boolean>('callHierarchyVisible', false);
Expand All @@ -31,6 +32,8 @@ class CallHierarchyController implements IEditorContribution {
return editor.getContribution<CallHierarchyController>(CallHierarchyController.Id);
}

private static _StorageDirection = 'callHierarchy/defaultDirection';

private readonly _ctxHasProvider: IContextKey<boolean>;
private readonly _ctxIsVisible: IContextKey<boolean>;
private readonly _dispoables = new DisposableStore();
Expand All @@ -39,6 +42,7 @@ class CallHierarchyController implements IEditorContribution {
constructor(
private readonly _editor: ICodeEditor,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IStorageService private readonly _storageService: IStorageService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
) {
this._ctxIsVisible = _ctxCallHierarchyVisible.bindTo(this._contextKeyService);
Expand Down Expand Up @@ -73,21 +77,26 @@ class CallHierarchyController implements IEditorContribution {
return;
}

const direction = this._storageService.getNumber(CallHierarchyController._StorageDirection, StorageScope.GLOBAL, <number>CallHierarchyDirection.CallsFrom);

Event.any<any>(this._editor.onDidChangeModel, this._editor.onDidChangeModelLanguage)(this.endCallHierarchy, this, this._sessionDisposables);
const widget = this._instantiationService.createInstance(
CallHierarchyTreePeekWidget,
this._editor,
position,
provider,
CallHierarchyDirection.CallsFrom
direction
);

widget.showLoading();
this._ctxIsVisible.set(true);

const cancel = new CancellationTokenSource();

this._sessionDisposables.add(widget.onDidClose(() => this.endCallHierarchy()));
this._sessionDisposables.add(widget.onDidClose(() => {
this.endCallHierarchy();
this._storageService.store(CallHierarchyController._StorageDirection, widget.direction, StorageScope.GLOBAL);
}));
this._sessionDisposables.add({ dispose() { cancel.cancel(); } });
this._sessionDisposables.add(widget);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export class CallHierarchyTreePeekWidget extends PeekViewWidget {
super.dispose();
}

get direction(): CallHierarchyDirection {
return this._direction;
}

private _applyTheme(theme: ITheme) {
const borderColor = theme.getColor(referencesWidget.peekViewBorder) || Color.transparent;
this.style({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { URI } from 'vs/base/common/uri';
import { IPosition } from 'vs/editor/common/core/position';

export const enum CallHierarchyDirection {
CallsTo, CallsFrom
CallsTo = 1,
CallsFrom = 2
}

export interface CallHierarchyItem {
Expand Down

0 comments on commit 3e87b24

Please sign in to comment.