mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 20:37:00 -05:00
Navigation bar support for symbols
This commit is contained in:
@@ -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 (<Identifier>n1.name).text.localeCompare((<Identifier>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<Declaration>(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<Declaration>(node.members, member => !hasDynamicName(member));
|
||||
}
|
||||
|
||||
function getInnermostModule(node: ModuleDeclaration): ModuleDeclaration {
|
||||
while (node.body.kind === SyntaxKind.ModuleDeclaration) {
|
||||
node = <ModuleDeclaration>node.body;
|
||||
|
||||
17
tests/cases/fourslash/scriptLexicalStructureSymbols1.ts
Normal file
17
tests/cases/fourslash/scriptLexicalStructureSymbols1.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////{| "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);
|
||||
15
tests/cases/fourslash/scriptLexicalStructureSymbols2.ts
Normal file
15
tests/cases/fourslash/scriptLexicalStructureSymbols2.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////{| "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);
|
||||
13
tests/cases/fourslash/scriptLexicalStructureSymbols3.ts
Normal file
13
tests/cases/fourslash/scriptLexicalStructureSymbols3.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////{| "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);
|
||||
Reference in New Issue
Block a user