aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorWilco Kusee <[email protected]>2019-10-18 12:40:03 +0100
committerWilco Kusee <[email protected]>2019-10-18 12:45:04 +0100
commit3b61acb4ae15a1ec6071db40e09437319795db67 (patch)
tree7aad0029f3f138cc2d6a21a3051c11b57a047cf1 /editors
parentce4fb06dec597207324195ae62db93f53984b890 (diff)
Make inlay hint length configurable
Diffstat (limited to 'editors')
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/commands/inlay_hints.ts40
-rw-r--r--editors/code/src/config.ts6
3 files changed, 37 insertions, 14 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index b9982c624..35211bcc2 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -260,6 +260,11 @@
260 "type": "boolean", 260 "type": "boolean",
261 "default": true, 261 "default": true,
262 "description": "Display additional type information in the editor" 262 "description": "Display additional type information in the editor"
263 },
264 "rust-analyzer.maxInlayHintLength": {
265 "type": "number",
266 "default": 20,
267 "description": "Maximum length for inlay hints"
263 } 268 }
264 } 269 }
265 }, 270 },
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> {
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 }