Elffuss BraidHub

kikocis/continue public

d7c7c28e99d9 · 5.5 KiBRawPermalink
1import { FromIdeProtocol } from "..";
2import { ToIdeFromWebviewOrCoreProtocol } from "../ide";
3
4import type {
5 ContinueRcJson,
6 FileStatsMap,
7 FileType,
8 IDE,
9 IdeInfo,
10 IdeSettings,
11 IndexTag,
12 Location,
13 Problem,
14 Range,
15 RangeInFile,
16 TerminalOptions,
17 Thread,
18} from "../..";
19
20export class MessageIde implements IDE {
21 constructor(
22 private readonly request: <T extends keyof ToIdeFromWebviewOrCoreProtocol>(
23 messageType: T,
24 data: ToIdeFromWebviewOrCoreProtocol[T][0],
25 ) => Promise<ToIdeFromWebviewOrCoreProtocol[T][1]>,
26 private readonly on: <T extends keyof FromIdeProtocol>(
27 messageType: T,
28 callback: (data: FromIdeProtocol[T][0]) => FromIdeProtocol[T][1],
29 ) => void,
30 ) {}
31
32 async readSecrets(keys: string[]): Promise<Record<string, string>> {
33 return this.request("readSecrets", { keys });
34 }
35
36 async writeSecrets(secrets: { [key: string]: string }): Promise<void> {
37 return this.request("writeSecrets", { secrets });
38 }
39
40 fileExists(fileUri: string): Promise<boolean> {
41 return this.request("fileExists", { filepath: fileUri });
42 }
43 async gotoDefinition(location: Location): Promise<RangeInFile[]> {
44 return this.request("gotoDefinition", { location });
45 }
46 onDidChangeActiveTextEditor(callback: (fileUri: string) => void): void {
47 this.on("didChangeActiveTextEditor", (data) => callback(data.filepath));
48 }
49
50 getIdeSettings(): Promise<IdeSettings> {
51 return this.request("getIdeSettings", undefined);
52 }
53 getFileStats(files: string[]): Promise<FileStatsMap> {
54 return this.request("getFileStats", { files });
55 }
56 getGitRootPath(dir: string): Promise<string | undefined> {
57 return this.request("getGitRootPath", { dir });
58 }
59 listDir(dir: string): Promise<[string, FileType][]> {
60 return this.request("listDir", { dir });
61 }
62
63 showToast: IDE["showToast"] = (...params) => {
64 return this.request("showToast", params);
65 };
66
67 getRepoName(dir: string): Promise<string | undefined> {
68 return this.request("getRepoName", { dir });
69 }
70
71 getDebugLocals(threadIndex: number): Promise<string> {
72 return this.request("getDebugLocals", { threadIndex });
73 }
74
75 getTopLevelCallStackSources(
76 threadIndex: number,
77 stackDepth: number,
78 ): Promise<string[]> {
79 return this.request("getTopLevelCallStackSources", {
80 threadIndex,
81 stackDepth,
82 });
83 }
84
85 getAvailableThreads(): Promise<Thread[]> {
86 return this.request("getAvailableThreads", undefined);
87 }
88
89 getTags(artifactId: string): Promise<IndexTag[]> {
90 return this.request("getTags", artifactId);
91 }
92
93 getIdeInfo(): Promise<IdeInfo> {
94 return this.request("getIdeInfo", undefined);
95 }
96
97 readRangeInFile(filepath: string, range: Range): Promise<string> {
98 return this.request("readRangeInFile", { filepath, range });
99 }
100
101 isTelemetryEnabled(): Promise<boolean> {
102 return this.request("isTelemetryEnabled", undefined);
103 }
104
105 getUniqueId(): Promise<string> {
106 return this.request("getUniqueId", undefined);
107 }
108
109 getWorkspaceConfigs(): Promise<ContinueRcJson[]> {
110 return this.request("getWorkspaceConfigs", undefined);
111 }
112
113 async getDiff(includeUnstaged: boolean) {
114 return await this.request("getDiff", { includeUnstaged });
115 }
116
117 async getClipboardContent(): Promise<{ text: string; copiedAt: string }> {
118 return {
119 text: "",
120 copiedAt: new Date().toISOString(),
121 };
122 }
123
124 async getTerminalContents() {
125 return await this.request("getTerminalContents", undefined);
126 }
127
128 async getWorkspaceDirs(): Promise<string[]> {
129 return await this.request("getWorkspaceDirs", undefined);
130 }
131
132 async showLines(
133 fileUri: string,
134 startLine: number,
135 endLine: number,
136 ): Promise<void> {
137 return await this.request("showLines", {
138 filepath: fileUri,
139 startLine,
140 endLine,
141 });
142 }
143
144 async writeFile(fileUri: string, contents: string): Promise<void> {
145 await this.request("writeFile", { path: fileUri, contents });
146 }
147
148 async showVirtualFile(title: string, contents: string): Promise<void> {
149 await this.request("showVirtualFile", { name: title, content: contents });
150 }
151
152 async openFile(fileUri: string): Promise<void> {
153 await this.request("openFile", { path: fileUri });
154 }
155
156 async openUrl(url: string): Promise<void> {
157 await this.request("openUrl", url);
158 }
159
160 async runCommand(command: string, options?: TerminalOptions): Promise<void> {
161 await this.request("runCommand", { command, options });
162 }
163
164 async saveFile(fileUri: string): Promise<void> {
165 await this.request("saveFile", { filepath: fileUri });
166 }
167 async readFile(fileUri: string): Promise<string> {
168 return await this.request("readFile", { filepath: fileUri });
169 }
170
171 getOpenFiles(): Promise<string[]> {
172 return this.request("getOpenFiles", undefined);
173 }
174
175 getCurrentFile() {
176 return this.request("getCurrentFile", undefined);
177 }
178
179 getPinnedFiles(): Promise<string[]> {
180 return this.request("getPinnedFiles", undefined);
181 }
182
183 getSearchResults(query: string): Promise<string> {
184 return this.request("getSearchResults", { query });
185 }
186
187 getFileResults(pattern: string): Promise<string[]> {
188 return this.request("getFileResults", { pattern });
189 }
190
191 getProblems(fileUri: string): Promise<Problem[]> {
192 return this.request("getProblems", { filepath: fileUri });
193 }
194
195 subprocess(command: string, cwd?: string): Promise<[string, string]> {
196 return this.request("subprocess", { command, cwd });
197 }
198
199 async getBranch(dir: string): Promise<string> {
200 return this.request("getBranch", { dir });
201 }
202}