Skip to content

Commit ce02f83

Browse files
committed
use ScriptKind instead of file extension
1 parent 7e97974 commit ce02f83

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ namespace ts {
21832183
for (let i = 0; i < errors.length; i++) {
21842184
const actualMessage = flattenDiagnosticMessageText(errors[i].messageText, "\n");
21852185
const expectedMessage = expectedErrors[i];
2186-
assert.equal(actualMessage, expectedMessage, "error message does not match");
2186+
assert.isTrue(actualMessage.indexOf(expectedMessage) === 0, `error message does not match, expected ${actualMessage} to start with ${expectedMessage}`);
21872187
}
21882188
}
21892189
}
@@ -2297,7 +2297,7 @@ namespace ts {
22972297
"')' expected.",
22982298
"Declaration or statement expected.",
22992299
"Declaration or statement expected.",
2300-
"Failed to parse file '/a/b/tsconfig.json': Unexpected token ) in JSON at position 7."
2300+
"Failed to parse file '/a/b/tsconfig.json'"
23012301
]);
23022302
}
23032303
// fix config and trigger watcher
@@ -2349,7 +2349,7 @@ namespace ts {
23492349
"')' expected.",
23502350
"Declaration or statement expected.",
23512351
"Declaration or statement expected.",
2352-
"Failed to parse file '/a/b/tsconfig.json': Unexpected token ) in JSON at position 7."
2352+
"Failed to parse file '/a/b/tsconfig.json'"
23532353
]);
23542354
}
23552355
});
@@ -2375,4 +2375,27 @@ namespace ts {
23752375
checkProjectRootFiles(project, [file1.path]);
23762376
});
23772377
});
2378+
2379+
describe("autoDiscovery", () => {
2380+
it("does not depend on extension", () => {
2381+
const file1 = {
2382+
path: "/a/b/app.html",
2383+
content: ""
2384+
};
2385+
const file2 = {
2386+
path: "/a/b/app.d.ts",
2387+
content: ""
2388+
};
2389+
const host = createServerHost([file1, file2]);
2390+
const projectService = createProjectService(host);
2391+
projectService.openExternalProject({
2392+
projectFileName: "/a/b/proj.csproj",
2393+
rootFiles: [toExternalFile(file2.path), { fileName: file1.path, hasMixedContent: true, scriptKind: ScriptKind.JS }],
2394+
options: {}
2395+
});
2396+
projectService.checkNumberOfProjects({ externalProjects: 1 });
2397+
const typingOptions = projectService.externalProjects[0].getTypingOptions();
2398+
assert.isTrue(typingOptions.enableAutoDiscovery, "Typing autodiscovery should be enabled");
2399+
});
2400+
});
23782401
}

src/server/project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ namespace ts.server {
2020
}
2121
}
2222

23-
const jsOrDts = [".js", ".d.ts"];
24-
2523
export function allRootFilesAreJsOrDts(project: Project): boolean {
26-
return project.getRootScriptInfos().every(f => fileExtensionIsAny(f.fileName, jsOrDts));
24+
return project.getRootScriptInfos().every(f => {
25+
return f.scriptKind === ScriptKind.JS || f.scriptKind == ScriptKind.JSX || fileExtensionIs(f.fileName, ".d.ts");
26+
});
2727
}
2828

2929
export interface ProjectFilesWithTSDiagnostics extends protocol.ProjectFiles {

0 commit comments

Comments
 (0)