Prechádzať zdrojové kódy

Debug launch fix: resolve adapter executable in bundled and packaged layouts

- findAdapterModule(): resources/adapter when packaged, require.resolve
  in dev; the old __dirname-relative path never existed in the esbuild
  bundle, so Theia reported the registered modula2 type as unsupported
- ship the adapter dir as extraResources outside asar
- builds now pass -g so breakpoints bind; hello example is debuggable
  and ships a working .vscode/launch.json
Eric Streit 1 týždeň pred
rodič
commit
16fa047279

+ 5 - 1
apps/electron/package.json

@@ -56,7 +56,11 @@
       "package.json"
     ],
     "extraResources": [
-      "plugins"
+      "plugins",
+      {
+        "from": "../../extensions/modula2-debug/lib/adapter",
+        "to": "adapter"
+      }
     ],
     "linux": {
       "target": [

+ 13 - 0
examples/hello/.vscode/launch.json

@@ -0,0 +1,13 @@
+{
+  "version": "0.2.0",
+  "configurations": [
+    modula2
+    {
+      "type": "modula2",
+      "request": "launch",
+      "name": "Debug Hello",
+      "program": "${workspaceFolder}/bin/Hello",
+      "cwd": "${workspaceFolder}"
+    }
+  ]
+}

+ 19 - 1
examples/hello/src/Main.mod

@@ -1,5 +1,23 @@
 MODULE Main;
 
+FROM InOut IMPORT WriteString, WriteLn;
+
+VAR
+  count: INTEGER;
+
+PROCEDURE Next(n: INTEGER): INTEGER;
+BEGIN
+  RETURN n + 1;
+END Next;
+
 BEGIN
-    (* Initial Modula-2 program *)
+  count := 0;
+  WHILE count < 3 DO
+    WriteString("Hello, Modula-2!");
+    WriteLn;
+    count := Next(count);
+  END;
 END Main.
+
+
+

+ 1 - 1
extensions/modula2-compiler/src/common/compiler.ts

@@ -113,7 +113,7 @@ export interface ProvidedTask {
 /** Pure task list for a project (tested headlessly; the Theia provider wraps these). */
 export function buildProvidedTasks(project: Modula2Project): ProvidedTask[] {
   const out = defaultOutput(project);
-  const buildArgs = ['-fiso', ...project.compiler.options, '-o', out, project.main];
+  const buildArgs = ['-fiso', '-g', ...project.compiler.options, '-o', out, project.main];
   return [
     { label: 'Modula-2: Build', group: { kind: 'build', isDefault: true }, command: project.compiler.path, args: buildArgs },
     { label: 'Modula-2: Clean', group: 'clean', command: 'rm', args: ['-f', out] },

+ 1 - 1
extensions/modula2-compiler/src/node/compiler-service.ts

@@ -66,7 +66,7 @@ export class GnuModula2CompilerService implements Modula2Compiler {
   async build(project: Modula2Project): Promise<BuildResult> {
     const out = defaultOutput(project);
     await fs.promises.mkdir(path.dirname(path.join(project.root, out)), { recursive: true });
-    const args = ['-fiso', ...project.compiler.options, '-o', out, project.main];
+    const args = ['-fiso', '-g', ...project.compiler.options, '-o', out, project.main];
     const command = [project.compiler.path, ...args].join(' ');
     let result: ProcessResult;
     try {

+ 31 - 5
extensions/modula2-debug/src/node/debug-adapter-contribution.ts

@@ -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. */