Skip to content

Commit 1ff174a

Browse files
committed
feat(vscode): added a statusbar item that shows some information about the current robot environment, like version, python version, etc.
1 parent a6f0488 commit 1ff174a

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

icons/robot.woff

1.48 KB
Binary file not shown.

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@
7474
},
7575
"main": "./out/extension.js",
7676
"contributes": {
77+
"icons": {
78+
"robotcode-robot": {
79+
"description": "RobotFramework Icon",
80+
"default": {
81+
"fontPath": "./icons/robot.woff",
82+
"fontCharacter": "\\E900"
83+
}
84+
}
85+
},
7786
"tomlValidation": [
7887
{
7988
"fileMatch": "robot.toml",

vscode-client/languageclientsmanger.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ export interface ClientStateChangedEvent {
7676
state: ClientState;
7777
}
7878

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+
}
7988
export class LanguageClientsManager {
8089
private clientsMutex = new Mutex();
8190

@@ -84,8 +93,10 @@ export class LanguageClientsManager {
8493

8594
private _disposables: vscode.Disposable;
8695
private _pythonValidPythonAndRobotEnv = new WeakMap<vscode.WorkspaceFolder, boolean>();
96+
private _workspaceFolderDiscoverInfo = new WeakMap<vscode.WorkspaceFolder, DiscoverInfoResult>();
8797

8898
private readonly _onClientStateChangedEmitter = new vscode.EventEmitter<ClientStateChangedEvent>();
99+
private readonly statusBarItem: vscode.StatusBarItem;
89100

90101
public get onClientStateChanged(): vscode.Event<ClientStateChangedEvent> {
91102
return this._onClientStateChangedEmitter.event;
@@ -106,8 +117,13 @@ export class LanguageClientsManager {
106117
fileWatcher1.onDidDelete((uri) => this.restart(vscode.workspace.getWorkspaceFolder(uri)?.uri));
107118
fileWatcher1.onDidChange((uri) => this.restart(vscode.workspace.getWorkspaceFolder(uri)?.uri));
108119

120+
this.statusBarItem = vscode.window.createStatusBarItem("robotCodeInfo", vscode.StatusBarAlignment.Right, 0);
121+
this.statusBarItem.text = "RobotCode";
122+
109123
this._disposables = vscode.Disposable.from(
110124
fileWatcher1,
125+
this.statusBarItem,
126+
vscode.window.onDidChangeActiveTextEditor(async (editor) => this.updateStatusbarItem(editor)),
111127
this.pythonManager.pythonExtension?.exports.settings.onDidChangeExecutionDetails(async (uri) => {
112128
if (uri !== undefined) {
113129
const folder = vscode.workspace.getWorkspaceFolder(uri);
@@ -133,6 +149,9 @@ export class LanguageClientsManager {
133149
await this.restart();
134150
}),
135151
);
152+
setTimeout(() => {
153+
this.updateStatusbarItem(vscode.window.activeTextEditor).then(undefined, undefined);
154+
}, 1000);
136155
}
137156

138157
public async clearCaches(): Promise<void> {
@@ -516,6 +535,7 @@ export class LanguageClientsManager {
516535

517536
public async restart(uri?: vscode.Uri): Promise<void> {
518537
this._pythonValidPythonAndRobotEnv = new WeakMap<vscode.WorkspaceFolder, boolean>();
538+
this._workspaceFolderDiscoverInfo = new WeakMap<vscode.WorkspaceFolder, DiscoverInfoResult>();
519539
await this.refresh(uri, true);
520540
}
521541

@@ -580,6 +600,8 @@ export class LanguageClientsManager {
580600
// do noting
581601
}
582602
}
603+
604+
await this.updateStatusbarItem(vscode.window.activeTextEditor);
583605
}
584606

585607
public async openUriInDocumentationView(uri: vscode.Uri): Promise<void> {
@@ -681,4 +703,41 @@ export class LanguageClientsManager {
681703
})) ?? []
682704
);
683705
}
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+
}
684743
}

0 commit comments

Comments
 (0)