@@ -76,6 +76,15 @@ export interface ClientStateChangedEvent {
76
76
state : ClientState ;
77
77
}
78
78
79
+ interface DiscoverInfoResult {
80
+ robot_version_string ?: string ;
81
+ python_version_string ?: string ;
82
+ machine ?: string ;
83
+ platform ?: string ;
84
+ system ?: string ;
85
+ system_version ?: string ;
86
+ [ key : string ] : string | undefined ;
87
+ }
79
88
export class LanguageClientsManager {
80
89
private clientsMutex = new Mutex ( ) ;
81
90
@@ -84,8 +93,10 @@ export class LanguageClientsManager {
84
93
85
94
private _disposables : vscode . Disposable ;
86
95
private _pythonValidPythonAndRobotEnv = new WeakMap < vscode . WorkspaceFolder , boolean > ( ) ;
96
+ private _workspaceFolderDiscoverInfo = new WeakMap < vscode . WorkspaceFolder , DiscoverInfoResult > ( ) ;
87
97
88
98
private readonly _onClientStateChangedEmitter = new vscode . EventEmitter < ClientStateChangedEvent > ( ) ;
99
+ private readonly statusBarItem : vscode . StatusBarItem ;
89
100
90
101
public get onClientStateChanged ( ) : vscode . Event < ClientStateChangedEvent > {
91
102
return this . _onClientStateChangedEmitter . event ;
@@ -106,8 +117,13 @@ export class LanguageClientsManager {
106
117
fileWatcher1 . onDidDelete ( ( uri ) => this . restart ( vscode . workspace . getWorkspaceFolder ( uri ) ?. uri ) ) ;
107
118
fileWatcher1 . onDidChange ( ( uri ) => this . restart ( vscode . workspace . getWorkspaceFolder ( uri ) ?. uri ) ) ;
108
119
120
+ this . statusBarItem = vscode . window . createStatusBarItem ( "robotCodeInfo" , vscode . StatusBarAlignment . Right , 0 ) ;
121
+ this . statusBarItem . text = "RobotCode" ;
122
+
109
123
this . _disposables = vscode . Disposable . from (
110
124
fileWatcher1 ,
125
+ this . statusBarItem ,
126
+ vscode . window . onDidChangeActiveTextEditor ( async ( editor ) => this . updateStatusbarItem ( editor ) ) ,
111
127
this . pythonManager . pythonExtension ?. exports . settings . onDidChangeExecutionDetails ( async ( uri ) => {
112
128
if ( uri !== undefined ) {
113
129
const folder = vscode . workspace . getWorkspaceFolder ( uri ) ;
@@ -133,6 +149,9 @@ export class LanguageClientsManager {
133
149
await this . restart ( ) ;
134
150
} ) ,
135
151
) ;
152
+ setTimeout ( ( ) => {
153
+ this . updateStatusbarItem ( vscode . window . activeTextEditor ) . then ( undefined , undefined ) ;
154
+ } , 1000 ) ;
136
155
}
137
156
138
157
public async clearCaches ( ) : Promise < void > {
@@ -516,6 +535,7 @@ export class LanguageClientsManager {
516
535
517
536
public async restart ( uri ?: vscode . Uri ) : Promise < void > {
518
537
this . _pythonValidPythonAndRobotEnv = new WeakMap < vscode . WorkspaceFolder , boolean > ( ) ;
538
+ this . _workspaceFolderDiscoverInfo = new WeakMap < vscode . WorkspaceFolder , DiscoverInfoResult > ( ) ;
519
539
await this . refresh ( uri , true ) ;
520
540
}
521
541
@@ -580,6 +600,8 @@ export class LanguageClientsManager {
580
600
// do noting
581
601
}
582
602
}
603
+
604
+ await this . updateStatusbarItem ( vscode . window . activeTextEditor ) ;
583
605
}
584
606
585
607
public async openUriInDocumentationView ( uri : vscode . Uri ) : Promise < void > {
@@ -681,4 +703,41 @@ export class LanguageClientsManager {
681
703
} ) ) ?? [ ]
682
704
) ;
683
705
}
706
+
707
+ private async updateStatusbarItem ( editor : vscode . TextEditor | undefined ) {
708
+ if ( editor && SUPPORTED_LANGUAGES . includes ( editor . document . languageId ) ) {
709
+ try {
710
+ const folder = vscode . workspace . getWorkspaceFolder ( editor . document . uri ) ;
711
+ if ( folder ) {
712
+ if ( ! this . _workspaceFolderDiscoverInfo . has ( folder ) ) {
713
+ this . _workspaceFolderDiscoverInfo . set (
714
+ folder ,
715
+ ( await this . pythonManager . executeRobotCode ( folder , [ "discover" , "info" ] ) ) as DiscoverInfoResult ,
716
+ ) ;
717
+ }
718
+ const info = this . _workspaceFolderDiscoverInfo . get ( folder ) ;
719
+ if ( info ?. robot_version_string ) {
720
+ this . statusBarItem . text = "$(robotcode-robot) " + info . robot_version_string ;
721
+ this . statusBarItem . tooltip = new vscode . MarkdownString (
722
+ `
723
+ - **Robot Framework**: ${ info . robot_version_string }
724
+ - **Python**: ${ info . python_version_string }
725
+ - **Platform**: ${ info . platform }
726
+ - **Machine**: ${ info . machine }
727
+ - **System**: ${ info . system }
728
+ - **System Version**: ${ info . system_version }
729
+ ` ,
730
+ true ,
731
+ ) ;
732
+
733
+ this . statusBarItem . show ( ) ;
734
+ return ;
735
+ }
736
+ }
737
+ } catch {
738
+ // do nothing
739
+ }
740
+ }
741
+ this . statusBarItem . hide ( ) ;
742
+ }
684
743
}
0 commit comments