Skip to content

Commit fdb3b68

Browse files
committed
enable non-ts extensions in inferred projects by default
1 parent fdcc7cc commit fdb3b68

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/harness/unittests/session.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ namespace ts.server {
150150
target: ScriptTarget.ES5,
151151
jsx: JsxEmit.React,
152152
newLine: NewLineKind.LineFeed,
153-
moduleResolution: ModuleResolutionKind.NodeJs
153+
moduleResolution: ModuleResolutionKind.NodeJs,
154+
allowNonTsExtensions: true // injected by tsserver
154155
});
155156
});
156157
});

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,4 +2471,38 @@ namespace ts.projectSystem {
24712471

24722472
});
24732473
});
2474+
2475+
describe("Inferred projects", () => {
2476+
it("should support files without extensions", () => {
2477+
const f = {
2478+
path: "/a/compile",
2479+
content: "let x = 1"
2480+
};
2481+
const host = createServerHost([f]);
2482+
const session = createSession(host);
2483+
session.executeCommand(<server.protocol.SetCompilerOptionsForInferredProjectsRequest>{
2484+
seq: 1,
2485+
type: "request",
2486+
command: "compilerOptionsForInferredProjects",
2487+
arguments: {
2488+
options: {
2489+
allowJs: true
2490+
}
2491+
}
2492+
});
2493+
session.executeCommand(<server.protocol.OpenRequest>{
2494+
seq: 2,
2495+
type: "request",
2496+
command: "open",
2497+
arguments: {
2498+
file: f.path,
2499+
fileContent: f.content,
2500+
scriptKindName: "JS"
2501+
}
2502+
});
2503+
const projectService = session.getProjectService();
2504+
checkNumberOfProjects(projectService, { inferredProjects: 1 });
2505+
checkProjectActualFiles(projectService.inferredProjects[0], [f.path]);
2506+
});
2507+
});
24742508
}

src/server/editorServices.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ namespace ts.server {
298298

299299
setCompilerOptionsForInferredProjects(projectCompilerOptions: protocol.ExternalProjectCompilerOptions): void {
300300
this.compilerOptionsForInferredProjects = convertCompilerOptions(projectCompilerOptions);
301+
// always set 'allowNonTsExtensions' for inferred projects since user cannot configure it from the outside
302+
// previously we did not expose a way for user to change these settings and this option was enabled by default
303+
this.compilerOptionsForInferredProjects.allowNonTsExtensions = true;
301304
this.compileOnSaveForInferredProjects = projectCompilerOptions.compileOnSave;
302305
for (const proj of this.inferredProjects) {
303306
proj.setCompilerOptions(this.compilerOptionsForInferredProjects);

0 commit comments

Comments
 (0)