mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Always include a root node in the navigation bar.
This lets us change the navigation bar counting algorithm to traverse from the root only, so it never has duplicate nodes.
This commit is contained in:
parent
27a1e91268
commit
fe77f541f6
@ -1961,23 +1961,22 @@ namespace FourSlash {
|
||||
|
||||
public verifyNavigationBarCount(expected: number) {
|
||||
const items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
|
||||
const actual = this.getNavigationBarItemsCount(items);
|
||||
const actual = this.getNavigationBarItemsCount(items[0]);
|
||||
|
||||
if (expected !== actual) {
|
||||
this.raiseError(`verifyNavigationBarCount failed - found: ${actual} navigation items, expected: ${expected}.`);
|
||||
}
|
||||
}
|
||||
|
||||
private getNavigationBarItemsCount(items: ts.NavigationBarItem[]) {
|
||||
let result = 0;
|
||||
if (items) {
|
||||
for (let i = 0, n = items.length; i < n; i++) {
|
||||
result++;
|
||||
result += this.getNavigationBarItemsCount(items[i].childItems);
|
||||
}
|
||||
private getNavigationBarItemsCount(root: ts.NavigationBarItem) {
|
||||
ts.Debug.assert(root.kind === ts.ScriptElementKind.moduleElement);
|
||||
function recur(item: ts.NavigationBarItem) {
|
||||
let count = 1;
|
||||
for (const child of item.childItems)
|
||||
count += recur(child);
|
||||
return count;
|
||||
}
|
||||
|
||||
return result;
|
||||
return recur(root);
|
||||
}
|
||||
|
||||
public verifyNavigationBarContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number) {
|
||||
|
||||
@ -9,16 +9,10 @@ namespace ts.NavigationBar {
|
||||
return getJsNavigationBarItems(sourceFile, compilerOptions);
|
||||
}
|
||||
|
||||
// If the source file has any child items, then it included in the tree
|
||||
// and takes lexical ownership of all other top-level items.
|
||||
let hasGlobalNode = false;
|
||||
|
||||
return getItemsWorker(getTopLevelNodes(sourceFile), createTopLevelItem);
|
||||
|
||||
function getIndent(node: Node): number {
|
||||
// If we have a global node in the tree,
|
||||
// then it adds an extra layer of depth to all subnodes.
|
||||
let indent = hasGlobalNode ? 1 : 0;
|
||||
let indent = 1; // Global node is the only one with indent 0.
|
||||
|
||||
let current = node.parent;
|
||||
while (current) {
|
||||
@ -508,11 +502,6 @@ namespace ts.NavigationBar {
|
||||
function createSourceFileItem(node: SourceFile): ts.NavigationBarItem {
|
||||
const childItems = getItemsWorker(getChildNodes(node.statements), createChildItem);
|
||||
|
||||
if (childItems === undefined || childItems.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
hasGlobalNode = true;
|
||||
const rootName = isExternalModule(node)
|
||||
? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName)))) + "\""
|
||||
: "<global>";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user