Skip to content

Commit

Permalink
DEV2-3410 init the chat on capabilities change (#1246)
Browse files Browse the repository at this point in the history
* DEV2-3410 init the chat on capabilities change

* set default view

* use welcome state
  • Loading branch information
dimacodota authored Aug 10, 2023
1 parent dec5079 commit a2733e7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 92 deletions.
24 changes: 9 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@
}
},
"contributes": {
"viewsWelcome": [
{
"view": "tabnine.empty",
"contents": "Tabnine Chat is currently in Beta\n\nWe understand that waiting for this awesome feature isn’t easy, but we guarantee it will be worth it. \n\nTabnine Chat will soon be available to all users, and we'll make sure to keep you informed. \n\nThank you for your patience! [Learn More](https://www.tabnine.com/#ChatSection)\nReceived Tabnine Chat beta access? Please ensure you’re signed in \n[Sign in](command:tabnine.authenticate)"
}
],
"viewsContainers": {
"activitybar": [
{
Expand All @@ -203,21 +209,9 @@
"when": "tabnine.chat.ready"
},
{
"type": "webview",
"id": "tabnine-today",
"name": "Tabnine Today",
"when": "!tabnine.chat.ready && tabnine.tabnine-today-ready"
},
{
"id": "tabnine-home",
"name": "Quick Access",
"when": "!tabnine.chat.ready && tabnine.tabnine-navigation-ready"
},
{
"type": "webview",
"id": "tabnine-notifications",
"name": "Notifications",
"when": "!tabnine.chat.ready && tabnine.notifications-ready"
"id": "tabnine.empty",
"name": "Welcome to Tabnine Chat",
"when": "!tabnine.chat.ready"
}
]
},
Expand Down
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { setTabnineExtensionContext } from "./globals/tabnineExtensionContext";
import { updatePersistedAlphaVersion } from "./preRelease/versions";
import isCloudEnv from "./cloudEnvs/isCloudEnv";
import setupCloudState from "./cloudEnvs/setupCloudState";
import registerTreeView from "./treeView/registerTreeView";
import { closeAssistant } from "./assistant/requests/request";
import initAssistant from "./assistant/AssistantClient";
import TabnineAuthenticationProvider from "./authentication/TabnineAuthenticationProvider";
Expand All @@ -53,6 +52,7 @@ import { forceRegistrationIfNeeded } from "./registration/forceRegistration";
import { installationState } from "./events/installationStateChangedEmitter";
import { statePoller } from "./state/statePoller";
import { Logger } from "./utils/logger";
import { callForLogin } from "./authentication/authentication.api";

export async function activate(
context: vscode.ExtensionContext
Expand Down Expand Up @@ -117,6 +117,9 @@ async function backgroundInit(context: vscode.ExtensionContext) {
clearSessionPreference: true,
});
}
vscode.commands.registerCommand("tabnine.authenticate", () => {
void callForLogin();
});
registerTestGenCodeLens(context);

if (context.extensionMode !== vscode.ExtensionMode.Test) {
Expand All @@ -132,7 +135,6 @@ async function backgroundInit(context: vscode.ExtensionContext) {
}

registerTabnineChatWidgetWebview(context);
registerTreeView(context);
pollNotifications(context);
pollStatuses(context);
setDefaultStatus();
Expand Down
59 changes: 39 additions & 20 deletions src/tabnineChatWidget/tabnineChatWidgetWebview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as vscode from "vscode";
import { ExtensionContext } from "vscode";
import ChatViewProvider from "./ChatViewProvider";
import { Capability, isCapabilityEnabled } from "../capabilities/capabilities";
import {
Capability,
isCapabilityEnabled,
onDidRefreshCapabilities,
} from "../capabilities/capabilities";
import { getState } from "../binary/requests/requests";
import { Logger } from "../utils/logger";

Expand All @@ -11,27 +15,42 @@ export default function registerTabnineChatWidgetWebview(
context: ExtensionContext,
serverUrl?: string
): void {
if (
typeof serverUrl === "string" || // we are in self hosted, and server url is configured
const isChatEnabled = getIsEnabled();

if (typeof serverUrl === "string" || isChatEnabled) {
registerChatView(serverUrl, context);
} else {
const disposable = onDidRefreshCapabilities(() => {
if (getIsEnabled()) {
registerChatView(serverUrl, context);
disposable.dispose();
}
});
}
}

function getIsEnabled() {
return (
isCapabilityEnabled(Capability.ALPHA_CAPABILITY) ||
isCapabilityEnabled(Capability.TABNINE_CHAT)
) {
registerWebview(context, serverUrl);
void vscode.commands.executeCommand(
"setContext",
"tabnine.chat.ready",
true
);
getState()
.then((state) => {
void vscode.commands.executeCommand(
"setContext",
"tabnine.chat.settings-ready",
state?.service_level !== "Business"
);
})
.catch((e) => Logger.error(`Failed to get the user state ${e}`));
}
);
}

function registerChatView(
serverUrl: string | undefined,
context: vscode.ExtensionContext
) {
registerWebview(context, serverUrl);
void vscode.commands.executeCommand("setContext", "tabnine.chat.ready", true);
getState()
.then((state) => {
void vscode.commands.executeCommand(
"setContext",
"tabnine.chat.settings-ready",
state?.service_level !== "Business"
);
})
.catch((e) => Logger.error(`Failed to get the user state ${e}`));
}

function registerWebview(context: ExtensionContext, serverUrl?: string): void {
Expand Down
55 changes: 0 additions & 55 deletions src/treeView/registerTreeView.ts

This file was deleted.

0 comments on commit a2733e7

Please sign in to comment.