Skip to content

Commit fbd3566

Browse files
feat(monaco): 优化提示文本样式
1 parent e078b5e commit fbd3566

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/monaco/src/lsp/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ export type ParamSignature = [name: string, sig: string, doc: string];
2727

2828
/** 缩进 */
2929
function indent(str: string, level: number, skipFirstLine = false): string {
30-
if (level <= 0) return str;
3130
const prefix = ' '.repeat(level);
3231
const lines = str.split('\n');
32+
// remove leading and trailing empty lines
33+
while (lines.length && lines[0]!.trim() === '') {
34+
lines.shift();
35+
}
36+
while (lines.length && lines.at(-1)!.trim() === '') {
37+
lines.pop();
38+
}
3339
const lineCount = lines.length;
3440
for (let i = skipFirstLine ? 1 : 0; i < lineCount; i++) {
3541
lines[i] = prefix + lines[i];
@@ -44,7 +50,7 @@ function globalParamsSignature(info: VmFunctionInfo | undefined): ParamSignature
4450
for (const [key, value] of Object.entries(info.params)) {
4551
const type = value.type ?? '';
4652
const doc = value.description ?? '';
47-
paramItems.push([key, `${key}: ${type || 'any'}`, doc ? `\`${key}\`: ${doc}` : '']);
53+
paramItems.push([key, `${key}: ${type || 'any'}`, doc ? `\`${key}\`: ${indent(doc, 0, true)}` : '']);
4854
}
4955
return paramItems;
5056
}

0 commit comments

Comments
 (0)