diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index bf76a453784..6b1e0740ef6 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1315,7 +1315,7 @@ namespace ts { projectService.openClientFile(file1.path, `var x = 1;`); project.updateGraph(); - const quickInfo = project.languageService.getQuickInfoAtPosition(file1.path, 4); + const quickInfo = project.getLanguageService().getQuickInfoAtPosition(file1.path, 4); assert.equal(quickInfo.kind, ScriptElementKind.variableElement); projectService.closeClientFile(file1.path); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 7a60183e7a8..527c16b11b3 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -135,7 +135,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 */ @@ -165,12 +165,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; @@ -300,7 +303,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(); @@ -504,7 +507,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); } } @@ -878,9 +881,9 @@ namespace ts.server { if (content !== undefined) { info = new ScriptInfo(this.host, fileName, content, scriptKind, openedByClient, hasMixedContent); info.setFormatOptions(toEditorSettings(this.getFormatCodeOptions())); - this.filenameToScriptInfo.set(fileName, info); + // do not watch files with mixed content - server doesn't know how to interpret it + this.filenameToScriptInfo.set(info.path, info); if (!info.isOpen && !hasMixedContent) { - // do not watch files with mixed content - server doesn't know how to interpret it info.setWatcher(this.host.watchFile(fileName, _ => this.onSourceFileChanged(fileName))); } } @@ -897,7 +900,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) { @@ -1057,7 +1060,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; }