diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-23 12:13:04 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-23 12:13:04 +0100 |
commit | d2e1f9f6da01132fd23394b5b789e4ef96ccc444 (patch) | |
tree | 686a96cbf68c7ae3c43c9f062d49cf70edd71cdb /editors | |
parent | 195272270be99c353c9555c9e36c66068434af60 (diff) | |
parent | 770bb8dc9b0d2e693918a4f8c8039bf2c6deab66 (diff) |
Merge #1980
1980: Shorten inline type hints r=matklad a=detrumi
Implements #1946
Co-authored-by: Wilco Kusee <[email protected]>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/commands/inlay_hints.ts | 18 | ||||
-rw-r--r-- | editors/code/src/config.ts | 6 |
3 files changed, 28 insertions, 1 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index 5ae050110..4b719aada 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -270,6 +270,11 @@ | |||
270 | "type": "boolean", | 270 | "type": "boolean", |
271 | "default": true, | 271 | "default": true, |
272 | "description": "Display additional type information in the editor" | 272 | "description": "Display additional type information in the editor" |
273 | }, | ||
274 | "rust-analyzer.maxInlayHintLength": { | ||
275 | "type": "number", | ||
276 | "default": 20, | ||
277 | "description": "Maximum length for inlay hints" | ||
273 | } | 278 | } |
274 | } | 279 | } |
275 | }, | 280 | }, |
diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index 5393a2bc9..ffaaaebcb 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts | |||
@@ -85,7 +85,11 @@ export class HintsUpdater { | |||
85 | if (newHints !== null) { | 85 | if (newHints !== null) { |
86 | const newDecorations = newHints.map(hint => ({ | 86 | const newDecorations = newHints.map(hint => ({ |
87 | range: hint.range, | 87 | range: hint.range, |
88 | renderOptions: { after: { contentText: `: ${hint.label}` } } | 88 | renderOptions: { |
89 | after: { | ||
90 | contentText: `: ${this.truncateHint(hint.label)}` | ||
91 | } | ||
92 | } | ||
89 | })); | 93 | })); |
90 | return editor.setDecorations( | 94 | return editor.setDecorations( |
91 | typeHintDecorationType, | 95 | typeHintDecorationType, |
@@ -94,6 +98,18 @@ export class HintsUpdater { | |||
94 | } | 98 | } |
95 | } | 99 | } |
96 | 100 | ||
101 | private truncateHint(label: string): string { | ||
102 | if (!Server.config.maxInlayHintLength) { | ||
103 | return label; | ||
104 | } | ||
105 | |||
106 | let newLabel = label.substring(0, Server.config.maxInlayHintLength); | ||
107 | if (label.length > Server.config.maxInlayHintLength) { | ||
108 | newLabel += '…'; | ||
109 | } | ||
110 | return newLabel; | ||
111 | } | ||
112 | |||
97 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { | 113 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { |
98 | const request: InlayHintsParams = { | 114 | const request: InlayHintsParams = { |
99 | textDocument: { uri: documentUri } | 115 | textDocument: { uri: documentUri } |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 49bdf7d72..331936b5e 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -23,6 +23,7 @@ export class Config { | |||
23 | public showWorkspaceLoadedNotification = true; | 23 | public showWorkspaceLoadedNotification = true; |
24 | public lruCapacity: null | number = null; | 24 | public lruCapacity: null | number = null; |
25 | public displayInlayHints = true; | 25 | public displayInlayHints = true; |
26 | public maxInlayHintLength: null | number = null; | ||
26 | public excludeGlobs = []; | 27 | public excludeGlobs = []; |
27 | public useClientWatching = false; | 28 | public useClientWatching = false; |
28 | public featureFlags = {}; | 29 | public featureFlags = {}; |
@@ -140,6 +141,11 @@ export class Config { | |||
140 | if (config.has('displayInlayHints')) { | 141 | if (config.has('displayInlayHints')) { |
141 | this.displayInlayHints = config.get('displayInlayHints') as boolean; | 142 | this.displayInlayHints = config.get('displayInlayHints') as boolean; |
142 | } | 143 | } |
144 | if (config.has('maxInlayHintLength')) { | ||
145 | this.maxInlayHintLength = config.get( | ||
146 | 'maxInlayHintLength' | ||
147 | ) as number; | ||
148 | } | ||
143 | if (config.has('excludeGlobs')) { | 149 | if (config.has('excludeGlobs')) { |
144 | this.excludeGlobs = config.get('excludeGlobs') || []; | 150 | this.excludeGlobs = config.get('excludeGlobs') || []; |
145 | } | 151 | } |