Elffuss BraidHub

kikocis/continue public

80eede9a6f83 · 4.3 KiBRawPermalink
1import { IDE } from "../../index";
2import { ToIdeFromWebviewOrCoreProtocol } from "../ide";
3
4import { Message } from ".";
5
6export class ReverseMessageIde {
7 private on<T extends keyof ToIdeFromWebviewOrCoreProtocol>(
8 messageType: T,
9 handler: (
10 data: ToIdeFromWebviewOrCoreProtocol[T][0],
11 ) =>
12 | Promise<ToIdeFromWebviewOrCoreProtocol[T][1]>
13 | ToIdeFromWebviewOrCoreProtocol[T][1],
14 ): void {
15 this._on(messageType, (msg) => {
16 const data = msg.data;
17 const result = handler(data);
18 return result;
19 });
20 }
21
22 constructor(
23 private readonly _on: <T extends keyof ToIdeFromWebviewOrCoreProtocol>(
24 messageType: T,
25 handler: (
26 message: Message<ToIdeFromWebviewOrCoreProtocol[T][0]>,
27 ) =>
28 | Promise<ToIdeFromWebviewOrCoreProtocol[T][1]>
29 | ToIdeFromWebviewOrCoreProtocol[T][1],
30 ) => void,
31 private readonly ide: IDE,
32 ) {
33 this.initializeListeners();
34 }
35
36 private initializeListeners() {
37 this.on("getFileStats", (data) => {
38 return this.ide.getFileStats(data.files);
39 });
40
41 this.on("getGitRootPath", (data) => {
42 return this.ide.getGitRootPath(data.dir);
43 });
44
45 this.on("listDir", (data) => {
46 return this.ide.listDir(data.dir);
47 });
48
49 this.on("showToast", (data) => {
50 return this.ide.showToast(...data);
51 });
52
53 this.on("getRepoName", (data) => {
54 return this.ide.getRepoName(data.dir);
55 });
56
57 this.on("getDebugLocals", (data) => {
58 return this.ide.getDebugLocals(data.threadIndex);
59 });
60
61 this.on("getTopLevelCallStackSources", (data) => {
62 return this.ide.getTopLevelCallStackSources(
63 data.threadIndex,
64 data.stackDepth,
65 );
66 });
67
68 this.on("getAvailableThreads", () => {
69 return this.ide.getAvailableThreads();
70 });
71
72 this.on("getTags", (data) => {
73 return this.ide.getTags(data);
74 });
75
76 this.on("getIdeInfo", () => {
77 return this.ide.getIdeInfo();
78 });
79
80 this.on("readRangeInFile", (data) => {
81 return this.ide.readRangeInFile(data.filepath, data.range);
82 });
83
84 this.on("isTelemetryEnabled", () => {
85 return this.ide.isTelemetryEnabled();
86 });
87
88 this.on("getUniqueId", () => {
89 return this.ide.getUniqueId();
90 });
91
92 this.on("getIdeSettings", () => {
93 return this.ide.getIdeSettings();
94 });
95
96 this.on("getDiff", (data) => {
97 return this.ide.getDiff(data.includeUnstaged);
98 });
99
100 this.on("getTerminalContents", () => {
101 return this.ide.getTerminalContents();
102 });
103
104 this.on("getWorkspaceDirs", () => {
105 return this.ide.getWorkspaceDirs();
106 });
107
108 this.on("showLines", (data) => {
109 return this.ide.showLines(data.filepath, data.startLine, data.endLine);
110 });
111
112 this.on("getControlPlaneSessionInfo", async (msg) => {
113 // Not supported in testing
114 return undefined;
115 });
116
117 this.on("writeFile", (data) => {
118 return this.ide.writeFile(data.path, data.contents);
119 });
120
121 this.on("fileExists", (data) => {
122 return this.ide.fileExists(data.filepath);
123 });
124
125 this.on("showVirtualFile", (data) => {
126 return this.ide.showVirtualFile(data.name, data.content);
127 });
128
129 this.on("openFile", (data) => {
130 return this.ide.openFile(data.path);
131 });
132
133 this.on("runCommand", (data) => {
134 return this.ide.runCommand(data.command);
135 });
136
137 this.on("saveFile", (data) => {
138 return this.ide.saveFile(data.filepath);
139 });
140
141 this.on("readFile", (data) => {
142 return this.ide.readFile(data.filepath);
143 });
144
145 this.on("getOpenFiles", () => {
146 return this.ide.getOpenFiles();
147 });
148
149 this.on("getCurrentFile", () => {
150 return this.ide.getCurrentFile();
151 });
152
153 this.on("getPinnedFiles", () => {
154 return this.ide.getPinnedFiles();
155 });
156
157 this.on("getSearchResults", (data) => {
158 return this.ide.getSearchResults(data.query, data.maxResults);
159 });
160
161 this.on("getFileResults", (data) => {
162 return this.ide.getFileResults(data.pattern, data.maxResults);
163 });
164
165 this.on("getProblems", (data) => {
166 return this.ide.getProblems(data.filepath);
167 });
168
169 this.on("subprocess", (data) => {
170 return this.ide.subprocess(data.command, data.cwd);
171 });
172
173 this.on("getBranch", (data) => {
174 return this.ide.getBranch(data.dir);
175 });
176 }
177}