Skip to content

Commit 5e548eb

Browse files
author
James Pogran
authored
Merge pull request #393 from glennsarti/redo-puppet-loading
(GH-399) Update status bar loading UI
2 parents ed2d96e + 5809893 commit 5e548eb

File tree

7 files changed

+55
-34
lines changed

7 files changed

+55
-34
lines changed

src/PuppetLanguageClient.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ export class PuppetLanguageClient {
4242
this.languageServerClient.onReady().then(
4343
() => {
4444
logger.debug('Language server client started, setting puppet version');
45-
this.setConnectionStatus('Loading Puppet', ConnectionStatus.Starting);
45+
this.setConnectionStatus('Loading Puppet', ConnectionStatus.Starting, '');
4646
this.queryLanguageServerStatus();
4747
},
4848
reason => {
49-
this.setConnectionStatus('Starting Error', ConnectionStatus.Failed);
49+
this.setConnectionStatus('Starting Error', ConnectionStatus.Failed, '');
5050
}
5151
);
5252

5353
}
5454

55-
public setConnectionStatus(statusText: string, status: ConnectionStatus): void {
55+
public setConnectionStatus(statusText: string, status: ConnectionStatus, toolTip: string): void {
5656
this.connectionStatus = status;
5757
this.connectionManager.status = status;
58-
this.statusBarItem.setConnectionStatus(statusText, status);
58+
this.statusBarItem.setConnectionStatus(statusText, status, toolTip);
5959
}
6060

6161
private queryLanguageServerStatus() {
@@ -69,7 +69,7 @@ export class PuppetLanguageClient {
6969
// After 30 seonds timeout the progress
7070
if (count >= 30 || this.languageServerClient === undefined) {
7171
clearInterval(handle);
72-
this.setConnectionStatus(lastVersionResponse.puppetVersion, ConnectionStatus.Running);
72+
this.setConnectionStatus(lastVersionResponse.puppetVersion, ConnectionStatus.RunningLoaded, '');
7373
resolve();
7474
return;
7575
}
@@ -83,19 +83,17 @@ export class PuppetLanguageClient {
8383
versionDetails.classesLoaded
8484
) {
8585
clearInterval(handle);
86-
this.setConnectionStatus(lastVersionResponse.puppetVersion, ConnectionStatus.Running);
86+
this.setConnectionStatus(lastVersionResponse.puppetVersion, ConnectionStatus.RunningLoaded, '');
8787
resolve();
8888
} else {
89-
let progress = 0;
89+
let toolTip: string = "";
9090

91-
if (versionDetails.factsLoaded) { progress++; }
92-
if (versionDetails.functionsLoaded) { progress++; }
93-
if (versionDetails.typesLoaded) { progress++; }
94-
if (versionDetails.classesLoaded) { progress++; }
91+
toolTip += (versionDetails.classesLoaded ? "✔ Classes: Loaded\n" : "⏳ Classes: Loading...\n");
92+
toolTip += (versionDetails.factsLoaded ? "✔ Facts: Loaded\n" : "⏳ Facts: Loading...\n");
93+
toolTip += (versionDetails.functionsLoaded ? "✔ Functions: Loaded\n" : "⏳ Functions: Loading...\n");
94+
toolTip += (versionDetails.typesLoaded ? "✔ Types: Loaded" : "⏳ Types: Loading...");
9595

96-
progress = Math.round(progress / 4.0 * 100);
97-
98-
this.setConnectionStatus('Loading Puppet (' + progress.toString() + '%)', ConnectionStatus.Starting);
96+
this.setConnectionStatus(lastVersionResponse.puppetVersion, ConnectionStatus.RunningLoading, toolTip);
9997
}
10098
});
10199

src/PuppetStatusBar.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,43 @@ export class PuppetStatusBar {
2525
});
2626
}
2727

