Skip to content

Commit

Permalink
Added shifting multiline hover information
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSpicyBurrito committed Sep 2, 2023
1 parent 88bb690 commit 14442f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/decoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []

Expand All @@ -41,15 +45,17 @@ 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

paddings.push(startLineLength - lineLength)
}

return paddings
const min = Math.min(...paddings)
return paddings.map((padding) => padding - min)
})

const texts = layouts.map((paddings, i) => {
Expand Down

0 comments on commit 14442f9

Please sign in to comment.