Skip to content

Commit

Permalink
Activate extension when running MySQL query
Browse files Browse the repository at this point in the history
  • Loading branch information
formulahendry committed Nov 26, 2017
1 parent 7680493 commit 31523aa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.0.3 (2017-11-26)
* Activate extension when running MySQL query

## 0.0.2 (2017-11-24)
* Better output format: display output as table
* [#2](https://github.com/formulahendry/vscode-mysql/issues/2): Add option to set maximum table count, and increase the dafault count
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-mysql",
"displayName": "MySQL",
"description": "MySQL management tool",
"version": "0.0.2",
"version": "0.0.3",
"publisher": "formulahendry",
"icon": "logo.png",
"engines": {
Expand All @@ -29,7 +29,8 @@
},
"activationEvents": [
"onView:mysql",
"onCommand:mysql.addConnection"
"onCommand:mysql.addConnection",
"onCommand:mysql.runQuery"
],
"main": "./out/extension",
"contributes": {
Expand Down
26 changes: 23 additions & 3 deletions src/common/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ export class Utility {
});
}

public static runQuery(sql?: string, connectionOptions?: IConnection) {
public static async runQuery(sql?: string, connectionOptions?: IConnection) {
AppInsightsClient.sendEvent("runQuery.start");
if (!sql && !vscode.window.activeTextEditor) {
vscode.window.showWarningMessage("No SQL file selected");
AppInsightsClient.sendEvent("runQuery.noFile");
return;
}
if (!connectionOptions && !Global.activeConnection) {
vscode.window.showWarningMessage("No MySQL Server or Database selected");
return;
const hasActiveConnection = await Utility.hasActiveConnection();
if (!hasActiveConnection) {
vscode.window.showWarningMessage("No MySQL Server or Database selected");
AppInsightsClient.sendEvent("runQuery.noMySQL");
return;
}
}

sql = sql ? sql : vscode.window.activeTextEditor.document.getText();
Expand Down Expand Up @@ -64,4 +69,19 @@ export class Utility {
const textDocument = await vscode.workspace.openTextDocument({ content: sql, language: "sql" });
return vscode.window.showTextDocument(textDocument);
}

private static async hasActiveConnection(): Promise<boolean> {
let count = 5;
while (!Global.activeConnection && count > 0) {
await Utility.sleep(100);
count--;
}
return !!Global.activeConnection;
}

private static sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
}

0 comments on commit 31523aa

Please sign in to comment.