diff --git a/editors/code/package.json b/editors/code/package.json index 5ae0501108..4b719aadaf 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -270,6 +270,11 @@ "type": "boolean", "default": true, "description": "Display additional type information in the editor" + }, + "rust-analyzer.maxInlayHintLength": { + "type": "number", + "default": 20, + "description": "Maximum length for inlay hints" } } }, diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index 5393a2bc92..ffaaaebcb0 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts @@ -85,7 +85,11 @@ export class HintsUpdater { if (newHints !== null) { const newDecorations = newHints.map(hint => ({ range: hint.range, - renderOptions: { after: { contentText: `: ${hint.label}` } } + renderOptions: { + after: { + contentText: `: ${this.truncateHint(hint.label)}` + } + } })); return editor.setDecorations( typeHintDecorationType, @@ -94,6 +98,18 @@ export class HintsUpdater { } } + private truncateHint(label: string): string { + if (!Server.config.maxInlayHintLength) { + return label; + } + + let newLabel = label.substring(0, Server.config.maxInlayHintLength); + if (label.length > Server.config.maxInlayHintLength) { + newLabel += '…'; + } + return newLabel; + } + private async queryHints(documentUri: string): Promise { const request: InlayHintsParams = { textDocument: { uri: documentUri } diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 49bdf7d729..331936b5ec 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -23,6 +23,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 = {}; @@ -140,6 +141,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') || []; }