Skip to content

Commit bb6c8b7

Browse files
committed
More logging
1 parent 3e27e65 commit bb6c8b7

File tree

10 files changed

+194
-140
lines changed

10 files changed

+194
-140
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## 11.0.2 (July 17, 2024)
4+
* Feature: Adding logging behind the `debug` and `trace` levels.
45
* Fix: Updating dependencies
56

67
## 11.0.1 (May 29, 2024)

esbuild.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ await build({
1212
"node:child_process",
1313
"node:fs",
1414
"node:fs/promises",
15-
"node:url",
1615
"node:path",
16+
"node:url",
17+
"node:util",
1718
],
1819
});

package-lock.json

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

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"scripts": {
3333
"vscode:prepublish": "npm run build",
3434
"build": "node esbuild.mjs",
35-
"package": "npx vsce package",
35+
"package": "npx @vscode/vsce package",
3636
"lint": "biome ci ./src",
3737
"pretest": "tsc --project tsconfig.test.json",
3838
"test": "npm run pretest && node ./out/test/run-test.js"
@@ -45,10 +45,10 @@
4545
"@types/sinonjs__fake-timers": "8.1.5",
4646
"@types/vscode": "1.91.0",
4747
"@vscode/test-electron": "2.4.1",
48-
"esbuild": "0.23.0",
49-
"mocha": "10.6.0",
48+
"esbuild": "0.23.1",
49+
"mocha": "10.7.3",
5050
"sinon": "18.0.0",
51-
"typescript": "5.5.3"
51+
"typescript": "5.5.4"
5252
},
5353
"homepage": "https://github.com/Sertion/vscode-gitblame/blob/main/README.md",
5454
"bugs": {

src/git/blame.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export class Blamer {
3838
return;
3939
}
4040

41-
let resolve: (blame: Promise<Blame | undefined>) => void = () => {};
41+
let resolve: (blame: Promise<Blame | undefined> | undefined) => void =
42+
() => {};
4243
this.files.set(
4344
fileName,
4445
new Promise<Blame | undefined>((res) => {
@@ -49,15 +50,27 @@ export class Blamer {
4950
const { file, gitRoot } = await this.create(fileName);
5051

5152
if (file === undefined) {
52-
resolve(Promise.resolve(undefined));
53+
resolve(undefined);
5354
return;
5455
}
5556

57+
Logger.debug("Setting up file watcher for '%s'", file.fileName);
58+
5659
this.fsWatchers.set(
5760
file.fileName,
58-
watch(file.fileName, () => {
59-
this.remove(file.fileName);
60-
}),
61+
watch(
62+
file.fileName,
63+
{
64+
persistent: false,
65+
},
66+
() => {
67+
Logger.debug(
68+
"File watcher callback for '%s' executed",
69+
file.fileName,
70+
);
71+
this.remove(file.fileName);
72+
},
73+
),
6174
);
6275

6376
const blame = this.blameQueue.add(() => file.getBlame());
@@ -95,6 +108,7 @@ export class Blamer {
95108
this.files.delete(fileName);
96109
this.fsWatchers.get(fileName)?.close();
97110
this.fsWatchers.delete(fileName);
111+
Logger.debug("Cache for '%s' cleared. File watcher closed.", fileName);
98112
}
99113

100114
public dispose(): void {

src/git/file.ts

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export class File {
3535

3636
const commitRegistry: CommitRegistry = new Map();
3737
for await (const chunk of this.process?.stdout ?? []) {
38+
Logger.debug(
39+
"Got chunk from '%s' git blame process. Size: %d",
40+
realFileName,
41+
chunk.length,
42+
);
3843
yield* processChunk(chunk, commitRegistry);
3944
}
4045
for await (const error of this.process?.stderr ?? []) {
@@ -50,6 +55,12 @@ export class File {
5055

5156
try {
5257
for await (const lineAttachedCommit of this.run(realpathFileName)) {
58+
Logger.trace(
59+
"Found blame information for %s:%d: hash:%s",
60+
realpathFileName,
61+
lineAttachedCommit.line.result,
62+
lineAttachedCommit.commit.hash,
63+
);
5364
blameInfo.set(lineAttachedCommit.line.result, lineAttachedCommit);
5465
}
5566
} catch (err) {

src/git/head-watch.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type FSWatcher, watch } from "node:fs";
22
import { join, resolve } from "node:path";
3+
import { Logger } from "../util/logger.js";
34
import { getGitFolder } from "./util/git-command.js";
45

56
export type HeadChangeEvent = {
@@ -34,22 +35,32 @@ export class HeadWatch {
3435
}
3536

3637
const repositoryRoot = resolve(gitRoot, "..");
38+
const HEADFile = join(gitRoot, "HEAD");
3739

3840
this.heads.set(
3941
gitRoot,
4042
watch(
41-
join(gitRoot, "HEAD"),
43+
HEADFile,
4244
{
4345
persistent: false,
4446
},
45-
() => this.callback({ gitRoot, repositoryRoot }),
47+
() => {
48+
Logger.debug("File watcher callback for '%s' called.", HEADFile);
49+
this.callback({ gitRoot, repositoryRoot });
50+
},
4651
),
4752
);
53+
54+
Logger.debug("File watcher for '%s' created.", HEADFile);
4855
}
4956

5057
public dispose(): void {
51-
for (const [, headWatcher] of this.heads) {
58+
for (const [gitRoot, headWatcher] of this.heads) {
5259
headWatcher.close();
60+
Logger.debug(
61+
"File watcher for HEAD file in git root '%s' closed.",
62+
gitRoot,
63+
);
5364
}
5465
this.heads.clear();
5566
this.filesWithFoundHeads.clear();

src/git/queue.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Logger } from "../util/logger";
2+
13
export class Queue<
24
ReturnValue = void,
35
QueueFunction extends () => Promise<ReturnValue> = () => Promise<ReturnValue>,
@@ -17,6 +19,10 @@ export class Queue<
1719
if (this.processing.size < this.maxParallel) {
1820
this.startFunction(toQueue);
1921
} else {
22+
Logger.debug(
23+
"Already running %s in parallel. Adding execution to queue.",
24+
this.maxParallel,
25+
);
2026
this.list.push(toQueue);
2127
}
2228
});

src/util/logger.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { format } from "node:util";
12
import { type LogOutputChannel, window } from "vscode";
23

34
export class Logger {
@@ -25,6 +26,14 @@ export class Logger {
2526
Logger.getInstance().out.info(info);
2627
}
2728

29+
public static debug(debug: string, ...args: (string | number)[]): void {
30+
Logger.getInstance().out.debug(format(debug, ...args));
31+
}
32+
33+
public static trace(debug: string, ...args: (string | number)[]): void {
34+
Logger.getInstance().out.trace(format(debug, ...args));
35+
}
36+
2837
public dispose(): void {
2938
Logger.instance = undefined;
3039
this.out.dispose();

src/view.ts

+20-19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { Commit } from "./git/util/stream-parsing.js";
1414

1515
import { isUncommitted } from "./git/util/is-hash.js";
1616
import { getActiveTextEditor } from "./util/get-active.js";
17+
import { Logger } from "./util/logger.js";
1718
import { getProperty } from "./util/property.js";
1819
import {
1920
toInlineTextView,
@@ -107,25 +108,25 @@ export class StatusBarView {
107108
}
108109

109110
private command(): string {
110-
const action = getProperty("statusBarMessageClickAction");
111-
112-
if (action === "Open tool URL") {
113-
return "gitblame.online";
114-
}
115-
if (action === "Open git show") {
116-
return "gitblame.gitShow";
117-
}
118-
if (action === "Copy hash to clipboard") {
119-
return "gitblame.addCommitHashToClipboard";
120-
}
121-
122-
return "gitblame.quickInfo";
111+
return {
112+
"Open tool URL": "gitblame.online",
113+
"Open git show": "gitblame.gitShow",
114+
"Copy hash to clipboard": "gitblame.addCommitHashToClipboard",
115+
"Show info message": "gitblame.quickInfo",
116+
}[getProperty("statusBarMessageClickAction")];
123117
}
124118

125119
private updateStatusBar(statusBar: StatusBarItem) {
126120
statusBar.text = this.statusBarText;
127121
statusBar.tooltip = this.statusBarTooltip;
128122
statusBar.command = this.statusBarCommand ? this.command() : undefined;
123+
124+
Logger.debug(
125+
"Updating status bar item with: Text:'%s', tooltip:'git blame%s', command:%s",
126+
statusBar.text,
127+
statusBar.tooltip,
128+
statusBar.command ?? "",
129+
);
129130
}
130131

131132
private text(text: string, command: boolean, tooltip = ""): void {
@@ -160,15 +161,15 @@ export class StatusBarView {
160161
if (!getProperty("inlineMessageEnabled")) {
161162
return;
162163
}
163-
const margin = getProperty("inlineMessageMargin");
164-
const decorationPosition = new Position(
165-
editor.selection.active.line,
166-
Number.MAX_SAFE_INTEGER,
167-
);
168164

169165
this.removeLineDecoration();
170166
// Add new decoration
171167
if (useDelay && (await this.delayUpdate(getProperty("delayBlame")))) {
168+
const margin = getProperty("inlineMessageMargin");
169+
const decorationPosition = new Position(
170+
editor.selection.active.line,
171+
Number.MAX_SAFE_INTEGER,
172+
);
172173
editor.setDecorations?.(this.decorationType, [
173174
{
174175
renderOptions: {
@@ -192,8 +193,8 @@ export class StatusBarView {
192193
public preUpdate(
193194
textEditor: PartialTextEditor | undefined,
194195
): textEditor is PartialTextEditor {
195-
this.clear();
196196
if (!validEditor(textEditor)) {
197+
this.clear();
197198
return false;
198199
}
199200
for (const rejects of this.ongoingViewUpdateRejects) {

0 commit comments

Comments
 (0)