From 01d93b22ba88bc06ff9026f0d94f0047c8576d23 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 19 Sep 2014 13:54:34 -0700 Subject: [PATCH] External module items now display their base file name in quotes. --- src/compiler/core.ts | 14 ++++++++++++++ src/compiler/parser.ts | 9 +-------- src/services/getScriptLexicalStructureWalker.ts | 8 ++++++-- ...scriptLexicalStructureItemsExternalModules2.ts | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 tests/cases/fourslash/scriptLexicalStructureItemsExternalModules2.ts diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 6bfa537c9f2..e6935afd599 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -521,6 +521,20 @@ module ts { return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; } + var supportedExtensions = [".d.ts", ".ts", ".js"]; + export function removeFileExtension(path: string): string { + + for (var i = 0; i < supportedExtensions.length; i++) { + var ext = supportedExtensions[i]; + + if (fileExtensionIs(path, ext)) { + return path.substr(0, path.length - ext.length); + } + } + + return path; + } + export interface ObjectAllocator { getNodeConstructor(kind: SyntaxKind): new () => Node; getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4005a000dc8..8a977c8c764 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -17,20 +17,13 @@ module ts { return node; } - var moduleExtensions = [".d.ts", ".ts", ".js"]; - interface ReferenceComments { referencedFiles: FileReference[]; amdDependencies: string[]; } export function getModuleNameFromFilename(filename: string) { - for (var i = 0; i < moduleExtensions.length; i++) { - var ext = moduleExtensions[i]; - var len = filename.length - ext.length; - if (len > 0 && filename.substr(len) === ext) return filename.substr(0, len); - } - return filename; + return removeFileExtension(filename); } export function getSourceFileOfNode(node: Node): SourceFile { diff --git a/src/services/getScriptLexicalStructureWalker.ts b/src/services/getScriptLexicalStructureWalker.ts index 565c580c3b4..6c3de09af67 100644 --- a/src/services/getScriptLexicalStructureWalker.ts +++ b/src/services/getScriptLexicalStructureWalker.ts @@ -195,7 +195,7 @@ module ts { case SyntaxKind.VariableDeclaration: var variableDeclaration = node; return basicChildItem(node, variableDeclaration.name.text, ts.ScriptElementKind.variableElement); - + case SyntaxKind.Constructor: return basicChildItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); } @@ -286,7 +286,11 @@ module ts { } hasGlobalNode = true; - return new ts.NavigationBarItem("", + var rootName = isExternalModule(node) ? + "\"" + getBaseFilename(removeFileExtension(normalizePath(node.filename))) + "\"" : + "" + + return new ts.NavigationBarItem(rootName, ts.ScriptElementKind.moduleElement, ts.ScriptElementKindModifier.none, [getNodeSpan(node)], diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules2.ts b/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules2.ts new file mode 100644 index 00000000000..b0bf6eb3fa2 --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules2.ts @@ -0,0 +1,15 @@ +/// + +// @Filename: test/file.ts +////{| "itemName": "Bar", "kind": "class" |}export class Bar { +//// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; +////} +////{| "itemName": "\"file\"", "kind": "module" |} +////{| "itemName": "x", "kind": "var", "parentName": "\"file\"" |} +////export var x: number; + +test.markers().forEach((marker) => { + verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +}); + +verify.getScriptLexicalStructureListCount(4); // external module node + variable in module + class + property