提交 5f48c695 编写于 作者: J Johannes Rieken

callh - show anchor as root node in tree, don't show badges, show current call path as meta title

上级 5f09de6e
......@@ -19,7 +19,6 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { PeekContext } from 'vs/editor/contrib/referenceSearch/peekViewWidget';
const _ctxHasCompletionItemProvider = new RawContextKey<boolean>('editorHasCallHierarchyProvider', false);
const _ctxCallHierarchyVisible = new RawContextKey<boolean>('callHierarchyVisible', false);
......@@ -102,7 +101,6 @@ class CallHierarchyController extends Disposable implements IEditorContribution
widget.showMessage(localize('no.item', "No results"));
return;
}
widget.showItem(item);
});
}
......
......@@ -7,7 +7,7 @@ import 'vs/css!./media/callHierarchy';
import { PeekViewWidget } from 'vs/editor/contrib/referenceSearch/peekViewWidget';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { CallHierarchyItem, CallHierarchyProvider, CallHierarchyDirection } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { CallHierarchyProvider, CallHierarchyDirection, CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { WorkbenchAsyncDataTree } from 'vs/platform/list/browser/listService';
import { FuzzyScore } from 'vs/base/common/filters';
import * as callHTree from 'vs/workbench/contrib/callHierarchy/browser/callHierarchyTree';
......@@ -262,6 +262,22 @@ export class CallHierarchyTreePeekWidget extends PeekViewWidget {
localDispose.push({ dispose: () => this._editor.deltaDecorations(ids, []) });
localDispose.push(value);
});
let node: callHTree.Call | CallHierarchyItem = element;
let names = [element.item.name];
while (true) {
let parent = this._tree.getParentElement(node);
if (!(parent instanceof callHTree.Call)) {
break;
}
if (this._direction === CallHierarchyDirection.CallsTo) {
names.push(parent.item.name);
} else {
names.unshift(parent.item.name);
}
node = parent;
}
this.setMetaTitle(localize('meta', " – {0}", names.join('')));
}
}, undefined, this._disposables);
......@@ -295,14 +311,14 @@ export class CallHierarchyTreePeekWidget extends PeekViewWidget {
this._tree.onDidChangeSelection(e => {
const [element] = e.elements;
// don't close on click
if (element && !(e.browserEvent instanceof MouseEvent)) {
if (element && isNonEmptyArray(element.locations) && !(e.browserEvent instanceof MouseEvent)) {
this.dispose();
this._editorService.openEditor({
resource: element.item.uri,
options: { selection: element.locations[0].range }
});
}
});
}, undefined, this._disposables);
}
showLoading(): void {
......@@ -319,30 +335,29 @@ export class CallHierarchyTreePeekWidget extends PeekViewWidget {
this._show();
}
showItem(item: CallHierarchyItem) {
this._parent.dataset['state'] = State.Data;
async showItem(item: CallHierarchyItem): Promise<void> {
this._show();
this._tree.setInput(item).then(() => {
if (!this._tree.getFirstElementChild(item)) {
//
this.showMessage(this._direction === CallHierarchyDirection.CallsFrom
? localize('empt.callsFrom', "No calls from '{0}'", item.name)
: localize('empt.callsTo', "No calls to '{0}'", item.name));
} else {
this._tree.domFocus();
this._tree.focusFirst();
this.setTitle(
item.name,
item.detail || this._labelService.getUriLabel(item.uri, { relative: true }),
);
this.setMetaTitle(this._direction === CallHierarchyDirection.CallsFrom
? localize('title.from', " – calls from '{0}'", item.name)
: localize('title.to', " – calls to '{0}'", item.name));
}
});
await this._tree.setInput(item);
const [root] = this._tree.getNode(item).children;
await this._tree.expand(root.element as callHTree.Call);
const firstChild = this._tree.getFirstElementChild(root.element);
if (!(firstChild instanceof callHTree.Call)) {
//
this.showMessage(this._direction === CallHierarchyDirection.CallsFrom
? localize('empt.callsFrom', "No calls from '{0}'", item.name)
: localize('empt.callsTo', "No calls to '{0}'", item.name));
} else {
this._parent.dataset['state'] = State.Data;
this._tree.domFocus();
this._tree.setFocus([firstChild]);
this.setTitle(
item.name,
item.detail || this._labelService.getUriLabel(item.uri, { relative: true }),
);
}
if (!this._toggleDirection) {
this._toggleDirection = new ToggleHierarchyDirectionAction(
......
......@@ -11,16 +11,10 @@ import { FuzzyScore, createMatches } from 'vs/base/common/filters';
import { IconLabel } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { symbolKindToCssClass, Location } from 'vs/editor/common/modes';
import { ILabelService } from 'vs/platform/label/common/label';
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
import { $, append } from 'vs/base/browser/dom';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { attachBadgeStyler } from 'vs/platform/theme/common/styler';
import { localize } from 'vs/nls';
import { Range } from 'vs/editor/common/core/range';
export class Call {
constructor(
readonly direction: CallHierarchyDirection,
readonly item: CallHierarchyItem,
readonly locations: Location[]
) { }
......@@ -30,22 +24,29 @@ export class SingleDirectionDataSource implements IAsyncDataSource<CallHierarchy
constructor(
public provider: CallHierarchyProvider,
public direction: () => CallHierarchyDirection
public getDirection: () => CallHierarchyDirection
) { }
hasChildren(_element: CallHierarchyItem): boolean {
hasChildren(): boolean {
return true;
}
async getChildren(element: CallHierarchyItem | Call): Promise<Call[]> {
if (element instanceof Call) {
element = element.item;
try {
const direction = this.getDirection();
const calls = await this.provider.resolveCallHierarchyItem(element.item, direction, CancellationToken.None);
if (!calls) {
return [];
}
return calls.map(([item, locations]) => new Call(item, locations));
} catch {
return [];
}
} else {
// 'root'
return [new Call(element, [{ uri: element.uri, range: Range.lift(element.range).collapseToStart() }])];
}
const direction = this.direction();
const calls = await this.provider.resolveCallHierarchyItem(element, direction, CancellationToken.None);
return calls
? calls.map(([item, locations]) => new Call(direction, item, locations))
: [];
}
}
......@@ -56,9 +57,7 @@ export class IdentityProvider implements IIdentityProvider<Call> {
}
class CallRenderingTemplate {
readonly disposable: IDisposable[];
readonly iconLabel: IconLabel;
readonly badge: CountBadge;
}
export class CallRenderer implements ITreeRenderer<Call, FuzzyScore, CallRenderingTemplate> {
......@@ -69,15 +68,11 @@ export class CallRenderer implements ITreeRenderer<Call, FuzzyScore, CallRenderi
constructor(
@ILabelService private readonly _labelService: ILabelService,
@IThemeService private readonly _themeService: IThemeService,
) { }
renderTemplate(parent: HTMLElement): CallRenderingTemplate {
const container = append(parent, $('.call'));
renderTemplate(container: HTMLElement): CallRenderingTemplate {
const iconLabel = new IconLabel(container, { supportHighlights: true });
const badge = new CountBadge(append(container, $('.count')));
const listener = attachBadgeStyler(badge, this._themeService);
return { iconLabel, badge, disposable: [iconLabel, listener] };
return { iconLabel };
}
renderElement(node: ITreeNode<Call, FuzzyScore>, _index: number, template: CallRenderingTemplate): void {
......@@ -93,15 +88,9 @@ export class CallRenderer implements ITreeRenderer<Call, FuzzyScore, CallRenderi
extraClasses: [symbolKindToCssClass(element.item.kind, true)]
}
);
template.badge.setCount(element.locations.length);
template.badge.setTitleFormat(element.direction === CallHierarchyDirection.CallsTo
? localize('count.to', "{0} calls to")
: localize('count.from', "{0} calls from"));
}
disposeTemplate(template: CallRenderingTemplate): void {
dispose(template.disposable);
template.iconLabel.dispose();
}
}
......
......@@ -37,17 +37,3 @@
.monaco-workbench .call-hierarchy .tree{
height: 100%;
}
.monaco-workbench .call-hierarchy .call {
display: flex;
}
.monaco-workbench .call-hierarchy .call .count {
margin-right: 12px;
margin-left: auto;
display: none;
}
.monaco-workbench .call-hierarchy .monaco-list-row.focused .call .count {
display: unset;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册