Skip to content

Commit

Permalink
Merge pull request #1 from NonSpicyBurrito:develop
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
NonSpicyBurrito authored Oct 13, 2022
2 parents 6b7fbbc + c8b9d22 commit ce459a0
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [1.1.0]

- Improved icon
- Added maximum cursor count
- Added debounce update

## [1.0.0]

- Initial release
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hoverlens",
"version": "1.0.0",
"version": "1.1.0",
"publisher": "NonSpicyBurrito",
"engines": {
"vscode": "^1.71.0"
Expand All @@ -19,7 +19,23 @@
"url": "https://github.com/NonSpicyBurrito/hoverlens.git"
},
"main": "./dist/extension.js",
"contributes": {},
"contributes": {
"configuration": {
"title": "Hover Lens",
"properties": {
"hoverlens.maximumCursorCount": {
"description": "Maximum cursor count which hover information will be displayed (set to 0 for unlimited).\nDisplaying hover information for too many cursors may degrade editor performance.",
"type": "number",
"default": 3
},
"hoverlens.debounceUpdate": {
"description": "Debounce hover information update (set to 0 for no debounce).\nUpdating hover information too quickly may degrade editor performance.",
"type": "number",
"default": 50
}
}
}
},
"activationEvents": [
"onStartupFinished"
],
Expand Down
5 changes: 5 additions & 0 deletions src/decoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export async function getDecorations(
) {
if (!selections.length) return []

const maxCount = vscode.workspace
.getConfiguration('hoverlens')
.get('maximumCursorCount', 3)
if (maxCount > 0 && selections.length > maxCount) return []

const positions = selections
.map((selection) => selection.active)
.sort((a, b) => b.line - a.line || b.character - a.character)
Expand Down
17 changes: 14 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as vscode from 'vscode'
import { getDecorations } from './decoration'
import { debounce } from './utils'

export function activate(context: vscode.ExtensionContext) {
let tokenSource: vscode.CancellationTokenSource

let currentDecorations: Awaited<ReturnType<typeof getDecorations>> = []

context.subscriptions.push(
vscode.window.onDidChangeTextEditorSelection(async (event) => {
tokenSource?.cancel()
const updateDecorations = debounce(
async (event: vscode.TextEditorSelectionChangeEvent) => {
tokenSource = new vscode.CancellationTokenSource()

const token = tokenSource.token
Expand All @@ -28,6 +28,17 @@ export function activate(context: vscode.ExtensionContext) {
new vscode.Selection(line, 0, line, 0),
])
)
},
() =>
vscode.workspace
.getConfiguration('hoverlens')
.get('debounceUpdate', 50)
)

context.subscriptions.push(
vscode.window.onDidChangeTextEditorSelection((event) => {
tokenSource?.cancel()
updateDecorations(event)
})
)
}
16 changes: 16 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function debounce<T extends (...args: never[]) => unknown>(
fn: T,
getMs: () => number
) {
let timer: NodeJS.Timeout
return (...args: Parameters<T>) => {
clearTimeout(timer)

const ms = getMs()
if (ms > 0) {
timer = setTimeout(() => fn(...args), getMs())
} else {
fn(...args)
}
}
}

0 comments on commit ce459a0

Please sign in to comment.