28-
public setConnectionStatus(statusText: string, status: ConnectionStatus): void {
28+
public setConnectionStatus(statusText: string, status: ConnectionStatus, toolTip: string): void {
2929
this.logger.debug(`Setting status bar to ${statusText}`);
30-
// Set color and icon for 'Running' by default
31-
var statusIconText = '$(terminal) ';
32-
var statusColor = '#affc74';
30+
// Icons are from https://octicons.github.com/
31+
var statusIconText: string;
32+
var statusColor: string;
3333

34-
if (status === ConnectionStatus.Starting) {
35-
statusIconText = '$(sync) ';
36-
statusColor = '#f3fc74';
37-
} else if (status === ConnectionStatus.Failed) {
38-
statusIconText = '$(alert) ';
39-
statusColor = '#fcc174';
34+
switch (status) {
35+
case ConnectionStatus.RunningLoaded:
36+
statusIconText = '$(terminal) ';
37+
statusColor = '#affc74';
38+
break;
39+
case ConnectionStatus.RunningLoading:
40+
// When the editor service is starting, it's functional but it may be missing
41+
// type/class/function/fact info. But language only features like format document
42+
// or document symbol, are available
43+
statusIconText = '$(sync~spin) ';
44+
statusColor = '#affc74';
45+
break;
46+
case ConnectionStatus.Failed:
47+
statusIconText = '$(alert) ';
48+
statusColor = '#fcc174';
49+
break;
50+
default:
51+
// ConnectionStatus.NotStarted
52+
// ConnectionStatus.Starting
53+
// ConnectionStatus.Stopping
54+
statusIconText = '$(gear) ';
55+
statusColor = '#f3fc74';
56+
break;
4057
}
4158

59+
statusIconText = (statusIconText + statusText).trim();
4260
this.statusBarItem.color = statusColor;
43-
this.statusBarItem.text = statusIconText + statusText;
61+
// Using a conditional here because resetting a $(sync~spin) will cause the animation to restart. Instead
62+
// Only change the status bar text if it has actually changed.
63+
if (this.statusBarItem.text !== statusIconText) { this.statusBarItem.text = statusIconText; }
64+
this.statusBarItem.tooltip = toolTip; // TODO: killme (new Date()).getUTCDate().toString() + "\nNewline\nWee!";
4465
}
4566

4667
public static showConnectionMenu() {

src/connection.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class ConnectionManager implements IConnectionManager {
6969
// Setup the configuration
7070
this.connectionConfiguration = connectionConfig;
7171

72-
this.setConnectionStatus('Starting Puppet...', ConnectionStatus.Starting);
72+
this.setConnectionStatus('Starting Puppet...', ConnectionStatus.Starting, '');
7373

7474
if (this.connectionConfiguration.type === ConnectionType.Local) {
7575
this.createLanguageServerProcess(
@@ -246,7 +246,8 @@ export class ConnectionManager implements IConnectionManager {
246246
logger.error(`[Puppet Lang Server Client] ` + `Could not start language client: ${err.message}`);
247247
connectionManager.setConnectionStatus(
248248
`Could not start language client: ${err.message}`,
249-
ConnectionStatus.Failed
249+
ConnectionStatus.Failed,
250+
''
250251
);
251252

252253
vscode.window.showErrorMessage(
@@ -346,12 +347,12 @@ export class ConnectionManager implements IConnectionManager {
346347
this.start(connectionConfig);
347348
}
348349

349-
private setConnectionStatus(statusText: string, status: ConnectionStatus): void {
350+
private setConnectionStatus(statusText: string, status: ConnectionStatus, toolTip: string): void {
350351
this.connectionStatus = status;
351-
this.statusBarItem.setConnectionStatus(statusText, status);
352+
this.statusBarItem.setConnectionStatus(statusText, status, toolTip);
352353
}
353354

354355
private setSessionFailure(message: string, ...additionalMessages: string[]) {
355-
this.setConnectionStatus('Starting Error', ConnectionStatus.Failed);
356+
this.setConnectionStatus('Starting Error', ConnectionStatus.Failed, '');
356357
}
357358
}

src/feature/FormatDocumentFeature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FormatDocumentProvider {
2121
}
2222

2323
public async formatTextEdits(document: vscode.TextDocument, options: vscode.FormattingOptions): Promise<vscode.TextEdit[]> {
24-
if (this.connectionManager.status !== ConnectionStatus.Running) {
24+
if ((this.connectionManager.status !== ConnectionStatus.RunningLoaded) && (this.connectionManager.status !== ConnectionStatus.RunningLoading)) {
2525
vscode.window.showInformationMessage("Please wait and try again. The Puppet extension is still loading...");
2626
return [];
2727
}

src/feature/NodeGraphFeature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class NodeGraphContentProvider implements vscode.TextDocumentContentProvider {
3232
source: sourceUri.toString()
3333
};
3434

35-
if ((this.connectionManager.status !== ConnectionStatus.Running) && (this.connectionManager.status !== ConnectionStatus.Starting)) {
35+
if ((this.connectionManager.status !== ConnectionStatus.RunningLoaded) && (this.connectionManager.status !== ConnectionStatus.RunningLoading)) {
3636
if (this.shownLanguageServerNotAvailable) {
3737
vscode.window.showInformationMessage("The Puppet Node Graph Preview is not available as the Editor Service is not ready");
3838
this.shownLanguageServerNotAvailable = true;

src/feature/PuppetResourceFeature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class PuppetResourceFeature implements IFeature {
2626
public run() {
2727
var thisCommand = this;
2828

29-
if (thisCommand._connectionManager.status !== ConnectionStatus.Running) {
29+
if (thisCommand._connectionManager.status !== ConnectionStatus.RunningLoaded) {
3030
vscode.window.showInformationMessage('Puppet Resource is not available as the Language Server is not ready');
3131
return;
3232
}

src/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
export enum ConnectionStatus {
66
NotStarted,
77
Starting,
8-
Running,
8+
RunningLoading,
9+
RunningLoaded,
910
Stopping,
1011
Failed
1112
}

0 commit comments

Comments
 (0)