1namespace 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} 64