Elffuss BraidHub

kikocis/continue public

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