diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ffb99..78bc688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [1.1.0] + +- Improved icon +- Added maximum cursor count +- Added debounce update + ## [1.0.0] - Initial release diff --git a/icon.png b/icon.png index 56d2fe6..426fb23 100644 Binary files a/icon.png and b/icon.png differ diff --git a/package-lock.json b/package-lock.json index 69b06d7..bf6b281 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "hoverlens", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "hoverlens", - "version": "1.0.0", + "version": "1.1.0", "license": "MIT", "dependencies": { "lodash": "^4.17.21", diff --git a/package.json b/package.json index b44b379..d675507 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hoverlens", - "version": "1.0.0", + "version": "1.1.0", "publisher": "NonSpicyBurrito", "engines": { "vscode": "^1.71.0" @@ -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" ], diff --git a/src/decoration.ts b/src/decoration.ts index 1a44d42..de6f1bd 100644 --- a/src/decoration.ts +++ b/src/decoration.ts @@ -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) diff --git a/src/extension.ts b/src/extension.ts index ec44f75..bd0d06e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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> = [] - 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 @@ -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) }) ) } diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..3fe82f6 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,16 @@ +export function debounce unknown>( + fn: T, + getMs: () => number +) { + let timer: NodeJS.Timeout + return (...args: Parameters) => { + clearTimeout(timer) + + const ms = getMs() + if (ms > 0) { + timer = setTimeout(() => fn(...args), getMs()) + } else { + fn(...args) + } + } +}