From db82e8b557c9836481618a73cec7c014903ff256 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Tue, 21 May 2024 14:04:19 -0700 Subject: fix(lsp): Fix display of JSDoc named examples (#23927) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were wrapping the display string in an unnecessary pair of triple backticks, breaking highlighting Before: ![Screenshot 2024-05-21 at 12 16 12 PM](https://github.com/denoland/deno/assets/17734409/1cf5a3ce-56dd-443d-9d1a-bd33625ff1f2) After: ![Screenshot 2024-05-21 at 12 16 36 PM](https://github.com/denoland/deno/assets/17734409/646c4c48-9b5a-4326-bb95-b1374627d969) --- tests/integration/lsp_tests.rs | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests') diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index ed95541d2..6a92ae00b 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -12979,3 +12979,55 @@ fn lsp_semantic_token_caching() { assert_eq!(res, res_cached); } + +#[test] +fn lsp_jsdoc_named_example() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let temp_dir = context.temp_dir().path(); + let mut client = context + .new_lsp_command() + .set_root_dir(temp_dir.clone()) + .build(); + client.initialize_default(); + + let main = source_file( + temp_dir.join("main.ts"), + r#" + /** + * @example Example1 + * ```ts + * foo(); + * ``` + */ + export function foo(): number { + return 1; + } + "#, + ); + + let diagnostics = client.did_open_file(&main); + assert_eq!(diagnostics.all().len(), 0); + + let hover = client.write_request( + "textDocument/hover", + json!({ + "textDocument": main.identifier(), + "position": main.range_of_nth(1, "foo").start, + }), + ); + + assert_json_subset( + hover, + json!({ + "contents": [ + { + "language": "typescript", + "value": "function foo(): number" + }, + "", + // The example name `Example1` should not be enclosed in backticks + "\n\n*@example* \nExample1\n```ts\nfoo();\n```" + ] + }), + ); +} -- cgit v1.2.3