mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Merge #1980
1980: Shorten inline type hints r=matklad a=detrumi Implements #1946 Co-authored-by: Wilco Kusee <wilcokusee@gmail.com>
This commit is contained in:
commit
d2e1f9f6da
3 changed files with 28 additions and 1 deletions
|
@ -270,6 +270,11 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "Display additional type information in the editor"
|
"description": "Display additional type information in the editor"
|
||||||
|
},
|
||||||
|
"rust-analyzer.maxInlayHintLength": {
|
||||||
|
"type": "number",
|
||||||
|
"default": 20,
|
||||||
|
"description": "Maximum length for inlay hints"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -85,7 +85,11 @@ export class HintsUpdater {
|
||||||
if (newHints !== null) {
|
if (newHints !== null) {
|
||||||
const newDecorations = newHints.map(hint => ({
|
const newDecorations = newHints.map(hint => ({
|
||||||
range: hint.range,
|
range: hint.range,
|
||||||
renderOptions: { after: { contentText: `: ${hint.label}` } }
|
renderOptions: {
|
||||||
|
after: {
|
||||||
|
contentText: `: ${this.truncateHint(hint.label)}`
|
||||||
|
}
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
return editor.setDecorations(
|
return editor.setDecorations(
|
||||||
typeHintDecorationType,
|
typeHintDecorationType,
|
||||||
|
@ -94,6 +98,18 @@ export class HintsUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private truncateHint(label: string): string {
|
||||||
|
if (!Server.config.maxInlayHintLength) {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
let newLabel = label.substring(0, Server.config.maxInlayHintLength);
|
||||||
|
if (label.length > Server.config.maxInlayHintLength) {
|
||||||
|
newLabel += '…';
|
||||||
|
}
|
||||||
|
return newLabel;
|
||||||
|
}
|
||||||
|
|
||||||
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
||||||
const request: InlayHintsParams = {
|
const request: InlayHintsParams = {
|
||||||
textDocument: { uri: documentUri }
|
textDocument: { uri: documentUri }
|
||||||
|
|
|
@ -23,6 +23,7 @@ export class Config {
|
||||||
public showWorkspaceLoadedNotification = true;
|
public showWorkspaceLoadedNotification = true;
|
||||||
public lruCapacity: null | number = null;
|
public lruCapacity: null | number = null;
|
||||||
public displayInlayHints = true;
|
public displayInlayHints = true;
|
||||||
|
public maxInlayHintLength: null | number = null;
|
||||||
public excludeGlobs = [];
|
public excludeGlobs = [];
|
||||||
public useClientWatching = false;
|
public useClientWatching = false;
|
||||||
public featureFlags = {};
|
public featureFlags = {};
|
||||||
|
@ -140,6 +141,11 @@ export class Config {
|
||||||
if (config.has('displayInlayHints')) {
|
if (config.has('displayInlayHints')) {
|
||||||
this.displayInlayHints = config.get('displayInlayHints') as boolean;
|
this.displayInlayHints = config.get('displayInlayHints') as boolean;
|
||||||
}
|
}
|
||||||
|
if (config.has('maxInlayHintLength')) {
|
||||||
|
this.maxInlayHintLength = config.get(
|
||||||
|
'maxInlayHintLength'
|
||||||
|
) as number;
|
||||||
|
}
|
||||||
if (config.has('excludeGlobs')) {
|
if (config.has('excludeGlobs')) {
|
||||||
this.excludeGlobs = config.get('excludeGlobs') || [];
|
this.excludeGlobs = config.get('excludeGlobs') || [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue