Skip to content

Commit c8b1e45

Browse files
TypeScript Botweswigham
TypeScript Bot
andauthored
Cherry-pick PR #45394 into release-4.4 (#45396)
Component commits: 61dd78f Use getFileAndProject in session provideInlayHints to ensure language service updates are applied Co-authored-by: Wesley Wigham <t-weswig@microsoft.com>
1 parent e7fd303 commit c8b1e45

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

src/server/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,9 +1453,9 @@ namespace ts.server {
14531453
}
14541454

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

14601460
return hints.map(hint => ({
14611461
...hint,

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
"unittests/tsserver/getExportReferences.ts",
192192
"unittests/tsserver/getFileReferences.ts",
193193
"unittests/tsserver/importHelpers.ts",
194+
"unittests/tsserver/inlayHints.ts",
194195
"unittests/tsserver/inferredProjects.ts",
195196
"unittests/tsserver/jsdocTag.ts",
196197
"unittests/tsserver/languageService.ts",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
namespace ts.projectSystem {
2+
describe("unittests:: tsserver:: inlayHints", () => {
3+
const configFile: File = {
4+
path: "/a/b/tsconfig.json",
5+
content: "{}"
6+
};
7+
const app: File = {
8+
path: "/a/b/app.ts",
9+
content: "declare function foo(param: any): void;\nfoo(12);"
10+
};
11+
12+
it("with updateOpen request does not corrupt documents", () => {
13+
const host = createServerHost([app, commonFile1, commonFile2, libFile, configFile]);
14+
const session = createSession(host);
15+
session.executeCommandSeq<protocol.OpenRequest>({
16+
command: protocol.CommandTypes.Open,
17+
arguments: { file: app.path }
18+
});
19+
session.executeCommandSeq<protocol.ConfigureRequest>({
20+
command: protocol.CommandTypes.Configure,
21+
arguments: {
22+
preferences: {
23+
includeInlayParameterNameHints: "all"
24+
} as UserPreferences
25+
}
26+
});
27+
verifyInlayHintResponse(session);
28+
session.executeCommandSeq<protocol.UpdateOpenRequest>({
29+
command: protocol.CommandTypes.UpdateOpen,
30+
arguments: {
31+
changedFiles: [{ fileName: app.path, textChanges: [{ start: { line: 1, offset: 39 }, end: { line: 1, offset: 39 }, newText: "//" }] }]
32+
}
33+
});
34+
verifyInlayHintResponse(session);
35+
session.executeCommandSeq<protocol.UpdateOpenRequest>({
36+
command: protocol.CommandTypes.UpdateOpen,
37+
arguments: {
38+
changedFiles: [{ fileName: app.path, textChanges: [{ start: { line: 1, offset: 41 }, end: { line: 1, offset: 41 }, newText: "c" }] }]
39+
}
40+
});
41+
verifyInlayHintResponse(session);
42+
43+
function verifyInlayHintResponse(session: TestSession) {
44+
verifyParamInlayHint(session.executeCommandSeq<protocol.InlayHintsRequest>({
45+
command: protocol.CommandTypes.ProvideInlayHints,
46+
arguments: {
47+
file: app.path,
48+
start: 0,
49+
length: app.content.length,
50+
}
51+
}).response as protocol.InlayHintItem[] | undefined);
52+
}
53+
54+
function verifyParamInlayHint(response: protocol.InlayHintItem[] | undefined) {
55+
Debug.assert(response);
56+
Debug.assert(response[0]);
57+
Debug.assertEqual(response[0].text, "param:");
58+
Debug.assertEqual(response[0].position.line, 2);
59+
Debug.assertEqual(response[0].position.offset, 5);
60+
}
61+
});
62+
});
63+
}

0 commit comments

Comments
 (0)