aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/inlay_hints.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/inlay_hints.ts')
-rw-r--r--editors/code/src/commands/inlay_hints.ts40
1 files changed, 26 insertions, 14 deletions
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 {
13 label: string; 13 label: string;
14} 14}
15 15
16const maxHintLength = 20;
17
18const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ 16const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
19 after: { 17 after: {
20 color: new vscode.ThemeColor('ralsp.inlayHint') 18 color: new vscode.ThemeColor('ralsp.inlayHint')
@@ -86,12 +84,12 @@ export class HintsUpdater {
86 const newHints = await this.queryHints(editor.document.uri.toString()); 84 const newHints = await this.queryHints(editor.document.uri.toString());
87 if (newHints !== null) { 85 if (newHints !== null) {
88 const newDecorations = newHints.map(hint => { 86 const newDecorations = newHints.map(hint => {
89 let label = hint.label.substring(0, maxHintLength); 87 const [label, range] = this.truncateHint(
90 if (hint.label.length > maxHintLength) { 88 hint.label,
91 label += '…'; 89 hint.range
92 } 90 );
93 return { 91 return {
94 range: this.truncateHint(hint.range), 92 range,
95 renderOptions: { 93 renderOptions: {
96 after: { 94 after: {
97 contentText: `: ${label}` 95 contentText: `: ${label}`
@@ -106,16 +104,30 @@ export class HintsUpdater {
106 } 104 }
107 } 105 }
108 106
109 private truncateHint(range: Range): Range { 107 private truncateHint(
110 if (!range.isSingleLine) { 108 label: string,
111 return range; 109 range: vscode.Range
110 ): [string, vscode.Range] {
111 if (!Server.config.maxInlayHintLength) {
112 return [label, range];
113 }
114
115 let newLabel = label.substring(0, Server.config.maxInlayHintLength);
116 if (label.length > Server.config.maxInlayHintLength) {
117 newLabel += '…';
112 } 118 }
113 const maxEnd = new vscode.Position( 119
120 range = new vscode.Range(
114 range.start.line, 121 range.start.line,
115 range.start.character + maxHintLength 122 range.start.character,
123 range.end.line,
124 Math.min(
125 range.start.character + Server.config.maxInlayHintLength,
126 range.end.character
127 )
116 ); 128 );
117 const end = range.end.isAfter(maxEnd) ? maxEnd : range.end; 129
118 return new Range(range.start, end); 130 return [newLabel, range];
119 } 131 }
120 132
121 private async queryHints(documentUri: string): Promise<InlayHint[] | null> { 133 private async queryHints(documentUri: string): Promise<InlayHint[] | null> {