提交 992e25cf 编写于 作者: J Johannes Rieken

callh - add toggle direction command

上级 fcc9736b
......@@ -38,6 +38,8 @@ class CallHierarchyController implements IEditorContribution {
private readonly _dispoables = new DisposableStore();
private readonly _sessionDisposables = new DisposableStore();
private _widget?: CallHierarchyTreePeekWidget;
constructor(
private readonly _editor: ICodeEditor,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
......@@ -74,24 +76,24 @@ class CallHierarchyController implements IEditorContribution {
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(
this._widget = this._instantiationService.createInstance(
CallHierarchyTreePeekWidget,
this._editor,
position,
direction
);
widget.showLoading();
this._widget.showLoading();
this._ctxIsVisible.set(true);
const cts = new CancellationTokenSource();
this._sessionDisposables.add(widget.onDidClose(() => {
this._sessionDisposables.add(this._widget.onDidClose(() => {
this.endCallHierarchy();
this._storageService.store(CallHierarchyController._StorageDirection, widget.direction, StorageScope.GLOBAL);
this._storageService.store(CallHierarchyController._StorageDirection, this._widget!.direction, StorageScope.GLOBAL);
}));
this._sessionDisposables.add({ dispose() { cts.dispose(true); } });
this._sessionDisposables.add(widget);
this._sessionDisposables.add(this._widget);
try {
const model = await CallHierarchyModel.create(document, position, cts.token);
......@@ -99,16 +101,22 @@ class CallHierarchyController implements IEditorContribution {
return; // nothing
} else if (model) {
this._sessionDisposables.add(model);
widget.showModel(model);
this._widget.showModel(model);
} else {
widget.showMessage(localize('no.item', "No results"));
this._widget.showMessage(localize('no.item', "No results"));
}
} catch (e) {
widget.showMessage(localize('error', "Failed to show call hierarchy"));
this._widget.showMessage(localize('error', "Failed to show call hierarchy"));
console.error(e);
}
}
toggleCallHierarchyDirection(): void {
if (this._widget) {
this._widget.toggleDirection();
}
}
endCallHierarchy(): void {
this._sessionDisposables.clear();
this._ctxIsVisible.set(false);
......@@ -135,17 +143,38 @@ registerEditorAction(class extends EditorAction {
primary: KeyMod.Shift + KeyMod.Alt + KeyCode.KEY_H
},
precondition: ContextKeyExpr.and(
_ctxCallHierarchyVisible.negate(),
_ctxHasCompletionItemProvider,
PeekContext.notInPeekEditor
)
});
}
async run(_accessor: ServicesAccessor, editor: ICodeEditor, args: any): Promise<void> {
async run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
return CallHierarchyController.get(editor).startCallHierarchy();
}
});
registerEditorAction(class extends EditorAction {
constructor() {
super({
id: 'editor.toggleCallHierarchy',
label: localize('title.toggle', "Toggle Call Hierarchy"),
alias: 'Toggle Call Hierarchy',
kbOpts: {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.Shift + KeyMod.Alt + KeyCode.KEY_H
},
precondition: _ctxCallHierarchyVisible
});
}
async run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
return CallHierarchyController.get(editor).toggleCallHierarchyDirection();
}
});
registerEditorCommand(new class extends EditorCommand {
......
......@@ -42,19 +42,14 @@ const enum State {
class ChangeHierarchyDirectionAction extends Action {
constructor(direction: CallHierarchyDirection, updateDirection: (direction: CallHierarchyDirection) => void) {
constructor(getDirection: () => CallHierarchyDirection, toggleDirection: () => void) {
super('', undefined, '', true, () => {
if (direction === CallHierarchyDirection.CallsTo) {
direction = CallHierarchyDirection.CallsFrom;
} else {
direction = CallHierarchyDirection.CallsTo;
}
updateDirection(direction);
toggleDirection();
update();
return Promise.resolve();
});
const update = () => {
if (direction === CallHierarchyDirection.CallsFrom) {
if (getDirection() === CallHierarchyDirection.CallsFrom) {
this.label = localize('toggle.from', "Showing Calls");
this.class = 'calls-from';
} else {
......@@ -387,19 +382,22 @@ export class CallHierarchyTreePeekWidget extends PeekViewWidget {
}
if (!this._changeDirectionAction) {
const changeDirection = async (newDirection: CallHierarchyDirection) => {
if (this._direction !== newDirection) {
this._treeViewStates.set(this._direction, this._tree.getViewState());
this._direction = newDirection;
await this.showModel(model);
}
};
this._changeDirectionAction = new ChangeHierarchyDirectionAction(this._direction, changeDirection);
this._changeDirectionAction = new ChangeHierarchyDirectionAction(() => this._direction, () => this.toggleDirection());
this._disposables.add(this._changeDirectionAction);
this._actionbarWidget!.push(this._changeDirectionAction, { icon: true, label: false });
}
}
async toggleDirection(): Promise<void> {
const model = this._tree.getInput();
if (model) {
const newDirection = this._direction === CallHierarchyDirection.CallsTo ? CallHierarchyDirection.CallsFrom : CallHierarchyDirection.CallsTo;
this._treeViewStates.set(this._direction, this._tree.getViewState());
this._direction = newDirection;
await this.showModel(model);
}
}
private _show() {
if (!this._isShowing) {
this.editor.revealLineInCenterIfOutsideViewport(this._where.lineNumber, ScrollType.Smooth);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册