From 4b07377efb0ea4924f8303022a1a1975414df25d Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Thu, 29 Sep 2016 16:17:44 -0700 Subject: [PATCH] Fix fragment handling --- src/services/completions.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index 35a7bce5561..9cb8abcd912 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -323,17 +323,25 @@ namespace ts.Completions { } /** - * Given a path ending at a directory, gets the completions for the path. + * Given a path ending at a directory, gets the completions for the path, and filters for those entries containing the basename. */ function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { - fragment = getDirectoryPath(fragment); // TODO: modify fragment so it respects our internal path representation? - if (!fragment) { - fragment = "./"; - } - else { - fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary? + if(fragment === undefined) { fragment = "./"; } // TODO: (arozga) remove the second check along with adding --strictNullChecks + + fragment = normalizeSlashes(fragment); + + const baseName = getBaseFileName(fragment); // TODO: brittle? + + // Remove the basename from our directory path + // TODO: (arozga) when is that used for filtering options later? + fragment = getDirectoryPath(fragment); + + if (fragment === "") { + fragment = '.' + directorySeparator; // TODO: (arozga) can we remove this? } + fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary? + const absolutePath = normalizeAndPreserveTrailingSlash(isRootedDiskPath(fragment) ? fragment : combinePaths(scriptPath, fragment)); const baseDirectory = getDirectoryPath(absolutePath); const ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); @@ -374,6 +382,8 @@ namespace ts.Completions { } } + result = result.filter(entry => entry.name.indexOf(baseName) >= 0); + return result; } @@ -583,7 +593,7 @@ namespace ts.Completions { // Wrap in try catch because getEffectiveTypeRoots touches the filesystem typeRoots = getEffectiveTypeRoots(options, host); } - catch (e) {} + catch (e) { } if (typeRoots) { for (const root of typeRoots) { @@ -1700,7 +1710,7 @@ namespace ts.Completions { try { return directoryProbablyExists(path, host); } - catch (e) {} + catch (e) { } return undefined; } @@ -1708,7 +1718,7 @@ namespace ts.Completions { try { return toApply && toApply.apply(host, args); } - catch (e) {} + catch (e) { } return undefined; } }