Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | 510x 510x 510x 1x 4x 4x 6x 5x 1x 1x 2x 1x 136x 77x 12x 77x | import * as vscode from 'vscode';
/**
* Base class for a node in the definition tree.
*/
export interface TreeNode {
/**
* The unique identifier of the tree item.
* @remark It must be unique across all tree items and thus using the resource IRI
* is not suitable. In moste cases we encode the path of the tree item from the
* root node using this notation: `<parent-iri>/<child-iri>`.
*/
id: string;
/**
* The URI of the tree item or undefined if the tree item is not associated with a URI.
*/
uri: string;
/**
* The default collapsible state of the tree item.
*/
initialCollapsibleState: vscode.TreeItemCollapsibleState;
/**
* Get the collapsible state of the tree item.
* @returns The collapsible state of the tree item.
*/
getCollapsibleState(): vscode.TreeItemCollapsibleState;
/**
* Get the command that is executed when the tree item is clicked.
* @returns A command that is executed when the tree item is clicked.
*/
getCommand(): vscode.Command | undefined;
/**
* Indicates whether the tree item has children.
* @returns `true` if the tree item has children, `false` otherwise.
*/
hasChildren(): boolean;
/**
* Get the children of the tree item.
*/
getChildren(): TreeNode[];
/**
* Get a value that can be accessed in `package.json` for the context menu.
* @returns A string that represents the context value of the tree item.
*/
getContextValue(): string;
/**
* Get the label of the tree item.
* @returns The label of the tree item.
*/
getLabel(): vscode.TreeItemLabel;
/**
* Get the description of the tree item.
* @returns A description string or `undefined` if no description should be shown.
*/
getDescription(): string;
/**
* Get the tooltip of the tree item.
* @returns A markdown string or `undefined` if no tooltip should be shown.
*/
getTooltip(): vscode.MarkdownString | undefined;
/**
* Get the icon of the tree item.
* @returns A theme icon, a file system path or undefined if no icon should be shown.
*/
getIcon(): vscode.ThemeIcon | undefined;
/**
* Get the theme color for the icon of the tree item.
* @returns A theme color or undefined for the default icon color.
*/
getIconColor(): vscode.ThemeColor | undefined;
}
/**
* Abstract base class for a node in tree views.
*/
export abstract class TreeNodeBase implements TreeNode {
id: string = '';
uri: string = '';
initialCollapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
getCommand(): vscode.Command | undefined {
return undefined;
}
getCollapsibleState(): vscode.TreeItemCollapsibleState {
const collapsibleState = this.hasChildren() ?
this.initialCollapsibleState :
vscode.TreeItemCollapsibleState.None;
return collapsibleState;
}
abstract getContextValue(): string;
hasChildren(): boolean {
return this.getChildren().length > 0;
}
getChildren(): TreeNode[] {
return [];
}
getDescription(): string {
return '';
}
abstract getLabel(): vscode.TreeItemLabel;
getTooltip(): vscode.MarkdownString | undefined {
return undefined;
}
getIcon(): vscode.ThemeIcon | undefined {
return undefined;
}
getIconColor(): vscode.ThemeColor | undefined {
return new vscode.ThemeColor('descriptionForeground');
}
}
/**
* Sort nodes by their labels according to the current label display settings.
* @param nodes A list of definition tree nodes.
* @returns The nodes sorted by their labels.
*/
export function sortByLabel(nodes: TreeNode[]): TreeNode[] {
return nodes
.map(n => ({ node: n, label: n.getLabel().label }))
.sort((a, b) => a.label.localeCompare(b.label))
.map(x => x.node);
} |