From 7da455c3903e7d63db974037a79142d54e0b49ce Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 21 Jul 2016 11:40:03 -0700 Subject: [PATCH] read ScriptKind\HasMixedContent when opening external project --- src/harness/unittests/tsserverProjectSystem.ts | 2 +- src/server/editorServices.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 70e1f34300c..b645ef29189 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -31,7 +31,7 @@ namespace ts { } function toExternalFile(fileName: string): server.protocol.ExternalFile { - return { fileName } + return { fileName }; } function toExternalFiles(fileNames: string[]) { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 5d28a352b17..442f7687617 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -746,7 +746,9 @@ namespace ts.server { if (!scriptInfo || !project.isRoot(scriptInfo)) { rootFilesChanged = true; if (!scriptInfo) { - scriptInfo = this.getOrCreateScriptInfoForNormalizedPath(normalizedPath, /*openedByClient*/ false); + const scriptKind = propertyReader.getScriptKind(f); + const hasMixedContent = propertyReader.hasMixedContent(f); + scriptInfo = this.getOrCreateScriptInfoForNormalizedPath(normalizedPath, /*openedByClient*/ false, /*fileContent*/ undefined, scriptKind, hasMixedContent); } } newRootScriptInfos.push(scriptInfo); @@ -855,12 +857,14 @@ namespace ts.server { return this.getScriptInfoForNormalizedPath(toNormalizedPath(uncheckedFileName)); } - getOrCreateScriptInfoForNormalizedPath(fileName: NormalizedPath, openedByClient: boolean, fileContent?: string, scriptKind?: ScriptKind) { + getOrCreateScriptInfoForNormalizedPath(fileName: NormalizedPath, openedByClient: boolean, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean) { let info = this.getScriptInfoForNormalizedPath(fileName); if (!info) { let content: string; if (this.host.fileExists(fileName)) { - content = fileContent || this.host.readFile(fileName); + // by default pick whatever content was supplied as the argument + // if argument was not given - then for mixed content files assume that its content is empty string + content = fileContent || (hasMixedContent ? "" : this.host.readFile(fileName)); } if (!content) { if (openedByClient) { @@ -871,7 +875,8 @@ namespace ts.server { info = new ScriptInfo(this.host, fileName, content, scriptKind, openedByClient); info.setFormatOptions(toEditorSettings(this.getFormatCodeOptions())); this.filenameToScriptInfo.set(fileName, info); - if (!info.isOpen) { + 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))); } }