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/src') 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 From 3b61acb4ae15a1ec6071db40e09437319795db67 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Fri, 18 Oct 2019 13:40:03 +0200 Subject: Make inlay hint length configurable --- editors/code/src/commands/inlay_hints.ts | 40 +++++++++++++++++++++----------- editors/code/src/config.ts | 6 +++++ 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index 3157c04c8..454a464d4 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts @@ -13,8 +13,6 @@ interface InlayHint { label: string; } -const maxHintLength = 20; - const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ after: { color: new vscode.ThemeColor('ralsp.inlayHint') @@ -86,12 +84,12 @@ export class HintsUpdater { const newHints = await this.queryHints(editor.document.uri.toString()); if (newHints !== null) { const newDecorations = newHints.map(hint => { - let label = hint.label.substring(0, maxHintLength); - if (hint.label.length > maxHintLength) { - label += '…'; - } + const [label, range] = this.truncateHint( + hint.label, + hint.range + ); return { - range: this.truncateHint(hint.range), + range, renderOptions: { after: { contentText: `: ${label}` @@ -106,16 +104,30 @@ export class HintsUpdater { } } - private truncateHint(range: Range): Range { - if (!range.isSingleLine) { - return range; + private truncateHint( + label: string, + range: vscode.Range + ): [string, vscode.Range] { + if (!Server.config.maxInlayHintLength) { + return [label, range]; + } + + let newLabel = label.substring(0, Server.config.maxInlayHintLength); + if (label.length > Server.config.maxInlayHintLength) { + newLabel += '…'; } - const maxEnd = new vscode.Position( + + range = new vscode.Range( range.start.line, - range.start.character + maxHintLength + range.start.character, + range.end.line, + Math.min( + range.start.character + Server.config.maxInlayHintLength, + range.end.character + ) ); - const end = range.end.isAfter(maxEnd) ? maxEnd : range.end; - return new Range(range.start, end); + + return [newLabel, range]; } private async queryHints(documentUri: string): Promise { diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index a4581485c..2578bc6d1 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -22,6 +22,7 @@ export class Config { public showWorkspaceLoadedNotification = true; public lruCapacity: null | number = null; public displayInlayHints = true; + public maxInlayHintLength: null | number = null; public excludeGlobs = []; public useClientWatching = false; public featureFlags = {}; @@ -131,6 +132,11 @@ export class Config { if (config.has('displayInlayHints')) { this.displayInlayHints = config.get('displayInlayHints') as boolean; } + if (config.has('maxInlayHintLength')) { + this.maxInlayHintLength = config.get( + 'maxInlayHintLength' + ) as number; + } if (config.has('excludeGlobs')) { this.excludeGlobs = config.get('excludeGlobs') || []; } -- cgit v1.2.3 From 770bb8dc9b0d2e693918a4f8c8039bf2c6deab66 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Wed, 23 Oct 2019 13:11:40 +0200 Subject: Do not truncate the range --- editors/code/src/commands/inlay_hints.ts | 40 ++++++++------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index 454a464d4..ffaaaebcb 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts @@ -83,20 +83,14 @@ export class HintsUpdater { ): Promise { const newHints = await this.queryHints(editor.document.uri.toString()); if (newHints !== null) { - const newDecorations = newHints.map(hint => { - const [label, range] = this.truncateHint( - hint.label, - hint.range - ); - return { - range, - renderOptions: { - after: { - contentText: `: ${label}` - } + const newDecorations = newHints.map(hint => ({ + range: hint.range, + renderOptions: { + after: { + contentText: `: ${this.truncateHint(hint.label)}` } - }; - }); + } + })); return editor.setDecorations( typeHintDecorationType, newDecorations @@ -104,30 +98,16 @@ export class HintsUpdater { } } - private truncateHint( - label: string, - range: vscode.Range - ): [string, vscode.Range] { + private truncateHint(label: string): string { if (!Server.config.maxInlayHintLength) { - return [label, range]; + return label; } let newLabel = label.substring(0, Server.config.maxInlayHintLength); if (label.length > Server.config.maxInlayHintLength) { newLabel += '…'; } - - range = new vscode.Range( - range.start.line, - range.start.character, - range.end.line, - Math.min( - range.start.character + Server.config.maxInlayHintLength, - range.end.character - ) - ); - - return [newLabel, range]; + return newLabel; } private async queryHints(documentUri: string): Promise { -- cgit v1.2.3