From 1f7b6e6a31afaaa00a57cf875b7a3a41af267250 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 27 Sep 2016 10:54:03 -0700 Subject: [PATCH] More comments --- src/compiler/core.ts | 11 +++++++++-- src/services/completions.ts | 14 +++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index aca9701eee7..0b6dd3c9d7c 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1015,7 +1015,9 @@ namespace ts { return path.replace(/\\/g, "/"); } - // Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files") + /** + * Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files") + */ export function getRootLength(path: string): number { if (path.charCodeAt(0) === CharacterCodes.slash) { if (path.charCodeAt(1) !== CharacterCodes.slash) return 1; @@ -1074,7 +1076,7 @@ namespace ts { export function normalizePath(path: string): string { path = normalizeSlashes(path); - const rootLength = getRootLength(path); + const rootLength = getRootLength(path); // TODO: this expects un-slash-normalized strings. eg: 'x:\\...' const root = path.substr(0, rootLength); const normalized = getNormalizedParts(path, rootLength); if (normalized.length) { @@ -1091,6 +1093,11 @@ namespace ts { return path.charCodeAt(path.length - 1) === directorySeparatorCharCode; } + /** + * Returns the path except for its basename. Eg: + * + * /path/to/file.ext -> /path/to + */ export function getDirectoryPath(path: Path): Path; export function getDirectoryPath(path: string): string; export function getDirectoryPath(path: string): any { diff --git a/src/services/completions.ts b/src/services/completions.ts index 00a5f80379b..04b68544376 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -322,10 +322,22 @@ namespace ts.Completions { return result; } + /** + * Given a path ending at a directory, gets the completions for the path. + */ function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { + /*Debug.assert(fragment !== undefined); + + if (fragment === "") { + fragment = "."; + } else { + fragment = getDirectoryPath(fragment); + } + */ + fragment = getDirectoryPath(fragment); // TODO: modify fragment so it respects our internal path representation? if (!fragment) { - fragment = "." + directorySeparator; + fragment = "."; } else { fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary?