From fdb3b6857d0f03693d53868c8a7752ce2801ea7a Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 27 Oct 2016 14:52:09 -0700 Subject: [PATCH] enable non-ts extensions in inferred projects by default --- src/harness/unittests/session.ts | 3 +- .../unittests/tsserverProjectSystem.ts | 34 +++++++++++++++++++ src/server/editorServices.ts | 3 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index dd9efe51a4a..05f62c4b9f6 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -150,7 +150,8 @@ namespace ts.server { target: ScriptTarget.ES5, jsx: JsxEmit.React, newLine: NewLineKind.LineFeed, - moduleResolution: ModuleResolutionKind.NodeJs + moduleResolution: ModuleResolutionKind.NodeJs, + allowNonTsExtensions: true // injected by tsserver }); }); }); diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 5ac18921578..870926a8c55 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2471,4 +2471,38 @@ namespace ts.projectSystem { }); }); + + describe("Inferred projects", () => { + it("should support files without extensions", () => { + const f = { + path: "/a/compile", + content: "let x = 1" + }; + const host = createServerHost([f]); + const session = createSession(host); + session.executeCommand({ + seq: 1, + type: "request", + command: "compilerOptionsForInferredProjects", + arguments: { + options: { + allowJs: true + } + } + }); + session.executeCommand({ + seq: 2, + type: "request", + command: "open", + arguments: { + file: f.path, + fileContent: f.content, + scriptKindName: "JS" + } + }); + const projectService = session.getProjectService(); + checkNumberOfProjects(projectService, { inferredProjects: 1 }); + checkProjectActualFiles(projectService.inferredProjects[0], [f.path]); + }); + }); } \ No newline at end of file diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index f80305efafa..a02becd87c4 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -298,6 +298,9 @@ namespace ts.server { setCompilerOptionsForInferredProjects(projectCompilerOptions: protocol.ExternalProjectCompilerOptions): void { this.compilerOptionsForInferredProjects = convertCompilerOptions(projectCompilerOptions); + // always set 'allowNonTsExtensions' for inferred projects since user cannot configure it from the outside + // previously we did not expose a way for user to change these settings and this option was enabled by default + this.compilerOptionsForInferredProjects.allowNonTsExtensions = true; this.compileOnSaveForInferredProjects = projectCompilerOptions.compileOnSave; for (const proj of this.inferredProjects) { proj.setCompilerOptions(this.compilerOptionsForInferredProjects);