Skip to content

Commit

Permalink
Merge branch 'commandblock2-debug-context-provider' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Mar 17, 2024
2 parents 6a5ad0e + 3b6902f commit 1e41ed6
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 79 deletions.
62 changes: 62 additions & 0 deletions core/context/providers/LocalsProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { BaseContextProvider } from "..";
import {
ContextItem,
ContextProviderDescription,
ContextProviderExtras,
ContextSubmenuItem,
LoadSubmenuItemsArgs,
} from "../..";

class LocalsProvider extends BaseContextProvider {
static description: ContextProviderDescription = {
title: "locals",
displayTitle: "Locals",
description: "Reference the contents of the local variables",
type: "submenu",
};

async getContextItems(
query: string,
extras: ContextProviderExtras
): Promise<ContextItem[]> {
// 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()).find(
(thread) => thread.id == threadIndex
);
const callStacksSources = await extras.ide.getTopLevelCallStackSources(
threadIndex,
this.options?.stackDepth || 3
);
const callStackContents = callStacksSources.reduce(
(acc, source, index) =>
acc + `\n\ncall stack ${index}\n` + "```\n" + source + "\n```",
""
);
return [
{
description: "The value, name and possibly type of the local variables",
content:
`This is a paused thread: ${thread?.name}\n` +
`Current local variable contents: \n${localVariables}.\n` +
`Current top level call stacks: ${callStackContents}`,
name: "Locals",
},
];
}

async loadSubmenuItems(
args: LoadSubmenuItemsArgs
): Promise<ContextSubmenuItem[]> {
const threads = await args.ide.getAvailableThreads();

return threads.map((thread) => ({
id: `${thread.id}`,
title: thread.name,
description: `${thread.id}`,
}));
}
}

export default LocalsProvider;
2 changes: 2 additions & 0 deletions core/context/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import PostgresContextProvider from "./PostgresContextProvider";
import ProblemsContextProvider from "./ProblemsContextProvider";
import SearchContextProvider from "./SearchContextProvider";
import TerminalContextProvider from "./TerminalContextProvider";
import LocalsProvider from "./LocalsProvider";
import URLContextProvider from "./URLContextProvider";

const Providers: (typeof BaseContextProvider)[] = [
Expand All @@ -24,6 +25,7 @@ const Providers: (typeof BaseContextProvider)[] = [
GitHubIssuesContextProvider,
GoogleContextProvider,
TerminalContextProvider,
LocalsProvider,
URLContextProvider,
OpenFilesContextProvider,
HttpContextProvider,
Expand Down
36 changes: 24 additions & 12 deletions core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare global {
postIntellijMessage?: (
messageType: string,
data: any,
messageIde: string,
messageIde: string
) => void;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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[]>;
}

Expand All @@ -141,7 +141,7 @@ export interface IContextProvider {

getContextItems(
query: string,
extras: ContextProviderExtras,
extras: ContextProviderExtras
): Promise<ContextItem[]>;

loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise<ContextSubmenuItem[]>;
Expand Down Expand Up @@ -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[]>;
}

Expand All @@ -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;
Expand All @@ -340,6 +345,12 @@ export interface IDE {
isTelemetryEnabled(): Promise<boolean>;
getUniqueId(): Promise<string>;
getTerminalContents(): Promise<string>;
getDebugLocals(threadIndex: number): Promise<string>;
getTopLevelCallStackSources(
threadIndex: number,
stackDepth: number
): Promise<string[]>;
getAvailableThreads(): Promise<Thread[]>;
listWorkspaceContents(directory?: string): Promise<string[]>;
listFolders(): Promise<string[]>;
getWorkspaceDirs(): Promise<string[]>;
Expand All @@ -355,12 +366,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[]>;
Expand Down Expand Up @@ -415,6 +426,7 @@ type ContextProviderName =
| "diff"
| "github"
| "terminal"
| "locals"
| "open"
| "google"
| "search"
Expand Down
18 changes: 15 additions & 3 deletions core/util/filesystem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "fs";
import { ContinueRcJson, IDE, IdeInfo, IndexTag, Problem, Range } from "..";
import { ContinueRcJson, IDE, IdeInfo, IndexTag, Problem, Range, Thread } from "..";

import { getContinueGlobalPath } from "./paths";

Expand Down Expand Up @@ -37,10 +37,22 @@ class FileSystemIde implements IDE {
getTerminalContents(): Promise<string> {
return Promise.resolve("");
}
async getDebugLocals(threadIndex: number): Promise<string> {
return Promise.resolve("");
}
async getTopLevelCallStackSources(
threadIndex: number,
stackDepth: number
): Promise<string[]> {
return Promise.resolve([]);
}
async getAvailableThreads(): Promise<Thread[]> {
return Promise.resolve([]);
}
showLines(
filepath: string,
startLine: number,
endLine: number,
endLine: number
): Promise<void> {
return Promise.resolve();
}
Expand Down Expand Up @@ -105,7 +117,7 @@ class FileSystemIde implements IDE {
showDiff(
filepath: string,
newContents: string,
stepIndex: number,
stepIndex: number
): Promise<void> {
return Promise.resolve();
}
Expand Down
23 changes: 19 additions & 4 deletions core/util/messageIde.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { ContinueRcJson, IDE, IdeInfo, IndexTag, Problem, Range } from "..";
import { ContinueRcJson, IDE, IdeInfo, IndexTag, 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 });
}
getTopLevelCallStackSources(
threadIndex: number,
stackDepth: number
): Promise<string[]> {
return this.request("getTopLevelCallStackSources", {
threadIndex,
stackDepth,
});
}
getAvailableThreads(): Promise<Thread[]> {
return this.request("getAvailableThreads", undefined);
}
getTags(artifactId: string): Promise<IndexTag[]> {
return this.request("getTags", artifactId);
}
Expand Down Expand Up @@ -48,7 +63,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 });
}
Expand Down Expand Up @@ -93,7 +108,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 });
}
Expand Down
20 changes: 16 additions & 4 deletions core/web/webviewProtocol.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
ContextItemWithId,
ContextSubmenuItem,
ContinueRcJson,
DiffLine,
IndexTag,
Problem,
Range,
Thread,
} from "..";
import { RangeInFileWithContents } from "../commands/util";

