Skip to content

Commit

Permalink
two webviews
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed Oct 19, 2024
1 parent 027d438 commit 8888ccb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
10 changes: 10 additions & 0 deletions extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
}
},
"commands": [
{
"command": "pearai.switchWebview",
"title": "PearAI: Switch Chat View"
},
{
"command": "pearai.acceptDiff",
"category": "PearAI",
Expand Down Expand Up @@ -530,6 +534,12 @@
"id": "pearai.continueGUIView",
"name": "",
"visibility": "visible"
},
{
"type": "webview",
"id": "pearai.continueGUIView2",
"name": "Chat 2",
"visibility": "visible"
}
]
},
Expand Down
3 changes: 3 additions & 0 deletions extensions/vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ const commandsMap: (
extensionContext.subscriptions,
);
},
"pearai.switchWebview": () => {
vscode.commands.executeCommand("pearai.internal.switchWebview");
},
"pearai.openConfigJson": () => {
ide.openFile(getConfigJsonPath());
},
Expand Down
41 changes: 40 additions & 1 deletion extensions/vscode/src/extension/VsCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export class VsCodeExtension {
private ide: VsCodeIde;
private tabAutocompleteModel: TabAutocompleteModel;
private sidebar: ContinueGUIWebviewViewProvider;
private windowId: string;
private sidebar2: ContinueGUIWebviewViewProvider;
private activeWebview: 'sidebar' | 'sidebar2' = 'sidebar'; private windowId: string;
private diffManager: DiffManager;
private verticalDiffManager: VerticalPerLineDiffManager;
webviewProtocolPromise: Promise<VsCodeWebviewProtocol>;
Expand Down Expand Up @@ -95,6 +96,29 @@ export class VsCodeExtension {
);
resolveWebviewProtocol(this.sidebar.webviewProtocol);

this.sidebar2 = new ContinueGUIWebviewViewProvider(
configHandlerPromise,
this.windowId + "_2",
this.extensionContext,
);

// Register second sidebar
context.subscriptions.push(
vscode.window.registerWebviewViewProvider(
"pearai.continueGUIView2",
this.sidebar2,
{
webviewOptions: { retainContextWhenHidden: true },
},
),
);

context.subscriptions.push(
vscode.commands.registerCommand("pearai.internal.switchWebview", () => {
this.switchWebview();
})
);

// Config Handler with output channel
const outputChannel = vscode.window.createOutputChannel(
"PearAI",
Expand Down Expand Up @@ -372,6 +396,21 @@ export class VsCodeExtension {

static continueVirtualDocumentScheme = "pearai";

public switchWebview() {
this.activeWebview = this.activeWebview === 'sidebar' ? 'sidebar2' : 'sidebar';
const activeProvider = this.activeWebview === 'sidebar' ? this.sidebar : this.sidebar2;

this.webviewProtocolPromise.then(protocol => {
if (activeProvider.webview) {
protocol.webview = activeProvider.webview;
}
});
// Refresh the webview content
activeProvider.webviewProtocol?.request("didChangeAvailableProfiles", { profiles: [] });

vscode.commands.executeCommand(`pearai.continueGUIView${this.activeWebview === 'sidebar' ? '' : '2'}.focus`);
}

// eslint-disable-next-line @typescript-eslint/naming-convention
private PREVIOUS_BRANCH_FOR_WORKSPACE_DIR: { [dir: string]: string } = {};

Expand Down

0 comments on commit 8888ccb

Please sign in to comment.