Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 52963ea

Browse files
authored
Throttle showDecoration (#66)
1 parent a9fd41b commit 52963ea

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

package-lock.json

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@
3939
"test": "node ./out/test/runTest.js",
4040
"deploy": "vsce publish"
4141
},
42+
"dependencies": {
43+
"throttle-debounce": "^5.0.0"
44+
},
4245
"devDependencies": {
4346
"@types/mocha": "^10.0.6",
4447
"@types/node": "20.x",
48+
"@types/throttle-debounce": "^5.0.2",
4549
"@types/vscode": "^1.78.0",
4650
"@typescript-eslint/eslint-plugin": "^7.4.0",
4751
"@typescript-eslint/parser": "^7.4.0",
@@ -52,4 +56,4 @@
5256
"mocha": "^10.4.0",
5357
"typescript": "^5.4.3"
5458
}
55-
}
59+
}

src/extension.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import * as cp from "child_process";
3+
import { throttle } from "throttle-debounce";
34

45
import {
56
parseGitBlamePorcelain,
@@ -74,13 +75,14 @@ function showDecoration(e: { readonly textEditor: vscode.TextEditor }) {
7475

7576
export function activate(context: vscode.ExtensionContext) {
7677
console.log('Extension "git-line-blame" has activated.');
78+
let showDecorationThrottled = throttle(100, showDecoration);
7779
context.subscriptions.push(
78-
vscode.window.onDidChangeTextEditorSelection(showDecoration),
79-
vscode.window.onDidChangeTextEditorVisibleRanges(showDecoration),
80+
vscode.window.onDidChangeTextEditorSelection(showDecorationThrottled),
81+
vscode.window.onDidChangeTextEditorVisibleRanges(showDecorationThrottled),
8082
vscode.workspace.onDidSaveTextDocument((e) => {
8183
const editor = vscode.window.activeTextEditor;
8284
if (editor !== undefined && e === editor.document) {
83-
showDecoration({ textEditor: editor });
85+
showDecorationThrottled({ textEditor: editor });
8486
}
8587
})
8688
);

0 commit comments

Comments
 (0)