|
|
@@ -77,15 +77,41 @@ export class Modula2DebugAdapterContribution implements DebugAdapterContribution
|
|
|
}
|
|
|
|
|
|
provideDebugAdapterExecutable(): MaybePromise<DebugAdapterExecutable | undefined> {
|
|
|
- // lib/node/debug-adapter-contribution.js -> lib/adapter/gdb-adapter.js
|
|
|
- const adapter = path.join(__dirname, '..', 'adapter', 'gdb-adapter.js');
|
|
|
+ const adapter = findAdapterModule();
|
|
|
+ return adapter ? { modulePath: adapter, args: [] } : undefined;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/** Locate the forkable debug adapter module in packaged and dev layouts.
|
|
|
+ *
|
|
|
+ * The backend runs bundled (esbuild), so `__dirname` points at the app's
|
|
|
+ * `lib/backend` and cannot be used to find extension files. Instead:
|
|
|
+ * packaged apps ship the adapter under `resources/adapter` (see the
|
|
|
+ * electron-builder `extraResources` entry); dev resolves through the
|
|
|
+ * workspace symlink.
|
|
|
+ */
|
|
|
+export function findAdapterModule(): string | undefined {
|
|
|
+ const candidates: string[] = [];
|
|
|
+ try {
|
|
|
+ const resources = (process as { resourcesPath?: string }).resourcesPath;
|
|
|
+ if (resources) candidates.push(path.join(resources, 'adapter', 'gdb-adapter.js'));
|
|
|
+ } catch {
|
|
|
+ // No Electron runtime: fall through to module resolution.
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ candidates.push(require.resolve('modula2-debug/lib/adapter/gdb-adapter.js'));
|
|
|
+ } catch {
|
|
|
+ // Not resolvable from here.
|
|
|
+ }
|
|
|
+ for (const candidate of candidates) {
|
|
|
try {
|
|
|
- fs.accessSync(adapter, fs.constants.R_OK);
|
|
|
+ fs.accessSync(candidate, fs.constants.R_OK);
|
|
|
+ return candidate;
|
|
|
} catch {
|
|
|
- return undefined;
|
|
|
+ // Try the next candidate.
|
|
|
}
|
|
|
- return { modulePath: adapter, args: [] };
|
|
|
}
|
|
|
+ return undefined;
|
|
|
}
|
|
|
|
|
|
/** Preferred program from modula2.json (bin/<name> or output), else undefined. */
|