added updateSubmenuItems request

This commit is contained in:
commandblock2 2024-03-11 22:26:43 +08:00
parent 3f6f9f202a
commit 4181490794
5 changed files with 101 additions and 55 deletions

View file

@ -1,5 +1,6 @@
import {
ContextItemWithId,
ContextSubmenuItem,
ContinueRcJson,
DiffLine,
Problem,
@ -23,7 +24,7 @@ export type IdeProtocol = {
readFile: [{ filepath: string }, string];
showDiff: [
{ filepath: string; newContents: string; stepIndex: number },
void,
void
];
diffLine: [
{
@ -32,7 +33,7 @@ export type IdeProtocol = {
startLine: number;
endLine: number;
},
void,
void
];
getProblems: [{ filepath: string }, Problem[]];
getBranch: [{ dir: string }, string];
@ -43,8 +44,11 @@ export type IdeProtocol = {
getDiff: [undefined, string];
getWorkspaceConfigs: [undefined, ContinueRcJson[]];
getTerminalContents: [undefined, string];
getDebugLocals: [{threadIndex: Number}, string];
getTopLevelCallStackSources: [{threadIndex: number, stackDepth: number}, string[]];
getDebugLocals: [{ threadIndex: Number }, string];
getTopLevelCallStackSources: [
{ threadIndex: number; stackDepth: number },
string[]
];
getAvailableThreads: [undefined, string[]];
isTelemetryEnabled: [undefined, boolean];
getUniqueId: [undefined, string];
@ -60,7 +64,7 @@ export type WebviewProtocol = Protocol &
workspacePaths: string[];
vscMachineId: string;
vscMediaUrl: string;
},
}
];
errorPopup: [{ message: string }, void];
@ -86,7 +90,11 @@ export type ReverseWebviewProtocol = {
historyIndex: number;
item: ContextItemWithId;
},
void,
void
];
updateSubmenuItems: [
{ provider: string; submenuItems: ContextSubmenuItem[] },
void
];
getDefaultModelTitle: [undefined, string];
newSessionWithPrompt: [{ prompt: string }, void];

View file

