use FileMap to store script info objects to avoid issues due to mismatched casing

This commit is contained in:
Vladimir Matveev
2016-07-26 16:44:30 -07:00
parent a8925f8c9d
commit 01c1bdbd4c
2 changed files with 13 additions and 6 deletions

View File

@@ -117,7 +117,7 @@ namespace ts.server {
/**
* Container of all known scripts
*/
private readonly filenameToScriptInfo = createNormalizedPathMap<ScriptInfo>();
private readonly filenameToScriptInfo = createFileMap<ScriptInfo>();
/**
* 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) {

View File

@@ -82,6 +82,11 @@ namespace ts.server {
return <NormalizedPath>normalizePath(fileName);
}
export function normalizedPathToPath(normalizedPath: NormalizedPath, currentDirectory: string, getCanonicalFileName: (f: string) => string): Path {
const f = isRootedDiskPath(normalizedPath) ? normalizedPath : getNormalizedAbsolutePath(normalizedPath, currentDirectory);
return <Path>getCanonicalFileName(f);
}
export function asNormalizedPath(fileName: string): NormalizedPath {
return <NormalizedPath>fileName;
}