From 59237d195f6afa0d8927128751ba5ff4562d7cce Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Fri, 28 May 2021 09:33:11 +1000 Subject: feat(cli): upgrade to TypeScript 4.3 (#9960) --- cli/lsp/tsc.rs | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'cli/lsp') diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index c345b705d..27b3bca0d 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -183,36 +183,45 @@ fn display_parts_to_string(parts: &[SymbolDisplayPart]) -> String { } fn get_tag_body_text(tag: &JsDocTagInfo) -> Option { - tag.text.as_ref().map(|text| match tag.name.as_str() { - "example" => { - let caption_regex = - Regex::new(r"(.*?)\s*\r?\n((?:\s|\S)*)").unwrap(); - if caption_regex.is_match(&text) { - caption_regex - .replace(text, |c: &Captures| { - format!("{}\n\n{}", &c[1], make_codeblock(&c[2])) - }) + tag.text.as_ref().map(|display_parts| { + // TODO(@kitsonk) check logic in vscode about handling this API change in + // tsserver + let text = display_parts_to_string(display_parts); + match tag.name.as_str() { + "example" => { + let caption_regex = + Regex::new(r"(.*?)\s*\r?\n((?:\s|\S)*)").unwrap(); + if caption_regex.is_match(&text) { + caption_regex + .replace(&text, |c: &Captures| { + format!("{}\n\n{}", &c[1], make_codeblock(&c[2])) + }) + .to_string() + } else { + make_codeblock(&text) + } + } + "author" => { + let email_match_regex = + Regex::new(r"(.+)\s<([-.\w]+@[-.\w]+)>").unwrap(); + email_match_regex + .replace(&text, |c: &Captures| format!("{} {}", &c[1], &c[2])) .to_string() - } else { - make_codeblock(text) } + "default" => make_codeblock(&text), + _ => replace_links(&text), } - "author" => { - let email_match_regex = Regex::new(r"(.+)\s<([-.\w]+@[-.\w]+)>").unwrap(); - email_match_regex - .replace(text, |c: &Captures| format!("{} {}", &c[1], &c[2])) - .to_string() - } - "default" => make_codeblock(text), - _ => replace_links(text), }) } fn get_tag_documentation(tag: &JsDocTagInfo) -> String { match tag.name.as_str() { "augments" | "extends" | "param" | "template" => { - if let Some(text) = &tag.text { + if let Some(display_parts) = &tag.text { let part_regex = Regex::new(r"^(\S+)\s*-?\s*").unwrap(); + // TODO(@kitsonk) check logic in vscode about handling this API change + // in tsserver + let text = display_parts_to_string(display_parts); let body: Vec<&str> = part_regex.split(&text).collect(); if body.len() == 3 { let param = body[1]; @@ -474,7 +483,7 @@ pub struct SymbolDisplayPart { #[serde(rename_all = "camelCase")] pub struct JsDocTagInfo { name: String, - text: Option, + text: Option>, } #[derive(Debug, Deserialize)] @@ -2703,7 +2712,7 @@ mod tests { "character": 7 }, "fileName": "file:///a.ts", - "messageText": "Cannot find name 'console'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'.", + "messageText": "Cannot find name 'console'. Do you need to change your target library? Try changing the \'lib\' compiler option to include 'dom'.", "sourceLine": "console.log(\"hello deno\");", "category": 1, "code": 2584 -- cgit v1.2.3