Skip to content

Commit

Permalink
handle mesage through the chatapi
Browse files Browse the repository at this point in the history
  • Loading branch information
dimacodota committed Dec 5, 2023
1 parent 800e779 commit 58f42ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/tabnineChatWidget/ChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
getCapabilities,
} from "../binary/requests/requests";
import { sendEvent } from "../binary/requests/sendEvent";
import { chatEventRegistry } from "./chatEventRegistry";
import { InserCode, insertTextAtCursor } from "./handlers/insertAtCursor";
import { resolveSymbols } from "./handlers/resolveSymbols";
import { peekDefinition } from "./handlers/peekDefinition";
Expand All @@ -31,6 +30,7 @@ import {
navigateToLocation,
} from "./handlers/navigateToLocation";
import { getWorkspaceRootPaths } from "../utils/workspaceFolders";
import { EventRegistry } from "./EventRegistry";

type GetUserResponse = {
token: string;
Expand Down Expand Up @@ -99,6 +99,8 @@ type APIConfig = {
export class ChatAPI {
private ready = new vscode.EventEmitter<void>();

private chatEventRegistry = new EventRegistry();

public onReady = new Promise((resolve) => {
this.ready.event(resolve);
});
Expand All @@ -116,7 +118,7 @@ export class ChatAPI {
);
}

chatEventRegistry
this.chatEventRegistry
.registerEvent<void, InitResponse>("init", async () => {
this.ready.fire();
return Promise.resolve({
Expand Down Expand Up @@ -253,4 +255,11 @@ export class ChatAPI {
}
);
}

async handleEvent<Req, Res>(
event: string,
requestPayload: Req
): Promise<Res> {
return this.chatEventRegistry.handleEvent(event, requestPayload);
}
}
3 changes: 1 addition & 2 deletions src/tabnineChatWidget/ChatViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as path from "path";
import * as fs from "fs";
import axios from "axios";
import { ExtensionContext, WebviewView, WebviewViewProvider } from "vscode";
import { chatEventRegistry } from "./chatEventRegistry";
import { ChatAPI } from "./ChatApi";
import { Logger } from "../utils/logger";
import { fireEvent } from "../binary/requests/requests";
Expand Down Expand Up @@ -40,7 +39,7 @@ export default class ChatViewProvider implements WebviewViewProvider {
this.chatWebview.onDidReceiveMessage(
async (message: RequestMessage) => {
try {
const payload = await chatEventRegistry.handleEvent(
const payload = await this.chatApi.handleEvent(
message.command,
message.data
);
Expand Down
5 changes: 0 additions & 5 deletions src/tabnineChatWidget/chatEventRegistry.ts

This file was deleted.

0 comments on commit 58f42ae

Please sign in to comment.