Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function create(item: TypeHierarchyItem, direction: TypeHierarchyDirection, resolved: boolean = true): Node {
const items = TypeHierarchyDirection.Children === direction ? item.children : item.parents;
if (items && items.length > 0) {
// If the server sent more levels than requested, use them.
resolved = true;
}
const node = {
id: v4(),
name: item.name,
description: item.detail,
parent: undefined,
location: Location.create(item.uri, item.selectionRange),
resolved,
children: items ? items.map(child => create(child, direction, false)) : [],
expanded: false,
visible: true,
selected: false,
kind: item.kind,
execute: () => this.openViewOrFlipHierarchyDirection(TypeHierarchyDirection.Children),
isEnabled: this.isEnabled.bind(this)
protected getDirection(args?: Partial): TypeHierarchyDirection {
return !!args && !!args.direction ? args.direction : TypeHierarchyDirection.Children;
}
protected async ensureResolved(node: TypeHierarchyTree.Node): Promise {
if (!node.resolved) {
const { service, direction } = this;
if (service && direction !== undefined) {
const { item } = node;
const param: ResolveTypeHierarchyItemParams = {
item,
direction,
resolve: 1
};
const resolvedItem = await service.resolve(param);
if (resolvedItem) {
node.resolved = true;
const items = TypeHierarchyDirection.Children === direction ? resolvedItem.children : resolvedItem.parents;
if (items) {
node.children = items.map(child => TypeHierarchyTree.Node.create(child, direction, false));
} else {
node.children = [];
}
}
}
}
}
data: new URI(item.uri).displayName,
fontData: {
color: 'var(--theia-descriptionForeground)',
}
}];
if (item.detail) {
captionSuffixes.unshift({
data: item.detail,
fontData: {
color: 'var(--theia-list-highlightForeground)',
style: 'italic'
}
});
}
const data = `${TypeHierarchyDirection.Children === direction ? '▼' : '▲'}`;
const color = `var(${TypeHierarchyDirection.Children === direction ? '--theia-errorForeground' : '--theia-successBackground'})`;
return {
captionSuffixes,
captionPrefixes: [{
data,
fontData: {
color,
style: 'bold'
}
}]
};
}