Elffuss BraidHub

kikocis/continue public

6d66081d22d3 · 5.9 KiBRawPermalink
1import * as fs from "node:fs";
2
3import { fileURLToPath } from "node:url";
4import {
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 ToastType,
19} from "../index.js";
20
21class FileSystemIde implements IDE {
22 constructor(private readonly workspaceDir: string) {}
23
24 async readSecrets(keys: string[]): Promise<Record<string, string>> {
25 return {};
26 }
27
28 async writeSecrets(secrets: { [key: string]: string }): Promise<void> {}
29
30 showToast(
31 type: ToastType,
32 message: string,
33 ...otherParams: any[]
34 ): Promise<void> {
35 return Promise.resolve();
36 }
37
38 fileExists(fileUri: string): Promise<boolean> {
39 const filepath = fileURLToPath(fileUri);
40 return Promise.resolve(fs.existsSync(filepath));
41 }
42
43 gotoDefinition(location: Location): Promise<RangeInFile[]> {
44 return Promise.resolve([]);
45 }
46
47 onDidChangeActiveTextEditor(callback: (fileUri: string) => void): void {
48 return;
49 }
50
51 isWorkspaceRemote(): Promise<boolean> {
52 return Promise.resolve(false);
53 }
54
55 async getIdeSettings(): Promise<IdeSettings> {
56 return {
57 remoteConfigServerUrl: undefined,
58 remoteConfigSyncPeriod: 60,
59 userToken: "",
60 continueTestEnvironment: "none",
61 pauseCodebaseIndexOnStart: false,
62 };
63 }
64
65 async getFileStats(fileUris: string[]): Promise<FileStatsMap> {
66 const result: FileStatsMap = {};
67 for (const uri of fileUris) {
68 try {
69 const filepath = fileURLToPath(uri);
70 const stats = fs.statSync(filepath);
71 result[uri] = {
72 lastModified: stats.mtimeMs,
73 size: stats.size,
74 };
75 } catch (error) {
76 console.error(`Error getting last modified time for ${uri}:`, error);
77 }
78 }
79 return result;
80 }
81
82 getGitRootPath(dir: string): Promise<string | undefined> {
83 return Promise.resolve(dir);
84 }
85
86 async listDir(dir: string): Promise<[string, FileType][]> {
87 const filepath = fileURLToPath(dir);
88 const all: [string, FileType][] = fs
89 .readdirSync(filepath, { withFileTypes: true })
90 .map((dirent: any) => [
91 dirent.name,
92 dirent.isDirectory()
93 ? (2 as FileType.Directory)
94 : dirent.isSymbolicLink()
95 ? (64 as FileType.SymbolicLink)
96 : (1 as FileType.File),
97 ]);
98 return Promise.resolve(all);
99 }
100
101 getRepoName(dir: string): Promise<string | undefined> {
102 return Promise.resolve(undefined);
103 }
104
105 async getTags(artifactId: string): Promise<IndexTag[]> {
106 const directory = (await this.getWorkspaceDirs())[0];
107 return [
108 {
109 artifactId,
110 branch: await this.getBranch(directory),
111 directory,
112 },
113 ];
114 }
115
116 getIdeInfo(): Promise<IdeInfo> {
117 return Promise.resolve({
118 ideType: "vscode",
119 name: "na",
120 version: "0.1",
121 remoteName: "na",
122 extensionVersion: "na",
123 });
124 }
125
126 readRangeInFile(fileUri: string, range: Range): Promise<string> {
127 return Promise.resolve("");
128 }
129
130 isTelemetryEnabled(): Promise<boolean> {
131 return Promise.resolve(true);
132 }
133
134 getUniqueId(): Promise<string> {
135 return Promise.resolve("NOT_UNIQUE");
136 }
137
138 getWorkspaceConfigs(): Promise<ContinueRcJson[]> {
139 return Promise.resolve([]);
140 }
141
142 getDiff(includeUnstaged: boolean): Promise<string[]> {
143 return Promise.resolve([]);
144 }
145
146 getClipboardContent(): Promise<{ text: string; copiedAt: string }> {
147 return Promise.resolve({ text: "", copiedAt: new Date().toISOString() });
148 }
149
150 getTerminalContents(): Promise<string> {
151 return Promise.resolve("");
152 }
153
154 async getDebugLocals(threadIndex: number): Promise<string> {
155 return Promise.resolve("");
156 }
157
158 async getTopLevelCallStackSources(
159 threadIndex: number,
160 stackDepth: number,
161 ): Promise<string[]> {
162 return Promise.resolve([]);
163 }
164
165 async getAvailableThreads(): Promise<Thread[]> {
166 return Promise.resolve([]);
167 }
168
169 showLines(
170 fileUri: string,
171 startLine: number,
172 endLine: number,
173 ): Promise<void> {
174 return Promise.resolve();
175 }
176
177 getWorkspaceDirs(): Promise<string[]> {
178 return Promise.resolve([this.workspaceDir]);
179 }
180
181 writeFile(fileUri: string, contents: string): Promise<void> {
182 const filepath = fileURLToPath(fileUri);
183 return new Promise((resolve, reject) => {
184 fs.writeFile(filepath, contents, (err) => {
185 if (err) {
186 reject(err);
187 }
188 resolve();
189 });
190 });
191 }
192
193 showVirtualFile(title: string, contents: string): Promise<void> {
194 return Promise.resolve();
195 }
196
197 openFile(path: string): Promise<void> {
198 return Promise.resolve();
199 }
200
201 openUrl(url: string): Promise<void> {
202 return Promise.resolve();
203 }
204
205 runCommand(command: string, options?: TerminalOptions): Promise<void> {
206 return Promise.resolve();
207 }
208
209 saveFile(fileUri: string): Promise<void> {
210 return Promise.resolve();
211 }
212
213 readFile(fileUri: string): Promise<string> {
214 const filepath = fileURLToPath(fileUri);
215 return new Promise((resolve, reject) => {
216 fs.readFile(filepath, "utf8", (err, contents) => {
217 if (err) {
218 reject(err);
219 }
220 resolve(contents);
221 });
222 });
223 }
224
225 getCurrentFile(): Promise<undefined> {
226 return Promise.resolve(undefined);
227 }
228
229 getBranch(dir: string): Promise<string> {
230 return Promise.resolve("");
231 }
232
233 getOpenFiles(): Promise<string[]> {
234 return Promise.resolve([]);
235 }
236
237 getPinnedFiles(): Promise<string[]> {
238 return Promise.resolve([]);
239 }
240
241 async getSearchResults(query: string, maxResults?: number): Promise<string> {
242 return "";
243 }
244
245 async getFileResults(
246 pattern: string,
247 maxResults?: number,
248 ): Promise<string[]> {
249 return [];
250 }
251
252 async getProblems(fileUri?: string | undefined): Promise<Problem[]> {
253 return Promise.resolve([]);
254 }
255
256 async subprocess(command: string, cwd?: string): Promise<[string, string]> {
257 return ["", ""];
258 }
259}
260
261export default FileSystemIde;