Expand All @@ -25,7 +27,7 @@ export type IdeProtocol = {
readFile: [{ filepath: string }, string];
showDiff: [
{ filepath: string; newContents: string; stepIndex: number },
void,
void
];
diffLine: [
{
Expand All @@ -34,7 +36,7 @@ export type IdeProtocol = {
startLine: number;
endLine: number;
},
void,
void
];
getProblems: [{ filepath: string }, Problem[]];
getBranch: [{ dir: string }, string];
Expand All @@ -45,6 +47,12 @@ export type IdeProtocol = {
getDiff: [undefined, string];
getWorkspaceConfigs: [undefined, ContinueRcJson[]];
getTerminalContents: [undefined, string];
getDebugLocals: [{ threadIndex: Number }, string];
getTopLevelCallStackSources: [
{ threadIndex: number; stackDepth: number },
string[]
];
getAvailableThreads: [undefined, Thread[]];
isTelemetryEnabled: [undefined, boolean];
getUniqueId: [undefined, string];
getTags: [string, IndexTag[]];
Expand All @@ -60,7 +68,7 @@ export type WebviewProtocol = Protocol &
workspacePaths: string[];
vscMachineId: string;
vscMediaUrl: string;
},
}
];

errorPopup: [{ message: string }, void];
Expand All @@ -86,7 +94,11 @@ export type ReverseWebviewProtocol = {
historyIndex: number;
item: ContextItemWithId;
},
void,
void
];
updateSubmenuItems: [
{ provider: string; submenuItems: ContextSubmenuItem[] },
void
];
getDefaultModelTitle: [undefined, string];
newSessionWithPrompt: [{ prompt: string }, void];
Expand Down
13 changes: 13 additions & 0 deletions docs/docs/customization/context-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ Type `@database` to reference table schemas you can use the drop-down or start t
}
```

### Debugger: Local Variables

Type `@locals` to reference the contents of the local variables with top n level (defaulting to 3) of call stack for that thread. A dropdown will appear, allowing you to select a specific thread to see the local variables in that thread.

```json
{
"name": "locals",
"params": {
"stackDepth": 3
}
}
```

### Requesting Context Providers

Not seeing what you want? Create an issue [here](https://github.com/continuedev/continue/issues/new?assignees=TyDunn&labels=enhancement&projects=&template=feature-request-%F0%9F%92%AA.md&title=) to request a new ContextProvider.
Expand Down
1 change: 1 addition & 0 deletions docs/static/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@
"enum": [
"diff",
"terminal",
"locals",
"open",
"google",
"search",
Expand Down
1 change: 1 addition & 0 deletions extensions/intellij/src/main/resources/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@
"enum": [
"diff",
"terminal",
"locals",
"open",
"google",
"search",
Expand Down
1 change: 1 addition & 0 deletions extensions/vscode/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@
"enum": [
"diff",
"terminal",
"locals",
"open",
"google",
"search",
Expand Down
Loading

0 comments on commit 1e41ed6

Please sign in to comment.