Skip to content

Commit cf681bb

Browse files
committed
#494 Logging Enhancements: transform empty args, and logging command invocations.
1 parent e44a48b commit cf681bb

4 files changed

Lines changed: 111 additions & 17 deletions

File tree

src/commands.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ export class CommandManager extends Disposable {
7878
*/
7979
private registerCommand(command: string, callback: (...args: any[]) => any) {
8080
this.registerDisposable(
81-
vscode.commands.registerCommand(command, callback)
81+
vscode.commands.registerCommand(command, (...args: any[]) => {
82+
this.logger.log('Command Invoked: ' + command);
83+
callback(...args);
84+
})
8285
);
8386
}
8487

src/logger.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as vscode from 'vscode';
22
import { Disposable } from './utils/disposable';
33

4+
const DOUBLE_QUOTE_REGEXP = /"/g;
5+
46
/**
57
* Manages the Git Graph Logger, which writes log information to the Git Graph Output Channel.
68
*/
@@ -32,11 +34,14 @@ export class Logger extends Disposable {
3234
* @param args The arguments passed to the command.
3335
*/
3436
public logCmd(cmd: string, args: string[]) {
35-
this.log('> ' + cmd + ' ' + args.map((arg) => {
36-
return arg.startsWith('--format=')
37+
this.log('> ' + cmd + ' ' + args.map((arg) => arg === ''
38+
? '""'
39+
: arg.startsWith('--format=')
3740
? '--format=...'
38-
: arg.includes(' ') ? '"' + arg.replace(/"/g, '\\"') + '"' : arg;
39-
}).join(' '));
41+
: arg.includes(' ')
42+
? '"' + arg.replace(DOUBLE_QUOTE_REGEXP, '\\"') + '"'
43+
: arg
44+
).join(' '));
4045
}
4146

4247
/**

0 commit comments

Comments
 (0)