Elffuss BraidHub

kikocis/continue public

ea675877d1a2 · 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
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 getUniqueId(): Promise<string> {
110 return this.request("getUniqueId", undefined);
111 }
112
113 getWorkspaceConfigs(): Promise<ContinueRcJson[]> {
114 return this.request("getWorkspaceConfigs", undefined);
115 }
116
117 async getDiff(includeUnstaged: boolean) {
118 return await this.request("getDiff", { includeUnstaged });
119 }
120
121 async getClipboardContent(): Promise<{ text: string; copiedAt: string }> {
122 return {
123 text: "",
124 copiedAt: new Date().toISOString(),
125 };
126 }
127
128 async getTerminalContents() {
129 return await this.request("getTerminalContents", undefined);
130 }
131
132 async getWorkspaceDirs(): Promise<string[]> {
133 return await this.request("getWorkspaceDirs", undefined);
134 }
135
136 async showLines(
137 fileUri: string,
138 startLine: number,
139 endLine: number,
140 ): Promise<void> {
141 return await this.request("showLines", {
142 filepath: fileUri,
143 startLine,
144 endLine,
145 });
146 }
147
148 async writeFile(fileUri: string, contents: string): Promise<void> {
149 await this.request("writeFile", { path: fileUri, contents });
150 }
151
152 async showVirtualFile(title: string, contents: string): Promise<void> {
153 await this.request("showVirtualFile", { name: title, content: contents });
154 }
155
156 async openFile(fileUri: string): Promise<void> {
157 await this.request("openFile", { path: fileUri });
158 }
159
160 async openUrl(url: string): Promise<void> {
161 await this.request("openUrl", url);
162 }
163
164 async runCommand(command: string, options?: TerminalOptions): Promise<void> {
165 await this.request("runCommand", { command, options });
166 }
167
168 async saveFile(fileUri: string): Promise<void> {
169 await this.request("saveFile", { filepath: fileUri });
170 }
171
172 async readFile(fileUri: string): Promise<string> {
173 return await this.request("readFile", { filepath: fileUri });
174 }
175
176 getOpenFiles(): Promise<string[]> {
177 return this.request("getOpenFiles", undefined);
178 }
179
180 getCurrentFile() {
181 return this.request("getCurrentFile", undefined);
182 }
183
184 getPinnedFiles(): Promise<string[]> {
185 return this.request("getPinnedFiles", undefined);
186 }
187
188 getSearchResults(query: string): Promise<string> {
189 return this.request("getSearchResults", { query });
190 }
191
192 getFileResults(pattern: string): Promise<string[]> {
193 return this.request("getFileResults", { pattern });
194 }
195
196 getProblems(fileUri: string): Promise<Problem[]> {
197 return this.request("getProblems", { filepath: fileUri });
198 }
199
200 subprocess(command: string, cwd?: string): Promise<[string, string]> {
201 return this.request("subprocess", { command, cwd });
202 }
203
204 async getBranch(dir: string): Promise<string> {
205 return this.request("getBranch", { dir });
206 }
207}