Skip to content

Allow dynamic files without external project and also use file names starting with ^ as dynamic file #21338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,45 @@ namespace ts.projectSystem {
const options = project.getCompilerOptions();
assert.equal(options.outDir, "C:/a/b", "");
});

it("dynamic file without external project", () => {
const file: FileOrFolder = {
path: "^walkThroughSnippet:/Users/UserName/projects/someProject/out/someFile#1.js",
content: "var x = 10;"
};
const host = createServerHost([libFile], { useCaseSensitiveFileNames: true });
const projectService = createProjectService(host);
projectService.setCompilerOptionsForInferredProjects({
module: ModuleKind.CommonJS,
allowJs: true,
allowSyntheticDefaultImports: true,
allowNonTsExtensions: true
});
projectService.openClientFile(file.path, "var x = 10;");

projectService.checkNumberOfProjects({ inferredProjects: 1 });
const project = projectService.inferredProjects[0];
checkProjectRootFiles(project, [file.path]);
checkProjectActualFiles(project, [file.path, libFile.path]);

assert.strictEqual(projectService.getDefaultProjectForFile(server.toNormalizedPath(file.path), /*ensureProject*/ true), project);
const indexOfX = file.content.indexOf("x");
assert.deepEqual(project.getLanguageService(/*ensureSynchronized*/ true).getQuickInfoAtPosition(file.path, indexOfX), {
kind: ScriptElementKind.variableElement,
kindModifiers: "",
textSpan: { start: indexOfX, length: 1 },
displayParts: [
{ text: "var", kind: "keyword" },
{ text: " ", kind: "space" },
{ text: "x", kind: "localName" },
{ text: ":", kind: "punctuation" },
{ text: " ", kind: "space" },
{ text: "number", kind: "keyword" }
],
documentation: [],
tags: []
});
});
});

describe("tsserverProjectSystem Proper errors", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ namespace ts.server {

const project = this.getOrCreateInferredProjectForProjectRootPathIfEnabled(info, projectRootPath) ||
this.getOrCreateSingleInferredProjectIfEnabled() ||
this.createInferredProject(getDirectoryPath(info.path));
this.createInferredProject(info.isDynamic ? this.currentDirectory : getDirectoryPath(info.path));

project.addRoot(info);
project.updateGraph();
Expand Down Expand Up @@ -1655,7 +1655,7 @@ namespace ts.server {
}

private getOrCreateInferredProjectForProjectRootPathIfEnabled(info: ScriptInfo, projectRootPath: NormalizedPath | undefined): InferredProject | undefined {
if (!this.useInferredProjectPerProjectRoot) {
if (info.isDynamic || !this.useInferredProjectPerProjectRoot) {
return undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/scriptInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace ts.server {

/*@internal*/
export function isDynamicFileName(fileName: NormalizedPath) {
return getBaseFileName(fileName)[0] === "^";
return fileName[0] === "^" || getBaseFileName(fileName)[0] === "^";
}

export class ScriptInfo {
Expand Down