Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
"@types/semver": "5.5.0",
"tslint": "5.16.0",
"typescript": "3.3.3333",
"vscode": "1.1.33"
"vscode": "1.1.33",
"elegant-spinner": "2.0.0"
},
"dependencies": {
"jmespath": "0.15.0",
Expand Down
45 changes: 45 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { HoverProvider, Hover, SnippetString, StatusBarAlignment, StatusBarItem,
import { AzService, CompletionKind, Arguments, Status } from './azService';
import { parse, findNode } from './parser';
import { exec } from './utils';
import * as spinner from 'elegant-spinner';

export function activate(context: ExtensionContext) {
const azService = new AzService(azNotFound);
Expand Down Expand Up @@ -152,15 +153,43 @@ class RunLineInEditor {
private queryEnabled = false;
private query: string | undefined;
private disposables: Disposable[] = [];
private commandRunningStatusBarItem: StatusBarItem;
private statusBarUpdateInterval!: NodeJS.Timer;
private statusBarSpinner = spinner();
private hideStatusBarItemTimeout! : NodeJS.Timeout;
private statusBarItemText : string = '';

constructor(private status: StatusBarInfo) {
this.disposables.push(commands.registerTextEditorCommand('ms-azurecli.toggleLiveQuery', editor => this.toggleQuery(editor)));
this.disposables.push(commands.registerTextEditorCommand('ms-azurecli.runLineInEditor', editor => this.run(editor)));
this.disposables.push(workspace.onDidCloseTextDocument(document => this.close(document)));
this.disposables.push(workspace.onDidChangeTextDocument(event => this.change(event)));

this.commandRunningStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
this.disposables.push(this.commandRunningStatusBarItem);
}

private runningCommandCount : number = 0;
private run(source: TextEditor) {
this.runningCommandCount += 1;
const t0 = Date.now();
if (this.runningCommandCount == 1)
{
this.statusBarItemText = `Azure CLI: Waiting for response`;
this.statusBarUpdateInterval = setInterval(() => {
if (this.runningCommandCount == 1)
{
this.commandRunningStatusBarItem.text = `${this.statusBarItemText} ${this.statusBarSpinner()}`;
}
else
{
this.commandRunningStatusBarItem.text = `${this.statusBarItemText} [${this.runningCommandCount}] ${this.statusBarSpinner()}`;
}
}, 50);
}
this.commandRunningStatusBarItem.show();
clearTimeout(this.hideStatusBarItemTimeout);

this.parsedResult = undefined;
this.query = undefined; // TODO
const cursor = source.selection.active;
Expand All @@ -174,10 +203,26 @@ class RunLineInEditor {
.then(() => this.parsedResult = JSON.parse(content))
.then(undefined, err => {})
)
.then(() => this.commandFinished(t0))
)
.then(undefined, console.error);
}

private commandFinished(startTime: number)
{
this.runningCommandCount -= 1
this.statusBarItemText = 'Azure CLI: Executed in ' + (Date.now() - startTime) + ' milliseconds';
this.commandRunningStatusBarItem.text = this.statusBarItemText;

if (this.runningCommandCount == 0)
{
clearInterval(this.statusBarUpdateInterval);

// hide status bar item after 10 seconds to keep status bar uncluttered
this.hideStatusBarItemTimeout = setTimeout(() => this.commandRunningStatusBarItem.hide(), 10000);
}
}

private toggleQuery(source: TextEditor) {
this.queryEnabled = !this.queryEnabled;
this.status.liveQuery = this.queryEnabled;
Expand Down