Skip to content

Commit 47a4f58

Browse files
authored
Merge pull request #1 from nexus-uw/sub-to-more-events
subscribe to more events + implement gtm requested recording filter
2 parents c68dc24 + d784c14 commit 47a4f58

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ From [git-time-metric/gtm](https://github.com/git-time-metric/gtm)
1010
>GTM is automatic, seamless and lightweight. There is no need to remember to start and stop timers. It's a process that only runs on occasion to capture edit events triggered by the editor. It does not require a background process or any file system monitoring.
1111
>Your time metrics are stored locally with the repository as Git notes. If you want to share your data, it can be pushed and fetched to and from the remote repository. Other GTM users on your team can do the same. This provides you the ability to see time metrics for the entire team.
1212
## Features
13-
- auto updates gtm everytime a file is saved
13+
- auto updates gtm everytime a file is saved + changed
1414

1515
## Requirements
1616

@@ -27,10 +27,15 @@ only tested on Ubuntu, so may not work on OSX, other Linuxs, and/or Windows
2727

2828
## Release Notes
2929

30+
### 0.0.2
31+
32+
Improved reporting logic to factor in changing current text file
33+
3034
### 0.0.1
3135

3236
Initial release of vscode-gtm
3337

3438

39+
3540
### Notes
3641
Logo belongs to https://github.com/git-time-metric/gtm

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-gtm",
33
"displayName": "vscode-gtm",
44
"description": "VSCode plugin to support Git Time Metrics",
5-
"version": "0.0.1",
5+
"version": "0.0.2",
66
"publisher": "s3ramsay",
77
"license": "MIT",
88
"engines": {

src/extension.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function run_cmd(cmd, args, callBack) {
77
var resp = "";
88
child.on('error', function (code) { console.error('error', resp); callBack(code) });
99
child.stdout.on('data', function (buffer) { resp += buffer.toString() });
10-
child.on('close', function (code) { callBack(code) });
10+
child.on('close', function (code) {console.log(resp) ;callBack(code) });
1111
}
1212

1313
export function activate(context: vscode.ExtensionContext) {
@@ -19,10 +19,29 @@ export function activate(context: vscode.ExtensionContext) {
1919
});
2020
let subscriptions: vscode.Disposable[] = [];
2121

22-
// report time every time a file is saved
23-
vscode.workspace.onDidSaveTextDocument((e: vscode.TextDocument) => {
24-
run_cmd('gtm', ['record', e.fileName], (res) => console.log(res));
25-
}, this, subscriptions);
22+
23+
let lastUpdated: Date = new Date();
24+
let lastSavedFileName: string;
25+
const MIN_UPDATE_FREQUENCE_MS = 30000; // 30 seconds
26+
27+
function handleUpdateEvent(fileName: string){
28+
const now = new Date();
29+
// if a new file is being saved OR it have been at least MIN_UPDATE_FREQUENCE_MS, record it
30+
if (fileName !== lastSavedFileName || (now.getTime() - lastUpdated.getTime()) >= MIN_UPDATE_FREQUENCE_MS) {
31+
run_cmd('gtm', ['record', lastSavedFileName], () => { });
32+
lastSavedFileName = fileName;
33+
lastUpdated = now;
34+
}
35+
}
36+
37+
// report to gtm everytime a file is saved
38+
vscode.workspace.onDidSaveTextDocument((e: vscode.TextDocument) => handleUpdateEvent(e.fileName), this, subscriptions);
39+
40+
// report to gtm everytime the user's selection of text changes
41+
vscode.window.onDidChangeTextEditorSelection((e:vscode.TextEditorSelectionChangeEvent) => handleUpdateEvent(e.textEditor.document.fileName), this, subscriptions);
42+
43+
// report to gtm everytime the user switches textEditors
44+
vscode.window.onDidChangeActiveTextEditor((e:vscode.TextEditor) => handleUpdateEvent(e.document.fileName), this, subscriptions);
2645
}
2746

2847
// always active, so no need to deactivate

0 commit comments

Comments
 (0)