Skip to content

Commit

Permalink
Throttle showDecoration (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
msvbg authored Jun 6, 2024
1 parent a9fd41b commit 52963ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@
"test": "node ./out/test/runTest.js",
"deploy": "vsce publish"
},
"dependencies": {
"throttle-debounce": "^5.0.0"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/node": "20.x",
"@types/throttle-debounce": "^5.0.2",
"@types/vscode": "^1.78.0",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
Expand All @@ -52,4 +56,4 @@
"mocha": "^10.4.0",
"typescript": "^5.4.3"
}
}
}
8 changes: 5 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode";
import * as cp from "child_process";
import { throttle } from "throttle-debounce";

import {
parseGitBlamePorcelain,
Expand Down Expand Up @@ -74,13 +75,14 @@ function showDecoration(e: { readonly textEditor: vscode.TextEditor }) {

export function activate(context: vscode.ExtensionContext) {
console.log('Extension "git-line-blame" has activated.');
let showDecorationThrottled = throttle(100, showDecoration);
context.subscriptions.push(
vscode.window.onDidChangeTextEditorSelection(showDecoration),
vscode.window.onDidChangeTextEditorVisibleRanges(showDecoration),
vscode.window.onDidChangeTextEditorSelection(showDecorationThrottled),
vscode.window.onDidChangeTextEditorVisibleRanges(showDecorationThrottled),
vscode.workspace.onDidSaveTextDocument((e) => {
const editor = vscode.window.activeTextEditor;
if (editor !== undefined && e === editor.document) {
showDecoration({ textEditor: editor });
showDecorationThrottled({ textEditor: editor });
}
})
);
Expand Down

0 comments on commit 52963ea

Please sign in to comment.