From 01c1bdbd4c920061b60760e2e927e541be2bb198 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 26 Jul 2016 16:44:30 -0700 Subject: [PATCH] use FileMap to store script info objects to avoid issues due to mismatched casing --- src/server/editorServices.ts | 14 ++++++++------ src/server/utilities.ts | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 8139decfd05..a11ad2bccd4 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -117,7 +117,7 @@ namespace ts.server { /** * Container of all known scripts */ - private readonly filenameToScriptInfo = createNormalizedPathMap(); + private readonly filenameToScriptInfo = createFileMap(); /** * maps external project file name to list of config files that were the part of this project */ @@ -147,12 +147,15 @@ namespace ts.server { private changedFiles: ScriptInfo[]; + private toCanonicalFileName: (f: string) => string; + constructor(public readonly host: ServerHost, public readonly logger: Logger, public readonly cancellationToken: HostCancellationToken, private readonly useSingleInferredProject: boolean, private readonly eventHandler?: ProjectServiceEventHandler) { + this.toCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames); this.directoryWatchers = new DirectoryWatchers(this); this.throttledOperations = new ThrottledOperations(host); // ts.disableIncrementalParsing = true; @@ -282,7 +285,7 @@ namespace ts.server { // TODO: handle isOpen = true case if (!info.isOpen) { - this.filenameToScriptInfo.remove(info.fileName); + this.filenameToScriptInfo.remove(info.path); // capture list of projects since detachAllProjects will wipe out original list const containingProjects = info.containingProjects.slice(); @@ -486,7 +489,7 @@ namespace ts.server { } if (info.containingProjects.length === 0) { // if there are not projects that include this script info - delete it - this.filenameToScriptInfo.remove(info.fileName); + this.filenameToScriptInfo.remove(info.path); } } @@ -851,7 +854,7 @@ namespace ts.server { if (content !== undefined) { info = new ScriptInfo(this.host, fileName, content, scriptKind, openedByClient); info.setFormatOptions(toEditorSettings(this.getFormatCodeOptions())); - this.filenameToScriptInfo.set(fileName, info); + this.filenameToScriptInfo.set(info.path, info); if (!info.isOpen) { info.setWatcher(this.host.watchFile(fileName, _ => this.onSourceFileChanged(fileName))); } @@ -869,7 +872,7 @@ namespace ts.server { } getScriptInfoForNormalizedPath(fileName: NormalizedPath) { - return this.filenameToScriptInfo.get(fileName); + return this.filenameToScriptInfo.get(normalizedPathToPath(fileName, this.host.getCurrentDirectory(), this.toCanonicalFileName)); } setHostConfiguration(args: protocol.ConfigureRequestArguments) { @@ -1029,7 +1032,6 @@ namespace ts.server { this.closeClientFile(file); } } - // if files were open or closed then explicitly refresh list of inferred projects // otherwise if there were only changes in files - record changed files in `changedFiles` and defer the update if (openFiles || closedFiles) { diff --git a/src/server/utilities.ts b/src/server/utilities.ts index ccbf380cfcb..e3e6470ebf2 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -82,6 +82,11 @@ namespace ts.server { return normalizePath(fileName); } + export function normalizedPathToPath(normalizedPath: NormalizedPath, currentDirectory: string, getCanonicalFileName: (f: string) => string): Path { + const f = isRootedDiskPath(normalizedPath) ? normalizedPath : getNormalizedAbsolutePath(normalizedPath, currentDirectory); + return getCanonicalFileName(f); + } + export function asNormalizedPath(fileName: string): NormalizedPath { return fileName; }