Skip to content

Commit a55b2e1

Browse files
author
Calvinn Ng
committed
update protocols based on previous changes
1 parent 7a8af76 commit a55b2e1

File tree

3 files changed

+90
-11
lines changed

3 files changed

+90
-11
lines changed

extensions/vscode/src/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as vscode from "vscode";
66
import { IDE, ContinueSDK } from "core";
77
import { AutocompleteOutcome } from "core/autocomplete/completionProvider";
88
import { ConfigHandler } from "core/config/handler";
9+
import { fetchwithRequestOptions } from "core/util/fetchWithOptions";
910
import { logDevData } from "core/util/devdata";
1011
import { Telemetry } from "core/util/posthog";
1112
import { ContinueGUIWebviewViewProvider } from "./debugPanel";
@@ -276,6 +277,8 @@ const commandsMap: (
276277
llm,
277278
fullInput: text || "",
278279
selectedCode: [],
280+
fetch: (url, init) =>
281+
fetchwithRequestOptions(url, init, config.requestOptions),
279282
});
280283
}) || [],
281284
)

extensions/vscode/src/ideProtocol.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as child_process from "child_process";
22
import { exec } from "child_process";
33
import {
44
ContinueRcJson,
5+
FileType,
56
IDE,
67
IdeInfo,
78
IndexTag,
@@ -10,6 +11,7 @@ import {
1011
Thread,
1112
} from "core";
1213
import { getContinueGlobalPath } from "core/util/paths";
14+
import { defaultIgnoreFile } from "core/indexing/ignore";
1315
import * as path from "path";
1416
import * as vscode from "vscode";
1517
import { DiffManager } from "./diff/horizontal";
@@ -28,6 +30,22 @@ class VsCodeIde implements IDE {
2830
this.ideUtils = new VsCodeIdeUtils();
2931
}
3032

33+
private authToken: string | undefined;
34+
private askedForAuth = false;
35+
36+
async getGitHubAuthToken(): Promise<string | undefined> {
37+
console.log("Reading Github Auth Token is not supported.")
38+
return undefined;
39+
}
40+
41+
async infoPopup(message: string): Promise<void> {
42+
vscode.window.showInformationMessage(message);
43+
}
44+
45+
async errorPopup(message: string): Promise<void> {
46+
vscode.window.showErrorMessage(message);
47+
}
48+
3149
async getRepoName(dir: string): Promise<string | undefined> {
3250
const repo = await this.getRepo(vscode.Uri.file(dir));
3351
const remote =
@@ -79,6 +97,18 @@ class VsCodeIde implements IDE {
7997
);
8098
}
8199

100+
async getLastModified(files: string[]): Promise<{ [path: string]: number }> {
101+
const pathToLastModified: { [path: string]: number } = {};
102+
await Promise.all(
103+
files.map(async (file) => {
104+
const stat = await vscode.workspace.fs.stat(uriFromFilePath(file));
105+
pathToLastModified[file] = stat.mtime;
106+
}),
107+
);
108+
109+
return pathToLastModified;
110+
}
111+
82112
async getStats(directory: string): Promise<{ [path: string]: number }> {
83113
const scheme = vscode.workspace.workspaceFolders?.[0].uri.scheme;
84114
const files = await this.listWorkspaceContents(directory);
@@ -255,6 +285,10 @@ class VsCodeIde implements IDE {
255285
return await this.ideUtils.getOpenFiles();
256286
}
257287

288+
async getCurrentFile(): Promise<string | undefined> {
289+
return vscode.window.activeTextEditor?.document.uri.fsPath;
290+
}
291+
258292
async getPinnedFiles(): Promise<string[]> {
259293
const tabArray = vscode.window.tabGroups.all[0].tabs;
260294

@@ -342,6 +376,19 @@ class VsCodeIde implements IDE {
342376
async getBranch(dir: string): Promise<string> {
343377
return this.ideUtils.getBranch(vscode.Uri.file(dir));
344378
}
379+
380+
getGitRootPath(dir: string): Promise<string | undefined> {
381+
return this.ideUtils.getGitRoot(dir);
382+
}
383+
384+
async listDir(dir: string): Promise<[string, FileType][]> {
385+
const files = await vscode.workspace.fs.readDirectory(uriFromFilePath(dir));
386+
return files
387+
.filter(([name, type]) => {
388+
!(type === vscode.FileType.File && defaultIgnoreFile.ignores(name));
389+
})
390+
.map(([name, type]) => [path.join(dir, name), type]) as any;
391+
}
345392
}
346393

347394
export { VsCodeIde };

extensions/vscode/src/webviewProtocol.ts

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { ContextItemId, IDE } from "core";
22
import { ConfigHandler } from "core/config/handler";
3+
import { fetchwithRequestOptions } from "core/util/fetchWithOptions";
34
import {
45
setupLocalMode,
56
setupOptimizedExistingUserMode,
67
setupOptimizedMode,
78
} from "core/config/onboarding";
9+
import { SiteIndexingConfig } from "core"
810
import { addModel, addOpenAIKey, deleteModel } from "core/config/util";
911
import { indexDocs } from "core/indexing/docs";
1012
import TransformersJsEmbeddingsProvider from "core/indexing/embeddings/TransformersJsEmbeddingsProvider";
@@ -379,7 +381,14 @@ export class VsCodeWebviewProtocol {
379381
while (!next.done) {
380382
if (protocol.abortedMessageIds.has(msg.messageId)) {
381383
protocol.abortedMessageIds.delete(msg.messageId);
382-
next = await gen.return({ completion: "", prompt: "" });
384+
next = await gen.return({
385+
completion: "",
386+
prompt: "",
387+
completionOptions: {
388+
...msg.data.completionOptions,
389+
model: model.model,
390+
},
391+
});
383392
break;
384393
}
385394
yield { content: next.value };
@@ -403,7 +412,14 @@ export class VsCodeWebviewProtocol {
403412
while (!next.done) {
404413
if (protocol.abortedMessageIds.has(msg.messageId)) {
405414
protocol.abortedMessageIds.delete(msg.messageId);
406-
next = await gen.return({ completion: "", prompt: "" });
415+
next = await gen.return({
416+
completion: "",
417+
prompt: "",
418+
completionOptions: {
419+
...msg.data.completionOptions,
420+
model: model.model,
421+
},
422+
});
407423
break;
408424
}
409425
yield { content: next.value.content };
@@ -465,6 +481,8 @@ export class VsCodeWebviewProtocol {
465481
},
466482
selectedCode,
467483
config,
484+
fetch: (url, init) =>
485+
fetchwithRequestOptions(url, init, config.requestOptions),
468486
})) {
469487
if (content) {
470488
yield { content };
@@ -490,7 +508,11 @@ export class VsCodeWebviewProtocol {
490508
}
491509

492510
try {
493-
const items = await provider.loadSubmenuItems({ ide });
511+
const items = await provider.loadSubmenuItems({
512+
ide: this.ide,
513+
fetch: (url, init) =>
514+
fetchwithRequestOptions(url, init, config.requestOptions)
515+
});
494516
return items;
495517
} catch (e) {
496518
vscode.window.showErrorMessage(
@@ -526,8 +548,10 @@ export class VsCodeWebviewProtocol {
526548
embeddingsProvider: config.embeddingsProvider,
527549
reranker: config.reranker,
528550
fullInput,
529-
ide,
551+
ide,
530552
selectedCode,
553+
fetch: (url, init) =>
554+
fetchwithRequestOptions(url, init, config.requestOptions),
531555
});
532556

533557
Telemetry.capture("useContextProvider", {
@@ -542,20 +566,25 @@ export class VsCodeWebviewProtocol {
542566
return [];
543567
}
544568
});
569+
545570
this.on("context/addDocs", (msg) => {
546-
const { url, title } = msg.data;
547-
const embeddingsProvider = new TransformersJsEmbeddingsProvider();
571+
const siteIndexingConfig: SiteIndexingConfig = {
572+
startUrl: msg.data.startUrl,
573+
rootUrl: msg.data.rootUrl,
574+
title: msg.data.title,
575+
maxDepth: msg.data.maxDepth,
576+
};
577+
548578
vscode.window.withProgress(
549579
{
550580
location: vscode.ProgressLocation.Notification,
551-
title: `Indexing ${title}`,
581+
title: `Indexing ${msg.data.title}`,
552582
cancellable: false,
553583
},
554584
async (progress) => {
555585
for await (const update of indexDocs(
556-
title,
557-
new URL(url),
558-
embeddingsProvider,
586+
siteIndexingConfig,
587+
new TransformersJsEmbeddingsProvider(),
559588
)) {
560589
progress.report({
561590
increment: update.progress,
@@ -564,7 +593,7 @@ export class VsCodeWebviewProtocol {
564593
}
565594

566595
vscode.window.showInformationMessage(
567-
`🎉 Successfully indexed ${title}`,
596+
`🎉 Successfully indexed ${msg.data.title}`,
568597
);
569598

570599
this.request("refreshSubmenuItems", undefined);

0 commit comments

Comments
 (0)