summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/lsp/tsc.rs9
-rw-r--r--tests/integration/lsp_tests.rs26
2 files changed, 19 insertions, 16 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 97fdb9cb6..5d5f5228c 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -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,
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index 042513456..9bccedd66 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -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!({
@@ -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": [
".",
@@ -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"
@@ -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": [
@@ -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"
}
]
})
@@ -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})",