Skip to content

Commit

Permalink
Added enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSpicyBurrito committed Sep 8, 2023
1 parent a396191 commit 09faa41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
13 changes: 12 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand All @@ -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(
Expand All @@ -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()
Expand Down

0 comments on commit 09faa41

Please sign in to comment.