refactor: changed the interface of threads
This commit is contained in:
parent
4181490794
commit
dacd9fb291
8 changed files with 94 additions and 82 deletions
|
|
@ -22,7 +22,9 @@ class LocalsProvider extends BaseContextProvider {
|
|||
// Assuming that the query is a number
|
||||
const localVariables = await extras.ide.getDebugLocals(Number(query));
|
||||
const threadIndex = Number(query);
|
||||
const thread = (await extras.ide.getAvailableThreads())[threadIndex];
|
||||
const thread = (await extras.ide.getAvailableThreads()).find(
|
||||
(thread) => thread.id == threadIndex
|
||||
);
|
||||
const callStacksSources = await extras.ide.getTopLevelCallStackSources(
|
||||
threadIndex,
|
||||
this.options?.stackDepth || 3
|
||||
|
|
@ -36,7 +38,7 @@ class LocalsProvider extends BaseContextProvider {
|
|||
{
|
||||
description: "The value, name and possibly type of the local variables",
|
||||
content:
|
||||
`This is a paused thread: ${thread.split(",")[1].trimStart()}\n` +
|
||||
`This is a paused thread: ${thread?.name}` +
|
||||
`Current local variable contents:\n\n${localVariables}.\n` +
|
||||
`Current top level call stacks: \n\n${callStackContents}`,
|
||||
name: "Locals",
|
||||
|
|
@ -49,16 +51,11 @@ class LocalsProvider extends BaseContextProvider {
|
|||
): Promise<ContextSubmenuItem[]> {
|
||||
const threads = await args.ide.getAvailableThreads();
|
||||
|
||||
return threads.map((thread, threadIndex) => {
|
||||
const [threadId, threadName] = thread
|
||||
.split(",")
|
||||
.map((str) => str.trimStart());
|
||||
return {
|
||||
id: `${threadIndex}`,
|
||||
title: threadName,
|
||||
description: threadId,
|
||||
};
|
||||
});
|
||||
return threads.map((thread) => ({
|
||||
id: `${thread.id}`,
|
||||
title: thread.name,
|
||||
description: `${thread.id}`,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
31
core/index.d.ts
vendored
31
core/index.d.ts
vendored
|
|
@ -16,7 +16,7 @@ declare global {
|
|||
postIntellijMessage?: (
|
||||
messageType: string,
|
||||
data: any,
|
||||
messageIde: string,
|
||||
messageIde: string
|
||||
) => void;
|
||||
}
|
||||
}
|
||||
|
|
@ -73,17 +73,17 @@ export interface ILLM extends LLMOptions {
|
|||
|
||||
streamComplete(
|
||||
prompt: string,
|
||||
options?: LLMFullCompletionOptions,
|
||||
options?: LLMFullCompletionOptions
|
||||
): AsyncGenerator<string, LLMReturnValue>;
|
||||
|
||||
streamChat(
|
||||
messages: ChatMessage[],
|
||||
options?: LLMFullCompletionOptions,
|
||||
options?: LLMFullCompletionOptions
|
||||
): AsyncGenerator<ChatMessage, LLMReturnValue>;
|
||||
|
||||
chat(
|
||||
messages: ChatMessage[],
|
||||
options?: LLMFullCompletionOptions,
|
||||
options?: LLMFullCompletionOptions
|
||||
): Promise<ChatMessage>;
|
||||
|
||||
countTokens(text: string): number;
|
||||
|
|
@ -123,10 +123,10 @@ export interface CustomContextProvider {
|
|||
type?: ContextProviderType;
|
||||
getContextItems(
|
||||
query: string,
|
||||
extras: ContextProviderExtras,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]>;
|
||||
loadSubmenuItems?: (
|
||||
args: LoadSubmenuItemsArgs,
|
||||
args: LoadSubmenuItemsArgs
|
||||
) => Promise<ContextSubmenuItem[]>;
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ export interface IContextProvider {
|
|||
|
||||
getContextItems(
|
||||
query: string,
|
||||
extras: ContextProviderExtras,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]>;
|
||||
|
||||
loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise<ContextSubmenuItem[]>;
|
||||
|
|
@ -287,15 +287,15 @@ export interface CustomLLMWithOptionals {
|
|||
streamCompletion?: (
|
||||
prompt: string,
|
||||
options: CompletionOptions,
|
||||
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>,
|
||||
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
|
||||
) => AsyncGenerator<string>;
|
||||
streamChat?: (
|
||||
messages: ChatMessage[],
|
||||
options: CompletionOptions,
|
||||
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>,
|
||||
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
|
||||
) => AsyncGenerator<string>;
|
||||
listModels?: (
|
||||
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>,
|
||||
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
|
||||
) => Promise<string[]>;
|
||||
}
|
||||
|
||||
|
|
@ -320,6 +320,11 @@ export class Problem {
|
|||
message: string;
|
||||
}
|
||||
|
||||
export class Thread {
|
||||
name: string;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export type IdeType = "vscode" | "jetbrains";
|
||||
export interface IdeInfo {
|
||||
ideType: IdeType;
|
||||
|
|
@ -339,7 +344,7 @@ export interface IDE {
|
|||
threadIndex: number,
|
||||
stackDepth: number
|
||||
): Promise<string[]>;
|
||||
getAvailableThreads(): Promise<string[]>;
|
||||
getAvailableThreads(): Promise<Thread[]>;
|
||||
listWorkspaceContents(directory?: string): Promise<string[]>;
|
||||
listFolders(): Promise<string[]>;
|
||||
getWorkspaceDirs(): Promise<string[]>;
|
||||
|
|
@ -355,12 +360,12 @@ export interface IDE {
|
|||
showLines(
|
||||
filepath: string,
|
||||
startLine: number,
|
||||
endLine: number,
|
||||
endLine: number
|
||||
): Promise<void>;
|
||||
showDiff(
|
||||
filepath: string,
|
||||
newContents: string,
|
||||
stepIndex: number,
|
||||
stepIndex: number
|
||||
): Promise<void>;
|
||||
getOpenFiles(): Promise<string[]>;
|
||||
getPinnedFiles(): Promise<string[]>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as fs from "fs";
|
||||
import { ContinueRcJson, IDE, IdeInfo, Problem, Range } from "..";
|
||||
import { ContinueRcJson, IDE, IdeInfo, Problem, Range, Thread } from "..";
|
||||
import { getContinueGlobalPath } from "./paths";
|
||||
|
||||
class FileSystemIde implements IDE {
|
||||
|
|
@ -36,16 +36,19 @@ class FileSystemIde implements IDE {
|
|||
async getDebugLocals(threadIndex: number): Promise<string> {
|
||||
return Promise.resolve("");
|
||||
}
|
||||
async getTopLevelCallStackSources(threadIndex: number, stackDepth: number): Promise<string[]> {
|
||||
async getTopLevelCallStackSources(
|
||||
threadIndex: number,
|
||||
stackDepth: number
|
||||
): Promise<string[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
async getAvailableThreads(): Promise<string[]> {
|
||||
async getAvailableThreads(): Promise<Thread[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
showLines(
|
||||
filepath: string,
|
||||
startLine: number,
|
||||
endLine: number,
|
||||
endLine: number
|
||||
): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
|
@ -110,7 +113,7 @@ class FileSystemIde implements IDE {
|
|||
showDiff(
|
||||
filepath: string,
|
||||
newContents: string,
|
||||
stepIndex: number,
|
||||
stepIndex: number
|
||||
): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { ContinueRcJson, IDE, IdeInfo, Problem, Range } from "..";
|
||||
import { ContinueRcJson, IDE, IdeInfo, Problem, Range, Thread } from "..";
|
||||
|
||||
export class MessageIde implements IDE {
|
||||
constructor(
|
||||
private readonly request: (messageType: string, data: any) => Promise<any>,
|
||||
private readonly request: (messageType: string, data: any) => Promise<any>
|
||||
) {}
|
||||
getDebugLocals(threadIndex: number): Promise<string> {
|
||||
return this.request("getDebugLocals", { threadIndex });
|
||||
|
|
@ -16,8 +16,8 @@ export class MessageIde implements IDE {
|
|||
stackDepth,
|
||||
});
|
||||
}
|
||||
getAvailableThreads(): Promise<string[]> {
|
||||
return this.request("getTopLevelCallStackSources", undefined);
|
||||
getAvailableThreads(): Promise<Thread[]> {
|
||||
return this.request("getAvailableThreads", undefined);
|
||||
}
|
||||
getIdeInfo(): Promise<IdeInfo> {
|
||||
return this.request("getIdeInfo", undefined);
|
||||
|
|
@ -60,7 +60,7 @@ export class MessageIde implements IDE {
|
|||
async showLines(
|
||||
filepath: string,
|
||||
startLine: number,
|
||||
endLine: number,
|
||||
endLine: number
|
||||
): Promise<void> {
|
||||
return await this.request("showLines", { filepath, startLine, endLine });
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ export class MessageIde implements IDE {
|
|||
async showDiff(
|
||||
filepath: string,
|
||||
newContents: string,
|
||||
stepIndex: number,
|
||||
stepIndex: number
|
||||
): Promise<void> {
|
||||
await this.request("showDiff", { filepath, newContents, stepIndex });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
DiffLine,
|
||||
Problem,
|
||||
Range,
|
||||
Thread,
|
||||
} from "..";
|
||||
import { RangeInFileWithContents } from "../commands/util";
|
||||
import { Protocol } from "../protocol";
|
||||
|
|
@ -49,7 +50,7 @@ export type IdeProtocol = {
|
|||
{ threadIndex: number; stackDepth: number },
|
||||
string[]
|
||||
];
|
||||
getAvailableThreads: [undefined, string[]];
|
||||
getAvailableThreads: [undefined, Thread[]];
|
||||
isTelemetryEnabled: [undefined, boolean];
|
||||
getUniqueId: [undefined, string];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,17 @@ export function registerDebugTracker(
|
|||
vscode.debug.registerDebugAdapterTrackerFactory("*", {
|
||||
createDebugAdapterTracker(session: vscode.DebugSession) {
|
||||
return {
|
||||
async onWillStopSession() {
|
||||
threadStopped.clear();
|
||||
webviewProtocol?.request("updateSubmenuItems", {
|
||||
provider: "locals",
|
||||
submenuItems: (await ide.getAvailableThreads()).map((thread) => ({
|
||||
id: `${thread.id}`,
|
||||
title: thread.name,
|
||||
description: `${thread.id}`,
|
||||
})),
|
||||
});
|
||||
},
|
||||
async onDidSendMessage(message: any) {
|
||||
if (message.type == "event") {
|
||||
switch (message.event) {
|
||||
|
|
@ -36,16 +47,11 @@ export function registerDebugTracker(
|
|||
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,
|
||||
};
|
||||
}
|
||||
(thread) => ({
|
||||
id: `${thread.id}`,
|
||||
title: thread.name,
|
||||
description: `${thread.id}`,
|
||||
})
|
||||
),
|
||||
});
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import * as path from "path";
|
|||
import * as vscode from "vscode";
|
||||
|
||||
import * as child_process from "child_process";
|
||||
import { ContinueRcJson, IDE, IdeInfo, Problem, Range } from "core";
|
||||
import { ContinueRcJson, IDE, IdeInfo, Problem, Range, Thread } from "core";
|
||||
import { DiffManager } from "./diff/horizontal";
|
||||
import { VsCodeIdeUtils } from "./util/ideUtils";
|
||||
import { traverseDirectory } from "./util/traverseDirectory";
|
||||
|
|
@ -33,8 +33,8 @@ class VsCodeIde implements IDE {
|
|||
filepath,
|
||||
new vscode.Range(
|
||||
new vscode.Position(range.start.line, range.start.character),
|
||||
new vscode.Position(range.end.line, range.end.character),
|
||||
),
|
||||
new vscode.Position(range.end.line, range.end.character)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ class VsCodeIde implements IDE {
|
|||
files.map(async (file) => {
|
||||
let stat = await vscode.workspace.fs.stat(uriFromFilePath(file));
|
||||
pathToLastModified[file] = stat.mtime;
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
return pathToLastModified;
|
||||
|
|
@ -79,10 +79,16 @@ class VsCodeIde implements IDE {
|
|||
return await this.ideUtils.getDebugLocals(threadIndex);
|
||||
}
|
||||
|
||||
async getTopLevelCallStackSources(threadIndex: number, stackDepth: number): Promise<string[]> {
|
||||
return await this.ideUtils.getTopLevelCallStackSources(threadIndex, stackDepth);
|
||||
async getTopLevelCallStackSources(
|
||||
threadIndex: number,
|
||||
stackDepth: number
|
||||
): Promise<string[]> {
|
||||
return await this.ideUtils.getTopLevelCallStackSources(
|
||||
threadIndex,
|
||||
stackDepth
|
||||
);
|
||||
}
|
||||
async getAvailableThreads(): Promise<string[]> {
|
||||
async getAvailableThreads(): Promise<Thread[]> {
|
||||
return await this.ideUtils.getAvailableThreads();
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +99,7 @@ class VsCodeIde implements IDE {
|
|||
const contents = await Promise.all(
|
||||
this.ideUtils
|
||||
.getWorkspaceDirectories()
|
||||
.map((dir) => this.ideUtils.getDirectoryContents(dir, true)),
|
||||
.map((dir) => this.ideUtils.getDirectoryContents(dir, true))
|
||||
);
|
||||
return contents.flat();
|
||||
}
|
||||
|
|
@ -108,7 +114,7 @@ class VsCodeIde implements IDE {
|
|||
for (const [filename, type] of files) {
|
||||
if (type === vscode.FileType.File && filename === ".continuerc.json") {
|
||||
const contents = await this.ideUtils.readFile(
|
||||
vscode.Uri.joinPath(workspaceDir, filename).fsPath,
|
||||
vscode.Uri.joinPath(workspaceDir, filename).fsPath
|
||||
);
|
||||
configs.push(JSON.parse(contents));
|
||||
}
|
||||
|
|
@ -126,7 +132,7 @@ class VsCodeIde implements IDE {
|
|||
directory,
|
||||
[],
|
||||
false,
|
||||
undefined,
|
||||
undefined
|
||||
)) {
|
||||
allDirs.push(dir);
|
||||
}
|
||||
|
|
@ -146,7 +152,7 @@ class VsCodeIde implements IDE {
|
|||
async writeFile(path: string, contents: string): Promise<void> {
|
||||
await vscode.workspace.fs.writeFile(
|
||||
vscode.Uri.file(path),
|
||||
Buffer.from(contents),
|
||||
Buffer.from(contents)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -161,11 +167,11 @@ class VsCodeIde implements IDE {
|
|||
async showLines(
|
||||
filepath: string,
|
||||
startLine: number,
|
||||
endLine: number,
|
||||
endLine: number
|
||||
): Promise<void> {
|
||||
const range = new vscode.Range(
|
||||
new vscode.Position(startLine, 0),
|
||||
new vscode.Position(endLine, 0),
|
||||
new vscode.Position(endLine, 0)
|
||||
);
|
||||
openEditorAndRevealRange(filepath, range).then(() => {
|
||||
// TODO: Highlight lines
|
||||
|
|
@ -199,7 +205,7 @@ class VsCodeIde implements IDE {
|
|||
async showDiff(
|
||||
filepath: string,
|
||||
newContents: string,
|
||||
stepIndex: number,
|
||||
stepIndex: number
|
||||
): Promise<void> {
|
||||
await this.diffManager.writeDiff(filepath, newContents, stepIndex);
|
||||
}
|
||||
|
|
@ -224,10 +230,10 @@ class VsCodeIde implements IDE {
|
|||
"@vscode",
|
||||
"ripgrep",
|
||||
"bin",
|
||||
"rg",
|
||||
"rg"
|
||||
),
|
||||
["-i", "-C", "2", `"${query}"`, "."],
|
||||
{ cwd: dir },
|
||||
{ cwd: dir }
|
||||
);
|
||||
let output = "";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { FileEdit, RangeInFile } from "core";
|
||||
import { FileEdit, RangeInFile, Thread } from "core";
|
||||
import path from "path";
|
||||
import * as vscode from "vscode";
|
||||
import { VsCodeExtension } from "../extension/vscodeExtension";
|
||||
|
|
@ -372,14 +372,12 @@ export class VsCodeIdeUtils {
|
|||
return threadsResponse;
|
||||
}
|
||||
|
||||
async getAvailableThreads(): Promise<string[]> {
|
||||
async getAvailableThreads(): Promise<Thread[]> {
|
||||
const session = vscode.debug.activeDebugSession;
|
||||
if (!session) return [];
|
||||
|
||||
const threadsResponse = await this._getThreads(session);
|
||||
return threadsResponse.threads.map(
|
||||
(thread: { id: number; name: string }) => `${thread.id}, ${thread.name}`
|
||||
);
|
||||
return threadsResponse.threads;
|
||||
}
|
||||
|
||||
async getDebugLocals(threadIndex: number = 0): Promise<string> {
|
||||
|
|
@ -392,13 +390,11 @@ export class VsCodeIdeUtils {
|
|||
return "";
|
||||
}
|
||||
|
||||
const variablesResponse = await this._getThreads(session)
|
||||
.then((threadsResponse) =>
|
||||
session.customRequest("stackTrace", {
|
||||
threadId: threadsResponse.threads[threadIndex].id,
|
||||
startFrame: 0,
|
||||
})
|
||||
)
|
||||
const variablesResponse = await session
|
||||
.customRequest("stackTrace", {
|
||||
threadId: threadIndex,
|
||||
startFrame: 0,
|
||||
})
|
||||
.then((traceResponse) =>
|
||||
session.customRequest("scopes", {
|
||||
frameId: traceResponse.stackFrames[0].id,
|
||||
|
|
@ -429,13 +425,11 @@ export class VsCodeIdeUtils {
|
|||
const session = vscode.debug.activeDebugSession;
|
||||
if (!session) return [];
|
||||
|
||||
const sourcesPromises = await this._getThreads(session)
|
||||
.then((threadsResponse) =>
|
||||
session.customRequest("stackTrace", {
|
||||
threadId: threadsResponse.threads[threadIndex].id,
|
||||
startFrame: 0,
|
||||
})
|
||||
)
|
||||
const sourcesPromises = await session
|
||||
.customRequest("stackTrace", {
|
||||
threadId: threadIndex,
|
||||
startFrame: 0,
|
||||
})
|
||||
.then((traceResponse) =>
|
||||
traceResponse.stackFrames
|
||||
.slice(0, stackDepth)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue