Skip to content

Commit 01c1bdb

Browse files
committed
use FileMap to store script info objects to avoid issues due to mismatched casing
1 parent a8925f8 commit 01c1bdb

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/server/editorServices.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ namespace ts.server {
117117
/**
118118
* Container of all known scripts
119119
*/
120-
private readonly filenameToScriptInfo = createNormalizedPathMap<ScriptInfo>();
120+
private readonly filenameToScriptInfo = createFileMap<ScriptInfo>();
121121
/**
122122
* maps external project file name to list of config files that were the part of this project
123123
*/
@@ -147,12 +147,15 @@ namespace ts.server {
147147

148148
private changedFiles: ScriptInfo[];
149149

150+
private toCanonicalFileName: (f: string) => string;
151+
150152
constructor(public readonly host: ServerHost,
151153
public readonly logger: Logger,
152154
public readonly cancellationToken: HostCancellationToken,
153155
private readonly useSingleInferredProject: boolean,
154156
private readonly eventHandler?: ProjectServiceEventHandler) {
155157

158+
this.toCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
156159
this.directoryWatchers = new DirectoryWatchers(this);
157160
this.throttledOperations = new ThrottledOperations(host);
158161
// ts.disableIncrementalParsing = true;
@@ -282,7 +285,7 @@ namespace ts.server {
282285
// TODO: handle isOpen = true case
283286

284287
if (!info.isOpen) {
285-
this.filenameToScriptInfo.remove(info.fileName);
288+
this.filenameToScriptInfo.remove(info.path);
286289

287290
// capture list of projects since detachAllProjects will wipe out original list
288291
const containingProjects = info.containingProjects.slice();
@@ -486,7 +489,7 @@ namespace ts.server {
486489
}
487490
if (info.containingProjects.length === 0) {
488491
// if there are not projects that include this script info - delete it
489-
this.filenameToScriptInfo.remove(info.fileName);
492+
this.filenameToScriptInfo.remove(info.path);
490493
}
491494
}
492495

@@ -851,7 +854,7 @@ namespace ts.server {
851854
if (content !== undefined) {
852855
info = new ScriptInfo(this.host, fileName, content, scriptKind, openedByClient);
853856
info.setFormatOptions(toEditorSettings(this.getFormatCodeOptions()));
854-
this.filenameToScriptInfo.set(fileName, info);
857+
this.filenameToScriptInfo.set(info.path, info);
855858
if (!info.isOpen) {
856859
info.setWatcher(this.host.watchFile(fileName, _ => this.onSourceFileChanged(fileName)));
857860
}
@@ -869,7 +872,7 @@ namespace ts.server {
869872
}
870873

871874
getScriptInfoForNormalizedPath(fileName: NormalizedPath) {
872-
return this.filenameToScriptInfo.get(fileName);
875+
return this.filenameToScriptInfo.get(normalizedPathToPath(fileName, this.host.getCurrentDirectory(), this.toCanonicalFileName));
873876
}
874877

875878
setHostConfiguration(args: protocol.ConfigureRequestArguments) {
@@ -1029,7 +1032,6 @@ namespace ts.server {
10291032
this.closeClientFile(file);
10301033
}
10311034
}
1032-
10331035
// if files were open or closed then explicitly refresh list of inferred projects
10341036
// otherwise if there were only changes in files - record changed files in `changedFiles` and defer the update
10351037
if (openFiles || closedFiles) {

src/server/utilities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ namespace ts.server {
8282
return <NormalizedPath>normalizePath(fileName);
8383
}
8484

85+
export function normalizedPathToPath(normalizedPath: NormalizedPath, currentDirectory: string, getCanonicalFileName: (f: string) => string): Path {
86+
const f = isRootedDiskPath(normalizedPath) ? normalizedPath : getNormalizedAbsolutePath(normalizedPath, currentDirectory);
87+
return <Path>getCanonicalFileName(f);
88+
}
89+
8590
export function asNormalizedPath(fileName: string): NormalizedPath {
8691
return <NormalizedPath>fileName;
8792
}

0 commit comments

Comments
 (0)