@@ -7,6 +7,7 @@ import * as vscode from 'vscode';
7
7
import {
8
8
AI_RECENT_PASTES_TIME_MS ,
9
9
COMMAND_DASHBOARD ,
10
+ Heartbeat ,
10
11
LogLevel ,
11
12
SEND_BUFFER_SECONDS ,
12
13
} from './constants' ;
@@ -26,19 +27,6 @@ interface FileSelectionMap {
26
27
[ key : string ] : FileSelection ;
27
28
}
28
29
29
- interface Heartbeat {
30
- time : number ;
31
- entity : string ;
32
- is_write : boolean ;
33
- lineno : number ;
34
- cursorpos : number ;
35
- lines_in_file : number ;
36
- alternate_project ?: string ;
37
- project_folder ?: string ;
38
- category ?: 'debugging' | 'ai coding' | 'building' | 'code reviewing' ;
39
- is_unsaved_entity ?: boolean ;
40
- }
41
-
42
30
export class WakaTime {
43
31
private agentName : string ;
44
32
private extension : any ;
@@ -544,45 +532,45 @@ export class WakaTime {
544
532
if ( Date . now ( ) - this . lastSent > SEND_BUFFER_SECONDS * 1000 ) {
545
533
this . sendHeartbeats ( ) ;
546
534
}
547
-
548
535
clearTimeout ( this . debounceTimeoutId ) ;
549
536
this . debounceTimeoutId = setTimeout ( ( ) => {
550
537
if ( this . disabled ) return ;
551
- let editor = vscode . window . activeTextEditor ;
538
+ const editor = vscode . window . activeTextEditor ;
552
539
if ( editor ) {
553
- let doc = editor . document ;
540
+ const doc = editor . document ;
554
541
if ( doc ) {
555
- let file : string = doc . fileName ;
556
- if ( file ) {
557
- if ( this . currentlyFocusedFile !== file ) {
558
- this . updateTeamStatusBarFromJson ( ) ;
559
- this . updateTeamStatusBar ( doc ) ;
560
- }
542
+ const file = Utils . getFocusedFile ( doc ) ;
543
+ if ( ! file ) {
544
+ return ;
545
+ }
546
+ if ( this . currentlyFocusedFile !== file ) {
547
+ this . updateTeamStatusBarFromJson ( ) ;
548
+ this . updateTeamStatusBar ( doc ) ;
549
+ }
561
550
562
- let time : number = Date . now ( ) ;
563
- if (
564
- isWrite ||
565
- Utils . enoughTimePassed ( this . lastHeartbeat , time ) ||
566
- this . lastFile !== file ||
567
- this . lastDebug !== this . isDebugging ||
568
- this . lastCompile !== this . isCompiling ||
569
- this . lastAICodeGenerating !== this . isAICodeGenerating
570
- ) {
571
- this . appendHeartbeat (
572
- doc ,
573
- time ,
574
- editor . selection . start ,
575
- isWrite ,
576
- this . isCompiling ,
577
- this . isDebugging ,
578
- this . isAICodeGenerating ,
579
- ) ;
580
- this . lastFile = file ;
581
- this . lastHeartbeat = time ;
582
- this . lastDebug = this . isDebugging ;
583
- this . lastCompile = this . isCompiling ;
584
- this . lastAICodeGenerating = this . isAICodeGenerating ;
585
- }
551
+ const time : number = Date . now ( ) ;
552
+ if (
553
+ isWrite ||
554
+ Utils . enoughTimePassed ( this . lastHeartbeat , time ) ||
555
+ this . lastFile !== file ||
556
+ this . lastDebug !== this . isDebugging ||
557
+ this . lastCompile !== this . isCompiling ||
558
+ this . lastAICodeGenerating !== this . isAICodeGenerating
559
+ ) {
560
+ this . appendHeartbeat (
561
+ doc ,
562
+ time ,
563
+ editor . selection . start ,
564
+ isWrite ,
565
+ this . isCompiling ,
566
+ this . isDebugging ,
567
+ this . isAICodeGenerating ,
568
+ ) ;
569
+ this . lastFile = file ;
570
+ this . lastHeartbeat = time ;
571
+ this . lastDebug = this . isDebugging ;
572
+ this . lastCompile = this . isCompiling ;
573
+ this . lastAICodeGenerating = this . isAICodeGenerating ;
586
574
}
587
575
}
588
576
}
@@ -600,12 +588,8 @@ export class WakaTime {
600
588
) : Promise < void > {
601
589
if ( ! this . dependencies . isCliInstalled ( ) ) return ;
602
590
603
- let file = doc . fileName ;
604
- if ( Utils . isRemoteUri ( doc . uri ) ) {
605
- file = `${ doc . uri . authority } ${ doc . uri . path } ` ;
606
- file = file . replace ( 'ssh-remote+' , 'ssh://' ) ;
607
- // TODO: how to support 'dev-container', 'attached-container', 'wsl', and 'codespaces' schemes?
608
- }
591
+ const file = Utils . getFocusedFile ( doc ) ;
592
+ if ( ! file ) return ;
609
593
610
594
// prevent sending the same heartbeat (https://github.com/wakatime/vscode-wakatime/issues/163)
611
595
if ( isWrite && this . isDuplicateHeartbeat ( file , time , selection ) ) return ;
@@ -905,11 +889,9 @@ export class WakaTime {
905
889
if ( ! doc ) return ;
906
890
}
907
891
908
- let file = doc . fileName ;
909
- if ( Utils . isRemoteUri ( doc . uri ) ) {
910
- file = `${ doc . uri . authority } ${ doc . uri . path } ` ;
911
- file = file . replace ( 'ssh-remote+' , 'ssh://' ) ;
912
- // TODO: how to support 'dev-container', 'attached-container', 'wsl', and 'codespaces' schemes?
892
+ const file = Utils . getFocusedFile ( doc ) ;
893
+ if ( ! file ) {
894
+ return ;
913
895
}
914
896
915
897
this . currentlyFocusedFile = file ;
0 commit comments