Skip to content
This repository was archived by the owner on Sep 19, 2025. It is now read-only.

Commit eb6e250

Browse files
committed
Add demo of displayParts rendering and description
1 parent 9d730ee commit eb6e250

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

demo/index.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ increment('not a number');`,
6262
});
6363
})();
6464

65+
function renderDisplayParts(dp: ts.SymbolDisplayPart[]) {
66+
const div = document.createElement("div");
67+
for (const part of dp) {
68+
const span = div.appendChild(document.createElement("span"));
69+
span.className = `quick-info-${part.kind}`;
70+
span.innerText = part.text;
71+
}
72+
return div;
73+
}
74+
6575
(async () => {
6676
const path = "index.ts";
6777

@@ -90,7 +100,28 @@ increment('not a number');`,
90100
tsSyncWorker(),
91101
tsLinterWorker(),
92102
autocompletion({
93-
override: [tsAutocompleteWorker()],
103+
override: [
104+
tsAutocompleteWorker({
105+
renderAutocomplete(raw) {
106+
return () => {
107+
const div = document.createElement("div");
108+
if (raw.documentation) {
109+
const description = div.appendChild(
110+
document.createElement("div"),
111+
);
112+
description.appendChild(
113+
renderDisplayParts(raw.documentation),
114+
);
115+
}
116+
if (raw?.displayParts) {
117+
const dp = div.appendChild(document.createElement("div"));
118+
dp.appendChild(renderDisplayParts(raw.displayParts));
119+
}
120+
return { dom: div };
121+
};
122+
},
123+
}),
124+
],
94125
}),
95126
tsHoverWorker(),
96127
],

src/autocomplete/tsAutocompleteWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { AutocompleteOptions } from "./types.js";
1212
* the TypeScript environment in a web worker.
1313
*/
1414
export function tsAutocompleteWorker(
15-
opts: AutocompleteOptions,
15+
opts: AutocompleteOptions = {},
1616
): CompletionSource {
1717
return async (
1818
context: CompletionContext,

0 commit comments

Comments
 (0)