Do not truncate the range

This commit is contained in:
Wilco Kusee 2019-10-23 13:11:40 +02:00
parent 3b61acb4ae
commit 770bb8dc9b
No known key found for this signature in database
GPG key ID: D5B2BB5CDC3334BC

View file

@ -83,20 +83,14 @@ export class HintsUpdater {
): Promise<void> { ): Promise<void> {
const newHints = await this.queryHints(editor.document.uri.toString()); const newHints = await this.queryHints(editor.document.uri.toString());
if (newHints !== null) { if (newHints !== null) {
const newDecorations = newHints.map(hint => { const newDecorations = newHints.map(hint => ({
const [label, range] = this.truncateHint( range: hint.range,
hint.label, renderOptions: {
hint.range after: {
); contentText: `: ${this.truncateHint(hint.label)}`
return {
range,
renderOptions: {
after: {
contentText: `: ${label}`
}
} }
}; }
}); }));
return editor.setDecorations( return editor.setDecorations(
typeHintDecorationType, typeHintDecorationType,
newDecorations newDecorations
@ -104,30 +98,16 @@ export class HintsUpdater {
} }
} }
private truncateHint( private truncateHint(label: string): string {
label: string,
range: vscode.Range
): [string, vscode.Range] {
if (!Server.config.maxInlayHintLength) { if (!Server.config.maxInlayHintLength) {
return [label, range]; return label;
} }
let newLabel = label.substring(0, Server.config.maxInlayHintLength); let newLabel = label.substring(0, Server.config.maxInlayHintLength);
if (label.length > Server.config.maxInlayHintLength) { if (label.length > Server.config.maxInlayHintLength) {
newLabel += '…'; newLabel += '…';
} }
return newLabel;
range = new vscode.Range(
range.start.line,
range.start.character,
range.end.line,
Math.min(
range.start.character + Server.config.maxInlayHintLength,
range.end.character
)
);
return [newLabel, range];
} }
private async queryHints(documentUri: string): Promise<InlayHint[] | null> { private async queryHints(documentUri: string): Promise<InlayHint[] | null> {