Elffuss BraidHub

kikocis/continue public

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