From 14442f9bac07d867d3708a315bda0f41231df89e Mon Sep 17 00:00:00 2001 From: NonSpicyBurrito Date: Sun, 3 Sep 2023 01:53:39 +0800 Subject: [PATCH] Added shifting multiline hover information --- package.json | 5 +++++ src/decoration.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 35d8dac..f079331 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,11 @@ "description": "Debounce hover information update (set to 0 for no debounce).\nUpdating hover information too quickly may degrade editor performance.", "type": "number", "default": 50 + }, + "hoverlens.maximumShiftCount": { + "description": "Maximum character count which multiline hover information is allowed to be shifted to avoid being cut off.", + "type": "number", + "default": 40 } } } diff --git a/src/decoration.ts b/src/decoration.ts index de6f1bd..d346517 100644 --- a/src/decoration.ts +++ b/src/decoration.ts @@ -33,6 +33,10 @@ export async function getDecorations( hovers.map(toPlainText).map(removeEmptyLines).join('\n').split('\n') ) + const maxShift = vscode.workspace + .getConfiguration('hoverlens') + .get('maximumShiftCount', 20) + const layouts = positions.map((position, i) => { const paddings: number[] = [] @@ -41,7 +45,8 @@ export async function getDecorations( position.line const count = Math.min(lines[i].length, space) - const startLineLength = getLineLength(position.line) + const startLineLength = + getLineLength(position.line) + Math.max(maxShift, 0) for (let i = 0; i < count; i++) { const lineLength = getLineLength(position.line + i) if (lineLength > startLineLength) break @@ -49,7 +54,8 @@ export async function getDecorations( paddings.push(startLineLength - lineLength) } - return paddings + const min = Math.min(...paddings) + return paddings.map((padding) => padding - min) }) const texts = layouts.map((paddings, i) => {