diff --git a/package.json b/package.json index 4fc1337..8febb74 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,11 @@ "configuration": { "title": "Hover Lens", "properties": { + "hoverlens.enabled": { + "description": "Whether Hover Lens is enabled or not.", + "type": "boolean", + "default": true + }, "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", diff --git a/src/config.ts b/src/config.ts index 38a6e66..5bac94e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,8 @@ import * as vscode from 'vscode' +export const getEnabled = () => + vscode.workspace.getConfiguration('hoverlens').get('enabled', true) + export const getMaxCount = () => vscode.workspace.getConfiguration('hoverlens').get('maximumCursorCount', 3) diff --git a/src/extension.ts b/src/extension.ts index 231d789..74ebb26 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode' import { Decoration, getDecorations } from './decoration' import { debounce } from './utils' -import { getDebounceUpdate } from './config' +import { getDebounceUpdate, getEnabled } from './config' let tokenSource: vscode.CancellationTokenSource | undefined const startUpdate = () => { @@ -25,6 +25,8 @@ const setDecorations = (decorations: Decoration[]) => { const updateDecorations = debounce( async (event: vscode.TextEditorSelectionChangeEvent) => { + if (!getEnabled()) return + const token = startUpdate() const decorations = await getDecorations( @@ -39,6 +41,15 @@ const updateDecorations = debounce( ) export const activate = (context: vscode.ExtensionContext) => { + context.subscriptions.push( + vscode.workspace.onDidChangeConfiguration(() => { + if (getEnabled()) return + + cancelUpdate() + setDecorations([]) + }) + ) + context.subscriptions.push( vscode.window.onDidChangeTextEditorSelection((event) => { cancelUpdate()