Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lsp): process Fenced Code Block in JSDoc on completion correctly #23822

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3283,14 +3283,17 @@ impl CompletionEntryDetails {
None
};
let documentation = if let Some(parts) = &self.documentation {
// NOTE: similar as `QuickInfo::to_hover()`
let mut value = display_parts_to_string(parts, language_server);
if let Some(tags) = &self.tags {
let tag_documentation = tags
let tags_preview = tags
.iter()
.map(|tag_info| get_tag_documentation(tag_info, language_server))
.collect::<Vec<String>>()
.join("");
value = format!("{value}\n\n{tag_documentation}");
.join(" \n\n");
if !tags_preview.is_empty() {
value = format!("{value}\n\n{tags_preview}");
}
}
Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
kind: lsp::MarkupKind::Markdown,
Expand Down
26 changes: 13 additions & 13 deletions tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6967,7 +6967,7 @@ fn lsp_completions_auto_import() {
"uri": "file:///a/🦕.ts",
"languageId": "typescript",
"version": 1,
"text": "export const foo = \"foo\";\n",
"text": "/**\n *\n * @example\n * ```ts\n * const result = add(1, 2);\n * console.log(result); // 3\n * ```\n *\n * @param {number} a - The first number\n * @param {number} b - The second number\n */\nexport function add(a: number, b: number) {\n return a + b;\n}",
}
}));
client.did_open(json!({
Expand All @@ -6984,20 +6984,20 @@ fn lsp_completions_auto_import() {
json!({ "triggerKind": 1 }),
);
assert!(!list.is_incomplete);
let item = list.items.iter().find(|item| item.label == "foo");
let item = list.items.iter().find(|item| item.label == "add");
let Some(item) = item else {
panic!("completions items missing 'foo' symbol");
panic!("completions items missing 'add' symbol");
};
let mut item_value = serde_json::to_value(item).unwrap();
item_value["data"]["tsc"]["data"]["exportMapKey"] =
serde_json::Value::String("".to_string());

let req = json!({
"label": "foo",
"label": "add",
"labelDetails": {
"description": "./🦕.ts",
},
"kind": 6,
"kind": 3,
"sortText": "￿16_0",
"commitCharacters": [
".",
Expand All @@ -7009,14 +7009,14 @@ fn lsp_completions_auto_import() {
"tsc": {
"specifier": "file:///a/file.ts",
"position": 12,
"name": "foo",
"name": "add",
"source": "./%F0%9F%A6%95.ts",
"specifierRewrite": [
"./%F0%9F%A6%95.ts",
"./🦕.ts",
],
"data": {
"exportName": "foo",
"exportName": "add",
"exportMapKey": "",
"moduleSpecifier": "./%F0%9F%A6%95.ts",
"fileName": "file:///a/%F0%9F%A6%95.ts"
Expand All @@ -7031,15 +7031,15 @@ fn lsp_completions_auto_import() {
assert_eq!(
res,
json!({
"label": "foo",
"label": "add",
"labelDetails": {
"description": "./🦕.ts",
},
"kind": 6,
"detail": "const foo: \"foo\"",
"kind": 3,
"detail": "function add(a: number, b: number): number",
"documentation": {
"kind": "markdown",
"value": ""
"value": "\n\n*@example* \n```ts\nconst result = add(1, 2);\nconsole.log(result); // 3\n``` \n\n*@param* - a - The first number \n\n*@param* - b - The second number"
},
"sortText": "￿16_0",
"additionalTextEdits": [
Expand All @@ -7048,7 +7048,7 @@ fn lsp_completions_auto_import() {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 0 }
},
"newText": "import { foo } from \"./🦕.ts\";\n\n"
"newText": "import { add } from \"./🦕.ts\";\n\n"
}
]
})
Expand Down Expand Up @@ -10161,7 +10161,7 @@ fn lsp_completions_complete_function_calls() {
"detail": "(method) Array<never>.map<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any): U[]",
"documentation": {
"kind": "markdown",
"value": "Calls a defined callback function on each element of an array, and returns an array that contains the results.\n\n*@param* - callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.*@param* - thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value."
"value": "Calls a defined callback function on each element of an array, and returns an array that contains the results.\n\n*@param* - callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. \n\n*@param* - thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value."
},
"sortText": "1",
"insertText": "map(${1:callbackfn})",
Expand Down