Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV2-3410 use welcome views #1259

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"--extensionDevelopmentPath=${workspaceRoot}",
"--logPluginHostCommunication",
],

"sourceMaps": true,
"preLaunchTask": "npm: build"
},
Expand Down
40 changes: 26 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,45 @@
}
},
"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": [
{
"id": "tabnine-access",
"title": "Tabnine AI Assistant",
"id": "tabnine",
"title": "Tabnine AI",
"icon": "small_logo.png"
}
]
},
"viewsWelcome": [
{
"view": "tabnine.loading",
"contents": "Loading please wait..."
}
],
"views": {
"tabnine-access": [
"tabnine": [
{
"type": "webview",
"id": "tabnine.chat",
"name": "Chat",
"when": "tabnine.chat.ready"
"when": "tabnine.authenticated && tabnine.chat.ready"
},
{
"id": "tabnine.chat.welcome",
"type": "webview",
"name": "Welcome to Chat",
"when": "tabnine.authenticated && !tabnine.chat.ready"
},
{
"id": "tabnine.authenticate",
"type": "webview",
"name": "Please log in",
"when": "!tabnine.authenticated && tabnine.process.ready && tabnine.capabilities.ready"
},
{
"id": "tabnine.empty",
"name": "Welcome to Tabnine Chat",
"when": "!tabnine.chat.ready"
"id": "tabnine.loading",
"name": "Loading",
"when": "!tabnine.process.ready || !tabnine.capabilities.ready"
}
]
},
Expand Down Expand Up @@ -435,4 +447,4 @@
"publisherId": "1924b661-7c19-45d9-9800-edeb32848fd7",
"isPreReleaseVersion": false
}
}
}
6 changes: 6 additions & 0 deletions src/authentication/TabnineAuthenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AuthenticationProvider,
AuthenticationProviderAuthenticationSessionsChangeEvent,
AuthenticationSession,
commands,
Disposable,
Event,
EventEmitter,
Expand Down Expand Up @@ -112,6 +113,11 @@ export default class TabnineAuthenticationProvider
if (newState?.is_logged_in) {
this.onDidLogin.emit(LOGIN_HAPPENED_EVENT, newState);
}
await commands.executeCommand(
"setContext",
"tabnine.authenticated",
newState?.is_logged_in
);

if (!oldState?.is_logged_in && newState?.is_logged_in) {
added.push((await this.getSessions())[0]);
Expand Down
9 changes: 5 additions & 4 deletions src/binary/Binary.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as child_process from "child_process";
import { Disposable, EventEmitter } from "vscode";
import { Disposable, EventEmitter, commands } from "vscode";
import { Mutex } from "await-semaphore";
import { once } from "events";
import BinaryRequester from "./InnerBinary";
Expand Down Expand Up @@ -148,9 +148,10 @@ export default class Binary {
void this.restartChild();
});

void waitForRejection(once(this.proc, "exit"), 200).then(() =>
this.ready.fire()
);
void waitForRejection(once(this.proc, "exit"), 200).then(() => {
void commands.executeCommand("setContext", "tabnine.process.ready", true);
this.ready.fire();
});

this.innerBinary.init(proc, readLine);
this.isRestarting = false;
Expand Down
12 changes: 12 additions & 0 deletions src/binary/requests/refreshRemote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { tabNineProcess } from "./requests";

export type RefreshResponse = {
is_successful: boolean;
error?: string;
};

export function refreshRemote(): Promise<RefreshResponse | null | undefined> {
return tabNineProcess.request<RefreshResponse>({
RefreshRemoteProperties: {},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ofekby - this is the usage of the RefreshRemoteProperties reuest

});
}
7 changes: 6 additions & 1 deletion src/capabilities/capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { Disposable, EventEmitter } from "vscode";
import { Disposable, EventEmitter, commands } from "vscode";
import {
ExperimentSource,
getCapabilities,
Expand Down Expand Up @@ -112,6 +112,11 @@ async function refreshCapabilities(): Promise<void> {
capabilities.experiment_source === ExperimentSource.APIErrorResponse)
) {
isReady = true;
await commands.executeCommand(
"setContext",
"tabnine.capabilities.ready",
true
);
}

