diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 362b477c80f..46f84a39af3 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2183,7 +2183,7 @@ namespace ts { for (let i = 0; i < errors.length; i++) { const actualMessage = flattenDiagnosticMessageText(errors[i].messageText, "\n"); const expectedMessage = expectedErrors[i]; - assert.equal(actualMessage, expectedMessage, "error message does not match"); + assert.isTrue(actualMessage.indexOf(expectedMessage) === 0, `error message does not match, expected ${actualMessage} to start with ${expectedMessage}`); } } } @@ -2297,7 +2297,7 @@ namespace ts { "')' expected.", "Declaration or statement expected.", "Declaration or statement expected.", - "Failed to parse file '/a/b/tsconfig.json': Unexpected token ) in JSON at position 7." + "Failed to parse file '/a/b/tsconfig.json'" ]); } // fix config and trigger watcher @@ -2349,7 +2349,7 @@ namespace ts { "')' expected.", "Declaration or statement expected.", "Declaration or statement expected.", - "Failed to parse file '/a/b/tsconfig.json': Unexpected token ) in JSON at position 7." + "Failed to parse file '/a/b/tsconfig.json'" ]); } }); @@ -2375,4 +2375,27 @@ namespace ts { checkProjectRootFiles(project, [file1.path]); }); }); + + describe("autoDiscovery", () => { + it("does not depend on extension", () => { + const file1 = { + path: "/a/b/app.html", + content: "" + }; + const file2 = { + path: "/a/b/app.d.ts", + content: "" + }; + const host = createServerHost([file1, file2]); + const projectService = createProjectService(host); + projectService.openExternalProject({ + projectFileName: "/a/b/proj.csproj", + rootFiles: [toExternalFile(file2.path), { fileName: file1.path, hasMixedContent: true, scriptKind: ScriptKind.JS }], + options: {} + }); + projectService.checkNumberOfProjects({ externalProjects: 1 }); + const typingOptions = projectService.externalProjects[0].getTypingOptions(); + assert.isTrue(typingOptions.enableAutoDiscovery, "Typing autodiscovery should be enabled"); + }); + }); } \ No newline at end of file diff --git a/src/server/project.ts b/src/server/project.ts index 4adbc7ca059..6700b906179 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -20,10 +20,10 @@ namespace ts.server { } } - const jsOrDts = [".js", ".d.ts"]; - export function allRootFilesAreJsOrDts(project: Project): boolean { - return project.getRootScriptInfos().every(f => fileExtensionIsAny(f.fileName, jsOrDts)); + return project.getRootScriptInfos().every(f => { + return f.scriptKind === ScriptKind.JS || f.scriptKind == ScriptKind.JSX || fileExtensionIs(f.fileName, ".d.ts"); + }); } export interface ProjectFilesWithTSDiagnostics extends protocol.ProjectFiles {