diff options
author | Wilco Kusee <[email protected]> | 2019-10-10 12:26:17 +0100 |
---|---|---|
committer | Wilco Kusee <[email protected]> | 2019-10-10 13:52:05 +0100 |
commit | ce4fb06dec597207324195ae62db93f53984b890 (patch) | |
tree | 5f66834352ba3ef53a594cf2da985982b26c89e4 | |
parent | 523d7d2c8210b382146c76927e93f1cc8a6d31e2 (diff) |
Truncate hints longer than 20 characters
-rw-r--r-- | editors/code/src/commands/inlay_hints.ts | 32 |
1 files changed, 28 insertions, 4 deletions
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 { | |||
13 | label: string; | 13 | label: string; |
14 | } | 14 | } |
15 | 15 | ||
16 | const maxHintLength = 20; | ||
17 | |||
16 | const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ | 18 | const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ |
17 | after: { | 19 | after: { |
18 | color: new vscode.ThemeColor('ralsp.inlayHint') | 20 | color: new vscode.ThemeColor('ralsp.inlayHint') |
@@ -83,10 +85,20 @@ export class HintsUpdater { | |||
83 | ): Promise<void> { | 85 | ): Promise<void> { |
84 | const newHints = await this.queryHints(editor.document.uri.toString()); | 86 | const newHints = await this.queryHints(editor.document.uri.toString()); |
85 | if (newHints !== null) { | 87 | if (newHints !== null) { |
86 | const newDecorations = newHints.map(hint => ({ | 88 | const newDecorations = newHints.map(hint => { |
87 | range: hint.range, | 89 | let label = hint.label.substring(0, maxHintLength); |
88 | renderOptions: { after: { contentText: `: ${hint.label}` } } | 90 | if (hint.label.length > maxHintLength) { |
89 | })); | 91 | label += '…'; |
92 | } | ||
93 | return { | ||
94 | range: this.truncateHint(hint.range), | ||
95 | renderOptions: { | ||
96 | after: { | ||
97 | contentText: `: ${label}` | ||
98 | } | ||
99 | } | ||
100 | }; | ||
101 | }); | ||
90 | return editor.setDecorations( | 102 | return editor.setDecorations( |
91 | typeHintDecorationType, | 103 | typeHintDecorationType, |
92 | newDecorations | 104 | newDecorations |
@@ -94,6 +106,18 @@ export class HintsUpdater { | |||
94 | } | 106 | } |
95 | } | 107 | } |
96 | 108 | ||
109 | private truncateHint(range: Range): Range { | ||
110 | if (!range.isSingleLine) { | ||
111 | return range; | ||
112 | } | ||
113 | const maxEnd = new vscode.Position( | ||
114 | range.start.line, | ||
115 | range.start.character + maxHintLength | ||
116 | ); | ||
117 | const end = range.end.isAfter(maxEnd) ? maxEnd : range.end; | ||
118 | return new Range(range.start, end); | ||
119 | } | ||
120 | |||
97 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { | 121 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { |
98 | const request: InlayHintsParams = { | 122 | const request: InlayHintsParams = { |
99 | textDocument: { uri: documentUri } | 123 | textDocument: { uri: documentUri } |