Handle project / program roots in tsserver correctly (#58562)

This commit is contained in:
Sheetal Nandi
2024-05-20 11:45:31 -07:00
committed by GitHub
parent d84431e706
commit ba78807aa1
10 changed files with 703 additions and 40 deletions

View File

@@ -217,10 +217,7 @@ describe("unittests:: tsserver:: dynamicFiles:: ", () => {
}], session);
}
catch (e) {
assert.strictEqual(
e.message.replace(/\r?\n/, "\n"),
`Debug Failure. False expression.\nVerbose Debug Information: {"fileName":"^walkThroughSnippet:/Users/UserName/projects/someProject/out/someFile#1.js","currentDirectory":"/user/username/projects/myproject","hostCurrentDirectory":"/","openKeys":[]}\nDynamic files must always be opened with service's current directory or service should support inferred project per projectRootPath.`,
);
session.logger.info(e.message);
}
const file2Path = file.path.replace("#1", "#2");
openFilesForSession([{ file: file2Path, content: file.content }], session);

View File

@@ -1,6 +1,7 @@
import * as ts from "../../_namespaces/ts.js";
import { dedent } from "../../_namespaces/Utils.js";
import { jsonToReadableText } from "../helpers.js";
import { libContent } from "../helpers/contents.js";
import { solutionBuildWithBaseline } from "../helpers/solutionBuilder.js";
import {
baselineTsserverLogs,
@@ -1930,4 +1931,56 @@ const b: B = new B();`,
});
}
});
it("with dts file next to ts file", () => {
const indexDts: File = {
path: "/home/src/projects/project/src/index.d.ts",
content: dedent`
declare global {
interface Window {
electron: ElectronAPI
api: unknown
}
}
`,
};
const host = createServerHost({
[indexDts.path]: indexDts.content,
"/home/src/projects/project/src/index.ts": dedent`
const api = {}
`,
"/home/src/projects/project/tsconfig.json": jsonToReadableText({
include: [
"src/*.d.ts",
],
references: [{ path: "./tsconfig.node.json" }],
}),
"/home/src/projects/project/tsconfig.node.json": jsonToReadableText({
include: ["src/**/*"],
compilerOptions: {
composite: true,
},
}),
[libFile.path]: libContent,
});
const session = new TestSession(host);
openFilesForSession([{ file: indexDts, projectRootPath: "/home/src/projects/project" }], session);
session.executeCommandSeq<ts.server.protocol.DocumentHighlightsRequest>({
command: ts.server.protocol.CommandTypes.DocumentHighlights,
arguments: {
...protocolFileLocationFromSubstring(indexDts, "global"),
filesToSearch: ["/home/src/projects/project/src/index.d.ts"],
},
});
session.executeCommandSeq<ts.server.protocol.EncodedSemanticClassificationsRequest>({
command: ts.server.protocol.CommandTypes.EncodedSemanticClassificationsFull,
arguments: {
file: indexDts.path,
start: 0,
length: indexDts.content.length,
format: "2020",
},
});
baselineTsserverLogs("projectReferences", "with dts file next to ts file", session);
});
});

View File

@@ -1416,7 +1416,7 @@ describe("unittests:: tsserver:: projects::", () => {
});
}
catch (e) {
assert.isTrue(e.message.indexOf("Debug Failure. False expression: Found script Info still attached to project") === 0);
session.logger.log(e.message);
}
baselineTsserverLogs("projects", "assert when removing project", session);
});