Skip to content

Commit

Permalink
Enable Plugin Install Flow (#369)
Browse files Browse the repository at this point in the history
* Implement notifications

* Implement auto install flow

* hasKiteConfig -> hasKiteRun

* Send launchCopilot and channel opts

* Remove jsconfig.json

* Minor tweaks

* Remove this.showCopilot

* Update kite-api to 3.2.0 and kite-connector to 3.14.0
  • Loading branch information
edzkite authored Jan 27, 2021
1 parent 4a7f71a commit 45fca23
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 39 deletions.
12 changes: 0 additions & 12 deletions jsconfig.json

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@
"install-local": "vsce package && code --install-extension kite-*.vsix && rm kite-*.vsix"
},
"dependencies": {
"kite-api": "=3.19.0",
"kite-connector": "=3.12.0",
"kite-api": "=3.20.0",
"kite-connector": "=3.14.0",
"md5": "^2.2.0",
"mixpanel": "^0.5.0",
"open": "^7.3.0",
Expand Down
36 changes: 29 additions & 7 deletions src/kite.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export const Kite = {
vscode.workspace.getConfiguration("kite").loggingLevel.toUpperCase()
];

KiteAPI
.isKiteInstalled()
.catch(NotificationsManager.showKiteInstallNotification);

this.setMaxFileSize();

this.disposables.push(
Expand Down Expand Up @@ -427,6 +423,7 @@ export const Kite = {
this.shown = {};
this.disposables = [];
this.attemptedToStartKite = false;
this.installing = false;
this.notifications = new NotificationsManager();
delete this.lastState;
delete this.lastStatus;
Expand Down Expand Up @@ -522,12 +519,32 @@ export const Kite = {
return state;
}
this.shown[state] = true;
if (KiteAPI.hasKiteRun()) {
NotificationsManager.showKiteInstallNotification();
} else {
NotificationsManager.showKiteDownloadingNotification();
this.installing = true;
KiteAPI.downloadKiteRelease({
install: true,
launchCopilot: true,
channel: 'vscode',
onRemove: () => { this.installing = false; },
})
.catch(e => {
console.error(e);
NotificationsManager.showKiteInstallErrorNotification();
});
}
break;
case KiteAPI.STATES.INSTALLED:
if (
!this.attemptedToStartKite &&
vscode.workspace.getConfiguration("kite").startKiteEngineOnStartup
) {
if (this.installing) {
// Guard against running Kite before installation fully completes.
break;
}
KiteAPI.runKiteAndWait(RUN_KITE_ATTEMPTS, RUN_KITE_INTERVAL).then(() => this.checkState(src));
this.attemptedToStartKite = true;
}
Expand Down Expand Up @@ -586,14 +603,19 @@ export const Kite = {
this.statusBarItem.show();
switch (state) {
case KiteAPI.STATES.UNSUPPORTED:
this.statusBarItem.text = "𝕜𝕚𝕥𝕖: not supported";
this.statusBarItem.tooltip =
"Kite engine is currently not supported on your platform";
this.statusBarItem.color = ERROR_COLOR();
this.statusBarItem.text = "𝕜𝕚𝕥𝕖: not supported";
break;
case KiteAPI.STATES.UNINSTALLED:
this.statusBarItem.text = "𝕜𝕚𝕥𝕖: not installed";
this.statusBarItem.tooltip = "Kite engine is not installed";
if (this.installing) {
this.statusBarItem.text = "𝕜𝕚𝕥𝕖: installing components";
this.statusBarItem.tooltip = "Installing components. Kite will launch automatically when ready.";
} else {
this.statusBarItem.text = "𝕜𝕚𝕥𝕖: not installed";
this.statusBarItem.tooltip = "Kite engine is not installed";
}
this.statusBarItem.color = ERROR_COLOR();
break;
case KiteAPI.STATES.INSTALLED:
Expand Down
69 changes: 51 additions & 18 deletions src/notifications.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import vscode from "vscode";
import open from "open";
import path from "path";

import metrics from "./metrics";

Expand Down Expand Up @@ -78,22 +77,56 @@ export default class NotificationsManager {
.then(hasDone => !hasDone && openKiteTutorial('python'));
}

static showKiteInstallNotification(err) {
if (typeof err.data !== 'undefined' && err.data.state === KiteAPI.STATES.UNINSTALLED) {
metrics.track("vscode_kite_installer_notification_shown");
vscode.window
.showInformationMessage(
"Kite requires the Kite Engine backend to provide completions and documentation. Please install it to use Kite.",
"Install"
)
.then(item => {
switch (item) {
case "Install":
open("https://www.kite.com/install/?utm_medium=editor&utm_source=vscode");
metrics.track("vscode_kite_installer_github_link_clicked");
break;
}
});
}
static showKiteInstallNotification() {
metrics.track("vscode_kite_installer_notification_shown");
vscode.window
.showInformationMessage(
"Kite requires the Kite Engine backend to provide completions and documentation. Please install it to use Kite.",
"Install"
)
.then(item => {
switch (item) {
case "Install":
open("https://www.kite.com/install/?utm_medium=editor&utm_source=vscode");
metrics.track("vscode_kite_installer_github_link_clicked");
break;
}
});
}

static showKiteDownloadingNotification() {
metrics.track("vscode_kite_downloading_notification_shown");
vscode.window
.showInformationMessage(
"Kite ships with a standalone application called the Copilot that can show you documentation while you code. The Copilot will launch automatically after Kite is finished installing.",
"OK",
"Learn More"
)
.then(item => {
switch (item) {
case "OK":
break;
case "Learn More":
open("https://www.kite.com/copilot/");
break;
}
});
}

static showKiteInstallErrorNotification() {
metrics.track("vscode_kite_downloading_failed_notification_shown");
vscode.window
.showErrorMessage(
"There was an error installing the Kite Engine, which is required for Kite to provide completions and documentation. Please install it to use Kite.",
"Install"
)
.then(item => {
switch (item) {
case "Install":
open("https://www.kite.com/install/?utm_medium=editor&utm_source=vscode");
metrics.track("vscode_kite_installer_github_link_clicked");
break;
}
});
}
}

0 comments on commit 45fca23

Please sign in to comment.