@ -1,14 +1,18 @@
import * as vscode from "vscode";
import { VsCodeWebviewProtocol } from "../webviewProtocol";
import { VsCodeIde } from "../ideProtocol";
export const threadStopped: Map<number, boolean> = new Map();
// Arrays has better perf but you probably won't have thousands of threads in a single debug session
export function registerDebugTracker(webviewProtocol: VsCodeWebviewProtocol) {
export function registerDebugTracker(
webviewProtocol: VsCodeWebviewProtocol,
ide: VsCodeIde
) {
vscode.debug.registerDebugAdapterTrackerFactory("*", {
createDebugAdapterTracker(session: vscode.DebugSession) {
return {
onDidSendMessage(message: any) {
async onDidSendMessage(message: any) {
if (message.type == "event") {
switch (message.event) {
case "continued":
@ -29,7 +33,21 @@ export function registerDebugTracker(webviewProtocol: VsCodeWebviewProtocol) {
threadStopped.set(key, false)
);
webviewProtocol?.request("refreshSubmenuItems", undefined);
webviewProtocol?.request("updateSubmenuItems", {
provider: "locals",
submenuItems: (await ide.getAvailableThreads()).map(
(thread, threadIndex) => {
const [threadId, threadName] = thread
.split(",")
.map((str) => str.trimStart());
return {
id: `${threadIndex}`,
title: threadName,
description: threadId,
};
}
),
});
break;
case "thread":
@ -45,7 +63,7 @@ export function registerDebugTracker(webviewProtocol: VsCodeWebviewProtocol) {
break;
}
}
}
},
};
},
});

View file

@ -36,7 +36,7 @@ export class VsCodeExtension {
// Config Handler with output channel
const outputChannel = vscode.window.createOutputChannel(
"Continue - LLM Prompt/Completion",
"Continue - LLM Prompt/Completion"
);
this.configHandler = new ConfigHandler(
this.ide,
@ -45,19 +45,19 @@ export class VsCodeExtension {
: new URL(remoteUrl),
async (log: string) => {
outputChannel.appendLine(
"==========================================================================",
"=========================================================================="
);
outputChannel.appendLine(
"==========================================================================",
"=========================================================================="
);
outputChannel.append(log);
},
() => this.webviewProtocol?.request("configUpdate", undefined),
() => this.webviewProtocol?.request("configUpdate", undefined)
);
this.configHandler.reloadConfig();
this.verticalDiffManager = new VerticalPerLineDiffManager(
this.configHandler,
this.configHandler
);
this.extensionContext = context;
this.tabAutocompleteModel = new TabAutocompleteModel(this.configHandler);
@ -67,11 +67,11 @@ export class VsCodeExtension {
this.ide,
this.windowId,
this.extensionContext,
this.verticalDiffManager,
this.verticalDiffManager
);
try {
const configSync = new RemoteConfigSync(
this.configHandler.reloadConfig.bind(this.configHandler),
this.configHandler.reloadConfig.bind(this.configHandler)
);
configSync.setup();
} catch (e) {
@ -85,14 +85,14 @@ export class VsCodeExtension {
this.sidebar,
{
webviewOptions: { retainContextWhenHidden: true },
},
),
}
)
);
this.webviewProtocol = this.sidebar.webviewProtocol;
// Indexing + pause token
const indexingPauseToken = new PauseToken(
context.globalState.get<boolean>("continue.indexingPaused") === true,
context.globalState.get<boolean>("continue.indexingPaused") === true
);
this.webviewProtocol.on("index/setPaused", (msg) => {
context.globalState.update("continue.indexingPaused", msg.data);
@ -103,14 +103,14 @@ export class VsCodeExtension {
this.indexer = new CodebaseIndexer(
this.configHandler,
this.ide,
indexingPauseToken,
indexingPauseToken
);
// CodeLens
registerAllCodeLensProviders(
context,
this.diffManager,
this.verticalDiffManager.editorToVerticalDiffCodeLens,
this.verticalDiffManager.editorToVerticalDiffCodeLens
);
// Tab autocomplete
@ -125,9 +125,9 @@ export class VsCodeExtension {
new ContinueCompletionProvider(
this.configHandler,
this.ide,
this.tabAutocompleteModel,
),
),
this.tabAutocompleteModel
)
)
);
// Commands
@ -138,10 +138,10 @@ export class VsCodeExtension {
this.sidebar,
this.configHandler,
this.diffManager,
this.verticalDiffManager,
this.verticalDiffManager
);
registerDebugTracker(this.webviewProtocol);
registerDebugTracker(this.webviewProtocol, this.ide);
// Indexing
this.ide.getWorkspaceDirs().then((dirs) => this.refreshCodebaseIndex(dirs));
@ -189,7 +189,7 @@ export class VsCodeExtension {
}
});
}
}),
})
);
// Register a content provider for the readonly virtual documents
@ -207,8 +207,8 @@ export class VsCodeExtension {
context.subscriptions.push(
vscode.workspace.registerTextDocumentContentProvider(
VsCodeExtension.continueVirtualDocumentScheme,
documentContentProvider,
),
documentContentProvider
)
);
}

View file

