Elffuss BraidHub

kikocis/continue public

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