Skip to content
Permalink
Browse files
Syntax operations also need to ensure project is present for the open…
… script infos since update could be pending to make sure open script info has project (#50418)

Also convert one relevant test case to baseline
Fixes #50131
  • Loading branch information
sheetalkamat committed Aug 24, 2022
1 parent 1d4fbbb commit b9a5bbc9afe9fa231aba5162c258bf1e2fa1e82e
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 16 deletions.
@@ -1868,9 +1868,9 @@ namespace ts.server {

private getFileAndLanguageServiceForSyntacticOperation(args: protocol.FileRequestArgs) {
// Since this is syntactic operation, there should always be project for the file
// we wouldnt have to ensure project but rather throw if we dont get project
// throw if we dont get project
const file = toNormalizedPath(args.file);
const project = this.getProject(args.projectFileName) || this.projectService.tryGetDefaultProjectForFile(file);
const project = this.getProject(args.projectFileName) || this.projectService.ensureDefaultProjectForFile(file);
if (!project) {
return Errors.ThrowNoProject();
}
@@ -1054,7 +1054,7 @@ namespace ts.projectSystem {
assert.equal(options.outDir, "C:/a/b", "");
});

it("files opened, closed affecting multiple projects", () => {
it("files opened and closed affecting multiple projects", () => {
const file: File = {
path: "/a/b/projects/config/file.ts",
content: `import {a} from "../files/file1"; export let b = a;`
@@ -1074,7 +1074,7 @@ namespace ts.projectSystem {

const files = [config, file, filesFile1, filesFile2, libFile];
const host = createServerHost(files);
const session = createSession(host);
const session = createSession(host, { logger: createLoggerWithInMemoryLogs() });
// Create configured project
session.executeCommandSeq<protocol.OpenRequest>({
command: protocol.CommandTypes.Open,
@@ -1083,18 +1083,13 @@ namespace ts.projectSystem {
}
});

const projectService = session.getProjectService();
const configuredProject = projectService.configuredProjects.get(config.path)!;
verifyConfiguredProject();

// open files/file1 = should not create another project
session.executeCommandSeq<protocol.OpenRequest>({
command: protocol.CommandTypes.Open,
arguments: {
file: filesFile1.path
}
});
verifyConfiguredProject();

// Close the file = should still have project
session.executeCommandSeq<protocol.CloseRequest>({
@@ -1103,7 +1098,6 @@ namespace ts.projectSystem {
file: file.path
}
});
verifyConfiguredProject();

// Open files/file2 - should create inferred project and close configured project
session.executeCommandSeq<protocol.OpenRequest>({
@@ -1112,8 +1106,6 @@ namespace ts.projectSystem {
file: filesFile2.path
}
});
checkNumberOfProjects(projectService, { inferredProjects: 1 });
checkProjectActualFiles(projectService.inferredProjects[0], [libFile.path, filesFile2.path]);

// Actions on file1 would result in assert
session.executeCommandSeq<protocol.OccurrencesRequest>({
@@ -1125,10 +1117,7 @@ namespace ts.projectSystem {
}
});

function verifyConfiguredProject() {
checkNumberOfProjects(projectService, { configuredProjects: 1 });
checkProjectActualFiles(configuredProject, [file.path, filesFile1.path, libFile.path, config.path]);
}
baselineTsserverLogs("projects", "files opened and closed affecting multiple projects", session);
});

it("requests are done on file on pendingReload but has svc for previous version", () => {
@@ -1620,5 +1609,40 @@ namespace ts.projectSystem {

checkNumberOfInferredProjects(projectService, 0);
});

it("file opened is in configured project that will be removed", () => {
const testsConfig: File = {
path: `${tscWatch.projectRoot}/playground/tsconfig.json`,
content: "{}"
};
const testsFile: File = {
path: `${tscWatch.projectRoot}/playground/tests.ts`,
content: `export function foo() {}`
};
const innerFile: File = {
path: `${tscWatch.projectRoot}/playground/tsconfig-json/tests/spec.ts`,
content: `export function bar() { }`
};
const innerConfig: File = {
path: `${tscWatch.projectRoot}/playground/tsconfig-json/tsconfig.json`,
content: JSON.stringify({
include: ["./src"]
})
};
const innerSrcFile: File = {
path: `${tscWatch.projectRoot}/playground/tsconfig-json/src/src.ts`,
content: `export function foobar() { }`
};
const host = createServerHost([testsConfig, testsFile, innerFile, innerConfig, innerSrcFile, libFile]);
const session = createSession(host, { logger: createLoggerWithInMemoryLogs() });
openFilesForSession([testsFile], session);
closeFilesForSession([testsFile], session);
openFilesForSession([innerFile], session);
session.executeCommandSeq<protocol.OutliningSpansRequest>({
command: protocol.CommandTypes.GetOutliningSpans,
arguments: { file: innerFile.path }
});
baselineTsserverLogs("projects", "file opened is in configured project that will be removed", session);
});
});
}

0 comments on commit b9a5bbc

Please sign in to comment.