Elffuss BraidHub

kikocis/continue public

9d8db5fc402e · 5.6 KiBRawPermalink
1import { FromIdeProtocol } from "..";
2import { GetGhTokenArgs, 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 getGitHubAuthToken(args: GetGhTokenArgs): Promise<string | undefined> {
54 return this.request("getGitHubAuthToken", args);
55 }
56 getFileStats(files: string[]): Promise<FileStatsMap> {
57 return this.request("getFileStats", { files });
58 }
59 getGitRootPath(dir: string): Promise<string | undefined> {
60 return this.request("getGitRootPath", { dir });
61 }
62 listDir(dir: string): Promise<[string, FileType][]> {
63 return this.request("listDir", { dir });
64 }
65
66 showToast: IDE["showToast"] = (...params) => {
67 return this.request("showToast", params);
68 };
69
70 getRepoName(dir: string): Promise<string | undefined> {
71 return this.request("getRepoName", { dir });
72 }
73
74 getDebugLocals(threadIndex: number): Promise<string> {
75 return this.request("getDebugLocals", { threadIndex });
76 }
77
78 getTopLevelCallStackSources(
79 threadIndex: number,
80 stackDepth: number,
81 ): Promise<string[]> {
82 return this.request("getTopLevelCallStackSources", {
83 threadIndex,
84 stackDepth,
85 });
86 }
87
88 getAvailableThreads(): Promise<Thread[]> {
89 return this.request("getAvailableThreads", undefined);
90 }
91
92 getTags(artifactId: string): Promise<IndexTag[]> {
93 return this.request("getTags", artifactId);
94 }
95
96 getIdeInfo(): Promise<IdeInfo> {
97 return this.request("getIdeInfo", undefined);
98 }
99
100 readRangeInFile(filepath: string, range: Range): Promise<string> {
101 return this.request("readRangeInFile", { filepath, range });
102 }
103
104 isTelemetryEnabled(): Promise<boolean> {
105 return this.request("isTelemetryEnabled", undefined);
106 }
107
108 getUniqueId(): Promise<string> {
109 return this.request("getUniqueId", undefined);
110 }
111
112 getWorkspaceConfigs(): Promise<ContinueRcJson[]> {
113 return this.request("getWorkspaceConfigs", undefined);
114 }
115
116 async getDiff(includeUnstaged: boolean) {
117 return await this.request("getDiff", { includeUnstaged });
118 }
119
120 async getClipboardContent(): Promise<{ text: string; copiedAt: string }> {
121 return {
122 text: "",
123 copiedAt: new Date().toISOString(),
124 };
125 }
126
127 async getTerminalContents() {
128 return await this.request("getTerminalContents", undefined);
129 }
130
131 async getWorkspaceDirs(): Promise<string[]> {
132 return await this.request("getWorkspaceDirs", undefined);
133 }
134
135 async showLines(
136 fileUri: string,
137 startLine: number,
138 endLine: number,
139 ): Promise<void> {
140 return await this.request("showLines", {
141 filepath: fileUri,
142 startLine,
143 endLine,
144 });
145 }
146
147 async writeFile(fileUri: string, contents: string): Promise<void> {
148 await this.request("writeFile", { path: fileUri, contents });
149 }
150
151 async showVirtualFile(title: string, contents: string): Promise<void> {
152 await this.request("showVirtualFile", { name: title, content: contents });
153 }
154
155 async openFile(fileUri: string): Promise<void> {
156 await this.request("openFile", { path: fileUri });
157 }
158
159 async openUrl(url: string): Promise<void> {
160 await this.request("openUrl", url);
161 }
162
163 async runCommand(command: string, options?: TerminalOptions): Promise<void> {
164 await this.request("runCommand", { command, options });
165 }
166
167 async saveFile(fileUri: string): Promise<void> {
168 await this.request("saveFile", { filepath: fileUri });
169 }
170 async readFile(fileUri: string): Promise<string> {
171 return await this.request("readFile", { filepath: fileUri });
172 }
173
174 getOpenFiles(): Promise<string[]> {
175 return this.request("getOpenFiles", undefined);
176 }
177
178 getCurrentFile() {
179 return this.request("getCurrentFile", undefined);
180 }
181
182 getPinnedFiles(): Promise<string[]> {
183 return this.request("getPinnedFiles", undefined);
184 }
185
186 getSearchResults(query: string): Promise<string> {
187 return this.request("getSearchResults", { query });
188 }
189
190 getFileResults(pattern: string): Promise<string[]> {
191 return this.request("getFileResults", { pattern });
192 }
193
194 getProblems(fileUri: string): Promise<Problem[]> {
195 return this.request("getProblems", { filepath: fileUri });
196 }
197
198 subprocess(command: string, cwd?: string): Promise<[string, string]> {
199 return this.request("subprocess", { command, cwd });
200 }
201
202 async getBranch(dir: string): Promise<string> {
203 return this.request("getBranch", { dir });
204 }
205}