Skip to content

Commit

Permalink
fix(lsp): Fix display of JSDoc named examples (#23927)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
nathanwhit authored and bartlomieju committed May 21, 2024
1 parent 93d7b37 commit dd896be
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static BRACKET_ACCESSOR_RE: Lazy<Regex> =
lazy_regex!(r#"^\[['"](.+)[\['"]\]$"#);
static CAPTION_RE: Lazy<Regex> =
lazy_regex!(r"<caption>(.*?)</caption>\s*\r?\n((?:\s|\S)*)");
static CODEBLOCK_RE: Lazy<Regex> = lazy_regex!(r"^\s*[~`]{3}");
static CODEBLOCK_RE: Lazy<Regex> = lazy_regex!(r"^\s*[~`]{3}"m);
static EMAIL_MATCH_RE: Lazy<Regex> = lazy_regex!(r"(.+)\s<([-.\w]+@[-.\w]+)>");
static HTTP_RE: Lazy<Regex> = lazy_regex!(r#"(?i)^https?:"#);
static JSDOC_LINKS_RE: Lazy<Regex> = lazy_regex!(
Expand Down
52 changes: 52 additions & 0 deletions tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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```"
]
}),
);
}

0 comments on commit dd896be

Please sign in to comment.