From ce4fb06dec597207324195ae62db93f53984b890 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Thu, 10 Oct 2019 13:26:17 +0200 Subject: Truncate hints longer than 20 characters --- editors/code/src/commands/inlay_hints.ts | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'editors/code') diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index 5393a2bc9..3157c04c8 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts @@ -13,6 +13,8 @@ interface InlayHint { label: string; } +const maxHintLength = 20; + const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ after: { color: new vscode.ThemeColor('ralsp.inlayHint') @@ -83,10 +85,20 @@ export class HintsUpdater { ): Promise { const newHints = await this.queryHints(editor.document.uri.toString()); if (newHints !== null) { - const newDecorations = newHints.map(hint => ({ - range: hint.range, - renderOptions: { after: { contentText: `: ${hint.label}` } } - })); + const newDecorations = newHints.map(hint => { + let label = hint.label.substring(0, maxHintLength); + if (hint.label.length > maxHintLength) { + label += '…'; + } + return { + range: this.truncateHint(hint.range), + renderOptions: { + after: { + contentText: `: ${label}` + } + } + }; + }); return editor.setDecorations( typeHintDecorationType, newDecorations @@ -94,6 +106,18 @@ export class HintsUpdater { } } + private truncateHint(range: Range): Range { + if (!range.isSingleLine) { + return range; + } + const maxEnd = new vscode.Position( + range.start.line, + range.start.character + maxHintLength + ); + const end = range.end.isAfter(maxEnd) ? maxEnd : range.end; + return new Range(range.start, end); + } + private async queryHints(documentUri: string): Promise { const request: InlayHintsParams = { textDocument: { uri: documentUri } -- cgit v1.2.3