enabledCapabilities = theseCapabilties;
Expand Down
6 changes: 6 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import { installationState } from "./events/installationStateChangedEmitter";
import { statePoller } from "./state/statePoller";
import { Logger } from "./utils/logger";
import { callForLogin } from "./authentication/authentication.api";
import { emptyStateWelcomeView } from "./tabnineChatWidget/webviews/emptyStateWelcomeView";
import { emptyStateAuthenticateView } from "./tabnineChatWidget/webviews/emptyStateAuthenticateView";

export async function activate(
context: vscode.ExtensionContext
Expand Down Expand Up @@ -120,6 +122,10 @@ async function backgroundInit(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("tabnine.authenticate", () => {
void callForLogin();
});
context.subscriptions.push(
emptyStateWelcomeView(context),
emptyStateAuthenticateView(context)
);
registerTestGenCodeLens(context);

if (context.extensionMode !== vscode.ExtensionMode.Test) {
Expand Down
4 changes: 1 addition & 3 deletions src/tabnineChatWidget/ChatViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ export default class ChatViewProvider implements WebviewViewProvider {
}

focusWebviewInput() {
void vscode.commands.executeCommand(
"workbench.view.extension.tabnine-access"
);
void vscode.commands.executeCommand("workbench.view.extension.tabnine");
void this.chatWebviewView?.show(true);
void this.chatWebview?.postMessage({
command: "focus-input",
Expand Down
17 changes: 17 additions & 0 deletions src/tabnineChatWidget/webviews/authenticate.html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { WELCOME_MESSAGE } from "./welcome.html";

const SIGN_IN_BUTTON = `<a style="display: inline-block; background-color: #007acc; color: #fff; border: none; padding: 6px 40%; border-radius: 3px; cursor: pointer; text-decoration: none;" href="command:tabnine.authenticate">Sign in</a>`;

export const html = `<!DOCTYPE html>
<html>
<body>
${WELCOME_MESSAGE}
<p>

Please ensure you’re signed in
<div style="text-align: center;">
${SIGN_IN_BUTTON}
</div>
</p>
</body>
</html>`;
30 changes: 30 additions & 0 deletions src/tabnineChatWidget/webviews/emptyStateAuthenticateView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Disposable, ExtensionContext, Uri, WebviewView, window } from "vscode";
import { fireEvent } from "../../binary/requests/requests";
import { html } from "./authenticate.html";

export function emptyStateAuthenticateView(
context: ExtensionContext
): Disposable {
return window.registerWebviewViewProvider("tabnine.authenticate", {
resolveWebviewView(webviewView: WebviewView) {
webviewView.onDidChangeVisibility(() => {
if (webviewView.visible) {
void fireEvent({
name: "tabnine-chat-authenticate-visible",
});
}
});

const view = webviewView.webview;
view.options = {
enableScripts: true,
enableCommandUris: true,
};
view.html = html;

void fireEvent({
name: "tabnine-chat-authenticate-inited",
});
},
});
}
25 changes: 25 additions & 0 deletions src/tabnineChatWidget/webviews/emptyStateWelcomeView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Disposable, ExtensionContext, Uri, WebviewView, window } from "vscode";
import { fireEvent } from "../../binary/requests/requests";
import { refreshRemote } from "../../binary/requests/refreshRemote";
import { html } from "./welcome.html";

export function emptyStateWelcomeView(context: ExtensionContext): Disposable {
return window.registerWebviewViewProvider("tabnine.chat.welcome", {
resolveWebviewView(webviewView: WebviewView) {
webviewView.onDidChangeVisibility(() => {
if (webviewView.visible) {
void refreshRemote();
void fireEvent({
name: "tabnine-chat-empty-visible",
});
}
});
void fireEvent({
name: "tabnine-chat-empty-inited",
});

const view = webviewView.webview;
view.html = html;
},
});
}
13 changes: 13 additions & 0 deletions src/tabnineChatWidget/webviews/welcome.html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const WELCOME_MESSAGE = `
<h1>Welcome to Tabnine Chat</h1>
<h2>Tabnine Chat is currently in Beta</h2>
<p>We understand that waiting for this awesome feature isn’t easy, but we guarantee it will be worth it.
Tabnine Chat will soon be available to all users, and we'll make sure to keep you informed. Thank you for your patience!
<a href="https://www.tabnine.com/#ChatSection">Learn More</a></p>`;

export const html = `<!DOCTYPE html>
<html>
<body>
${WELCOME_MESSAGE}
</body>
</html>`;