From 2f3c32afd659b3edda1b24599f1abc1b1b125d18 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 6 Feb 2015 21:22:44 -0800 Subject: [PATCH] Navigation bar support for symbols --- src/services/navigationBar.ts | 16 +++++++++++----- .../fourslash/scriptLexicalStructureSymbols1.ts | 17 +++++++++++++++++ .../fourslash/scriptLexicalStructureSymbols2.ts | 15 +++++++++++++++ .../fourslash/scriptLexicalStructureSymbols3.ts | 13 +++++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/scriptLexicalStructureSymbols1.ts create mode 100644 tests/cases/fourslash/scriptLexicalStructureSymbols2.ts create mode 100644 tests/cases/fourslash/scriptLexicalStructureSymbols3.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 771fe48219f..b254397f8b0 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -97,8 +97,7 @@ module ts.NavigationBar { function sortNodes(nodes: Node[]): Node[] { return nodes.slice(0).sort((n1: Declaration, n2: Declaration) => { if (n1.name && n2.name) { - // TODO(jfreeman): How do we sort declarations with computed names? - return (n1.name).text.localeCompare((n2.name).text); + return getPropertyNameForPropertyNameNode(n1.name).localeCompare(getPropertyNameForPropertyNameNode(n2.name)); } else if (n1.name) { return 1; @@ -426,7 +425,7 @@ module ts.NavigationBar { // Add the constructor parameters in as children of the class (for property parameters). // Note that *all* parameters will be added to the nodes array, but parameters that // are not properties will be filtered out later by createChildItem. - var nodes: Node[] = removeComputedProperties(node); + var nodes: Node[] = removeDynamicallyNamedProperties(node); if (constructor) { nodes.push.apply(nodes, constructor.parameters); } @@ -455,7 +454,7 @@ module ts.NavigationBar { } function createIterfaceItem(node: InterfaceDeclaration): ts.NavigationBarItem { - var childItems = getItemsWorker(sortNodes(removeComputedProperties(node)), createChildItem); + var childItems = getItemsWorker(sortNodes(removeDynamicallyNamedProperties(node)), createChildItem); return getNavigationBarItem( node.name.text, ts.ScriptElementKind.interfaceElement, @@ -466,10 +465,17 @@ module ts.NavigationBar { } } - function removeComputedProperties(node: ClassDeclaration | InterfaceDeclaration | EnumDeclaration): Declaration[] { + function removeComputedProperties(node: EnumDeclaration): Declaration[] { return filter(node.members, member => member.name === undefined || member.name.kind !== SyntaxKind.ComputedPropertyName); } + /** + * Like removeComputedProperties, but retains the properties with well known symbol names + */ + function removeDynamicallyNamedProperties(node: ClassDeclaration | InterfaceDeclaration): Declaration[]{ + return filter(node.members, member => !hasDynamicName(member)); + } + function getInnermostModule(node: ModuleDeclaration): ModuleDeclaration { while (node.body.kind === SyntaxKind.ModuleDeclaration) { node = node.body; diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols1.ts b/tests/cases/fourslash/scriptLexicalStructureSymbols1.ts new file mode 100644 index 00000000000..e3dde6738e9 --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureSymbols1.ts @@ -0,0 +1,17 @@ +/// + +////{| "itemName": "C", "kind": "class", "parentName": "" |} +////class C { +//// {| "itemName": "[Symbol.isRegExp]", "kind": "property", "parentName": "C" |} +//// [Symbol.isRegExp] = 0; +//// {| "itemName": "[Symbol.iterator]", "kind": "method", "parentName": "C" |} +//// [Symbol.iterator]() { } +//// {| "itemName": "[Symbol.isConcatSpreadable]", "kind": "getter", "parentName": "C" |} +//// get [Symbol.isConcatSpreadable]() { } +////} + +test.markers().forEach(marker => { + verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +}); + +verify.getScriptLexicalStructureListCount(test.markers().length); \ No newline at end of file diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols2.ts b/tests/cases/fourslash/scriptLexicalStructureSymbols2.ts new file mode 100644 index 00000000000..d048de895ec --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureSymbols2.ts @@ -0,0 +1,15 @@ +/// + +////{| "itemName": "I", "kind": "interface", "parentName": "" |} +////interface I { +//// {| "itemName": "[Symbol.isRegExp]", "kind": "property", "parentName": "I" |} +//// [Symbol.isRegExp]: string; +//// {| "itemName": "[Symbol.iterator]", "kind": "method", "parentName": "I" |} +//// [Symbol.iterator](): string; +////} + +test.markers().forEach(marker => { + verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +}); + +verify.getScriptLexicalStructureListCount(test.markers().length); \ No newline at end of file diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols3.ts b/tests/cases/fourslash/scriptLexicalStructureSymbols3.ts new file mode 100644 index 00000000000..19f81037559 --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureSymbols3.ts @@ -0,0 +1,13 @@ +/// + +////{| "itemName": "E", "kind": "enum", "parentName": "" |} +////enum E { +//// // No nav bar entry for this +//// [Symbol.isRegExp] = 0 +////} + +test.markers().forEach(marker => { + verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +}); + +verify.getScriptLexicalStructureListCount(test.markers().length); \ No newline at end of file