Fix harness getDirectores implementation to not include directory as prefix (#21633) (#21687)

This commit is contained in:
Andy
2018-02-06 11:38:17 -08:00
committed by GitHub
parent eca6410c6e
commit 07c9505cd3
5 changed files with 11 additions and 17 deletions
+1 -4
View File
@@ -189,10 +189,7 @@ namespace Harness.LanguageService {
getCancellationToken() { return this.cancellationToken; }
getDirectories(path: string): string[] {
const dir = this.virtualFileSystem.traversePath(path);
if (dir && dir.isDirectory()) {
return ts.map((<Utils.VirtualDirectory>dir).getDirectories(), (d) => ts.combinePaths(path, d.name));
}
return [];
return dir && dir.isDirectory() ? dir.getDirectories().map(d => d.name) : [];
}
getCurrentDirectory(): string { return virtualFileSystemRoot; }
getDefaultLibFileName(): string { return Harness.Compiler.defaultLibFileName; }
+1 -1
View File
@@ -365,7 +365,7 @@ namespace ts.Completions {
// import x = require("/*completion position*/");
// var y = require("/*completion position*/");
// export * from "/*completion position*/";
return pathCompletionsInfo(PathCompletions.getStringLiteralCompletionsFromModuleNames(sourceFile, node as StringLiteral, compilerOptions, host, typeChecker));
return pathCompletionsInfo(PathCompletions.getStringLiteralCompletionsFromModuleNames(sourceFile, node, compilerOptions, host, typeChecker));
default:
return fromContextualType();
+6 -5
View File
@@ -6,7 +6,7 @@ namespace ts.Completions.PathCompletions {
const scriptPath = node.getSourceFile().path;
const scriptDirectory = getDirectoryPath(scriptPath);
const span = getDirectoryFragmentTextSpan((<StringLiteral>node).text, node.getStart(sourceFile) + 1);
const span = getDirectoryFragmentTextSpan(node.text, node.getStart(sourceFile) + 1);
if (isPathRelativeToScript(literalValue) || isRootedDiskPath(literalValue)) {
const extensions = getSupportedExtensions(compilerOptions);
if (compilerOptions.rootDirs) {
@@ -226,7 +226,8 @@ namespace ts.Completions.PathCompletions {
const includeGlob = normalizedSuffix ? "**/*" : "./*";
const matches = tryReadDirectory(host, baseDirectory, fileExtensions, /*exclude*/ undefined, [includeGlob]);
const directories = tryGetDirectories(host, baseDirectory);
const directories = tryGetDirectories(host, baseDirectory).map(d => combinePaths(baseDirectory, d));
// Trim away prefix and suffix
return mapDefined(concatenate(matches, directories), match => {
const normalizedMatch = normalizePath(match);
@@ -476,14 +477,14 @@ namespace ts.Completions.PathCompletions {
const nodeModulesDependencyKeys = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
function tryGetDirectories(host: LanguageServiceHost, directoryName: string): string[] {
return tryIOAndConsumeErrors(host, host.getDirectories, directoryName);
return tryIOAndConsumeErrors(host, host.getDirectories, directoryName) || [];
}
function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>): string[] | undefined {
function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>): string[] | undefined | undefined {
return tryIOAndConsumeErrors(host, host.readDirectory, path, extensions, exclude, include);
}
function tryReadFile(host: LanguageServiceHost, path: string): string {
function tryReadFile(host: LanguageServiceHost, path: string): string | undefined {
return tryIOAndConsumeErrors(host, host.readFile, path);
}
+2 -2
View File
@@ -200,8 +200,8 @@ namespace ts {
/* @internal */ hasChangedAutomaticTypeDirectiveNames?: boolean;
/*
* getDirectories is also required for full import and type reference completions. Without it defined, certain
* completions will not be provided
* Required for full import and type reference completions.
* These should be unprefixed names. E.g. `getDirectories("/foo/bar")` should return `["a", "b"]`, not `["/foo/bar/a", "/foo/bar/b"]`.
*/
getDirectories?(directoryName: string): string[];
@@ -20,8 +20,4 @@
////}
const [replacementSpan] = test.ranges();
verify.completionsAt("", [
{ name: "a", replacementSpan },
{ name: "b", replacementSpan },
{ name: "dir", replacementSpan },
]);
verify.completionsAt("", ["a", "b", "dir"].map(name => ({ name, replacementSpan })));