diff options
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/commands/inlay_hints.ts | 40 | ||||
-rw-r--r-- | editors/code/src/config.ts | 6 |
2 files changed, 32 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 | ||
16 | const maxHintLength = 20; | ||
17 | |||
18 | const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ | 16 | const 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> { |
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 { | |||
22 | public showWorkspaceLoadedNotification = true; | 22 | public showWorkspaceLoadedNotification = true; |
23 | public lruCapacity: null | number = null; | 23 | public lruCapacity: null | number = null; |
24 | public displayInlayHints = true; | 24 | public displayInlayHints = true; |
25 | public maxInlayHintLength: null | number = null; | ||
25 | public excludeGlobs = []; | 26 | public excludeGlobs = []; |
26 | public useClientWatching = false; | 27 | public useClientWatching = false; |
27 | public featureFlags = {}; | 28 | public featureFlags = {}; |
@@ -131,6 +132,11 @@ export class Config { | |||
131 | if (config.has('displayInlayHints')) { | 132 | if (config.has('displayInlayHints')) { |
132 | this.displayInlayHints = config.get('displayInlayHints') as boolean; | 133 | this.displayInlayHints = config.get('displayInlayHints') as boolean; |
133 | } | 134 | } |
135 | if (config.has('maxInlayHintLength')) { | ||
136 | this.maxInlayHintLength = config.get( | ||
137 | 'maxInlayHintLength' | ||
138 | ) as number; | ||
139 | } | ||
134 | if (config.has('excludeGlobs')) { | 140 | if (config.has('excludeGlobs')) { |
135 | this.excludeGlobs = config.get('excludeGlobs') || []; | 141 | this.excludeGlobs = config.get('excludeGlobs') || []; |
136 | } | 142 | } |