Skip to content

Commit 5108285

Browse files
committed
Port (#12474)
1 parent c43c37f commit 5108285

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,35 @@ namespace ts.projectSystem {
578578
checkWatchedDirectories(host, ["/a/b/c", "/a/b", "/a"]);
579579
});
580580

581+
it("can handle tsconfig file name with difference casing", () => {
582+
const f1 = {
583+
path: "/a/b/app.ts",
584+
content: "let x = 1"
585+
};
586+
const config = {
587+
path: "/a/b/tsconfig.json",
588+
content: JSON.stringify({
589+
include: []
590+
})
591+
};
592+
593+
const host = createServerHost([f1, config], { useCaseSensitiveFileNames: false });
594+
const service = createProjectService(host);
595+
service.openExternalProject(<protocol.ExternalProject>{
596+
projectFileName: "/a/b/project.csproj",
597+
rootFiles: toExternalFiles([f1.path, combinePaths(getDirectoryPath(config.path).toUpperCase(), getBaseFileName(config.path))]),
598+
options: {}
599+
});
600+
service.checkNumberOfProjects({ configuredProjects: 1 });
601+
checkProjectActualFiles(service.configuredProjects[0], []);
602+
603+
service.openClientFile(f1.path);
604+
service.checkNumberOfProjects({ configuredProjects: 1, inferredProjects: 1 });
605+
606+
checkProjectActualFiles(service.configuredProjects[0], []);
607+
checkProjectActualFiles(service.inferredProjects[0], [f1.path]);
608+
})
609+
581610
it("create configured project without file list", () => {
582611
const configFile: FileOrFolder = {
583612
path: "/a/b/tsconfig.json",

src/server/editorServices.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ namespace ts.server {
257257

258258
private changedFiles: ScriptInfo[];
259259

260-
private toCanonicalFileName: (f: string) => string;
260+
readonly toCanonicalFileName: (f: string) => string;
261261

262262
public lastDeletedFile: ScriptInfo;
263263

@@ -777,7 +777,13 @@ namespace ts.server {
777777
}
778778

779779
private findConfiguredProjectByProjectName(configFileName: NormalizedPath) {
780-
return findProjectByName(configFileName, this.configuredProjects);
780+
// make sure that casing of config file name is consistent
781+
configFileName = asNormalizedPath(this.toCanonicalFileName(configFileName));
782+
for (const proj of this.configuredProjects) {
783+
if (proj.canonicalConfigFilePath === configFileName) {
784+
return proj;
785+
}
786+
}
781787
}
782788

783789
private findExternalProjectByProjectName(projectFileName: string) {

src/server/project.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ namespace ts.server {
817817
private directoryWatcher: FileWatcher;
818818
private directoriesWatchedForWildcards: Map<FileWatcher>;
819819
private typeRootsWatchers: FileWatcher[];
820+
readonly canonicalConfigFilePath: NormalizedPath;
820821

821822
/** Used for configured projects which may have multiple open roots */
822823
openRefCount = 0;
@@ -830,6 +831,7 @@ namespace ts.server {
830831
languageServiceEnabled: boolean,
831832
public compileOnSaveEnabled: boolean) {
832833
super(configFileName, ProjectKind.Configured, projectService, documentRegistry, hasExplicitListOfFiles, languageServiceEnabled, compilerOptions, compileOnSaveEnabled);
834+
this.canonicalConfigFilePath = asNormalizedPath(projectService.toCanonicalFileName(configFileName));
833835
}
834836

835837
getConfigFilePath() {

0 commit comments

Comments
 (0)