Skip to content

🤖 Pick PR #45394 (Use getFileAndProject in session pr...) into release-4.4 #45396

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
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
4 changes: 2 additions & 2 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1453,9 +1453,9 @@ namespace ts.server {
}

private provideInlayHints(args: protocol.InlayHintsRequestArgs) {
const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args);
const { file, project } = this.getFileAndProject(args);
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
const hints = languageService.provideInlayHints(file, args, this.getPreferences(file));
const hints = project.getLanguageService().provideInlayHints(file, args, this.getPreferences(file));

return hints.map(hint => ({
...hint,
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"unittests/tsserver/getExportReferences.ts",
"unittests/tsserver/getFileReferences.ts",
"unittests/tsserver/importHelpers.ts",
"unittests/tsserver/inlayHints.ts",
"unittests/tsserver/inferredProjects.ts",
"unittests/tsserver/jsdocTag.ts",
"unittests/tsserver/languageService.ts",
Expand Down
63 changes: 63 additions & 0 deletions src/testRunner/unittests/tsserver/inlayHints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace ts.projectSystem {
describe("unittests:: tsserver:: inlayHints", () => {
const configFile: File = {
path: "/a/b/tsconfig.json",
content: "{}"
};
const app: File = {
path: "/a/b/app.ts",
content: "declare function foo(param: any): void;\nfoo(12);"
};

it("with updateOpen request does not corrupt documents", () => {
const host = createServerHost([app, commonFile1, commonFile2, libFile, configFile]);
const session = createSession(host);
session.executeCommandSeq<protocol.OpenRequest>({
command: protocol.CommandTypes.Open,
arguments: { file: app.path }
});
session.executeCommandSeq<protocol.ConfigureRequest>({
command: protocol.CommandTypes.Configure,
arguments: {
preferences: {
includeInlayParameterNameHints: "all"
} as UserPreferences
}
});
verifyInlayHintResponse(session);
session.executeCommandSeq<protocol.UpdateOpenRequest>({
command: protocol.CommandTypes.UpdateOpen,
arguments: {
changedFiles: [{ fileName: app.path, textChanges: [{ start: { line: 1, offset: 39 }, end: { line: 1, offset: 39 }, newText: "//" }] }]
}
});
verifyInlayHintResponse(session);
session.executeCommandSeq<protocol.UpdateOpenRequest>({
command: protocol.CommandTypes.UpdateOpen,
arguments: {
changedFiles: [{ fileName: app.path, textChanges: [{ start: { line: 1, offset: 41 }, end: { line: 1, offset: 41 }, newText: "c" }] }]
}
});
verifyInlayHintResponse(session);

function verifyInlayHintResponse(session: TestSession) {
verifyParamInlayHint(session.executeCommandSeq<protocol.InlayHintsRequest>({
command: protocol.CommandTypes.ProvideInlayHints,
arguments: {
file: app.path,
start: 0,
length: app.content.length,
}
}).response as protocol.InlayHintItem[] | undefined);
}

function verifyParamInlayHint(response: protocol.InlayHintItem[] | undefined) {
Debug.assert(response);
Debug.assert(response[0]);
Debug.assertEqual(response[0].text, "param:");
Debug.assertEqual(response[0].position.line, 2);
Debug.assertEqual(response[0].position.offset, 5);
}
});
});
}