@ -25,12 +25,12 @@ export class VsCodeIdeUtils {
async gotoDefinition(
filepath: string,
position: vscode.Position,
position: vscode.Position
): Promise<vscode.Location[]> {
const locations: vscode.Location[] = await vscode.commands.executeCommand(
"vscode.executeDefinitionProvider",
uriFromFilePath(filepath),
position,
position
);
return locations;
}
@ -38,25 +38,25 @@ export class VsCodeIdeUtils {
async documentSymbol(filepath: string): Promise<vscode.DocumentSymbol[]> {
return await vscode.commands.executeCommand(
"vscode.executeDocumentSymbolProvider",
uriFromFilePath(filepath),
uriFromFilePath(filepath)
);
}
async references(
filepath: string,
position: vscode.Position,
position: vscode.Position
): Promise<vscode.Location[]> {
return await vscode.commands.executeCommand(
"vscode.executeReferenceProvider",
uriFromFilePath(filepath),
position,
position
);
}
async foldingRanges(filepath: string): Promise<vscode.FoldingRange[]> {
return await vscode.commands.executeCommand(
"vscode.executeFoldingRangeProvider",
uriFromFilePath(filepath),
uriFromFilePath(filepath)
);
}
@ -80,12 +80,12 @@ export class VsCodeIdeUtils {
rangeInFile.range.start.line,
rangeInFile.range.start.character,
rangeInFile.range.end.line,
rangeInFile.range.end.character,
rangeInFile.range.end.character
);
const editor = await openEditorAndRevealRange(
rangeInFile.filepath,
range,
vscode.ViewColumn.One,
vscode.ViewColumn.One
);
if (editor) {
const decorationType = vscode.window.createTextEditorDecorationType({
@ -100,7 +100,7 @@ export class VsCodeIdeUtils {
cursorDisposable.dispose();
editor.setDecorations(decorationType, []);
}
},
}
);
setTimeout(() => {
@ -123,9 +123,9 @@ export class VsCodeIdeUtils {
edit.range.start.line,
edit.range.start.character,
edit.range.end.line,
edit.range.end.character,
edit.range.end.character
),
edit.replacement,
edit.replacement
);
}
@ -134,7 +134,7 @@ export class VsCodeIdeUtils {
const panel = vscode.window.createWebviewPanel(
"continue.continueGUIView",
"Continue",
vscode.ViewColumn.One,
vscode.ViewColumn.One
);
// panel.webview.html = this.sidebar.getSidebarContent(
// extensionContext,
@ -165,8 +165,8 @@ export class VsCodeIdeUtils {
vscode.Uri.parse(
`${
VsCodeExtension.continueVirtualDocumentScheme
}:${encodeURIComponent(name)}?${encodeURIComponent(contents)}`,
),
}:${encodeURIComponent(name)}?${encodeURIComponent(contents)}`
)
)
.then((doc) => {
vscode.window.showTextDocument(doc, { preview: false });
@ -248,7 +248,7 @@ export class VsCodeIdeUtils {
async getDirectoryContents(
directory: string,
recursive: boolean,
recursive: boolean
): Promise<string[]> {
if (!recursive) {
return (
@ -273,7 +273,7 @@ export class VsCodeIdeUtils {
gitRoot ?? directory,
[],
true,
gitRoot === directory ? undefined : onlyThisDirectory,
gitRoot === directory ? undefined : onlyThisDirectory
)) {
allFiles.push(file);
}
@ -297,14 +297,14 @@ export class VsCodeIdeUtils {
if (typeof contents === "undefined") {
try {
const fileStats = await vscode.workspace.fs.stat(
uriFromFilePath(filepath),
uriFromFilePath(filepath)
);
if (fileStats.size > 10 * MAX_BYTES) {
return "";
}
const bytes = await vscode.workspace.fs.readFile(
uriFromFilePath(filepath),
uriFromFilePath(filepath)
);
// Truncate the buffer to the first MAX_BYTES
@ -319,10 +319,10 @@ export class VsCodeIdeUtils {
async readRangeInFile(
filepath: string,
range: vscode.Range,
range: vscode.Range
): Promise<string> {
const contents = new TextDecoder().decode(
await vscode.workspace.fs.readFile(vscode.Uri.file(filepath)),
await vscode.workspace.fs.readFile(vscode.Uri.file(filepath))
);
const lines = contents.split("\n");
return (
@ -336,20 +336,20 @@ export class VsCodeIdeUtils {
const tempCopyBuffer = await vscode.env.clipboard.readText();
if (commands < 0) {
await vscode.commands.executeCommand(
"workbench.action.terminal.selectAll",
"workbench.action.terminal.selectAll"
);
} else {
for (let i = 0; i < commands; i++) {
await vscode.commands.executeCommand(
"workbench.action.terminal.selectToPreviousCommand",
"workbench.action.terminal.selectToPreviousCommand"
);
}
}
await vscode.commands.executeCommand(
"workbench.action.terminal.copySelection",
"workbench.action.terminal.copySelection"
);
await vscode.commands.executeCommand(
"workbench.action.terminal.clearSelection",
"workbench.action.terminal.clearSelection"
);
const terminalContents = await vscode.env.clipboard.readText();
await vscode.env.clipboard.writeText(tempCopyBuffer);
@ -361,7 +361,6 @@ export class VsCodeIdeUtils {
return terminalContents;
}
private async _getThreads(session: vscode.DebugSession) {
const threadsResponse = await session.customRequest("threads");
const threads = threadsResponse.threads.filter((thread: any) =>

View file

@ -45,6 +45,27 @@ function useSubmenuContextProviders() {
setLoaded(false);
});
useWebviewListener("updateSubmenuItems", async (data) => {
const minisearch = new MiniSearch<ContextSubmenuItem>({
fields: ["title", "description"],
storeFields: ["id", "title", "description"],
});
minisearch.addAll(data.submenuItems);
setMinisearches((prev) => ({ ...prev, [data.provider]: minisearch }));
if (data.provider === "file") {
const openFiles = await getOpenFileItems();
setFallbackResults((prev) => ({ ...prev, file: openFiles }));
} else {
setFallbackResults((prev) => ({
...prev,
[data.provider]: data.submenuItems.slice(0, 6),
}));
}
});
function addItem(providerTitle: string, item: ContextSubmenuItem) {
if (!minisearches[providerTitle]) {
return;