zero-plusplus / vscode-autohotkey-debug

https://marketplace.visualstudio.com/items?itemName=zero-plusplus.vscode-autohotkey-debug
52 stars 4 forks source link

The `extends` attribute in launch.json does not work in the multi-root workspace and throws an error #285

Open zero-plusplus opened 1 year ago

zero-plusplus commented 1 year ago

RELATED: #284

The following is how to fix it.

// extension.ts
public resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
    if (config.extends) {
      // Correction point -----------------------------------------------------------------------
      const launch = folder
        ? JSON.parse(readFileSync(path.resolve(folder.uri.fsPath, '.vscode', 'launch.json'), 'utf-8'))
        : vscode.workspace.getConfiguration().get<Record<string, any>>('launch');
      // ----------------------------------------------------------------------------------------
      if (launch && 'configurations' in launch && Array.isArray(launch.configurations)) {
        const sourceConfig = launch.configurations.find((conf) => equalsIgnoreCase(conf.name, config.extends));
        if (!sourceConfig) {
          throw Error(`No matching configuration found. Please modify the \`extends\` attribute. \nSpecified: ${String(config.extends)}`);
        }
        defaults(config, sourceConfig);
      }
    }
    // ...
}

When using workspace, no method was found to get the current debug configurations. Therefore, reading launch.json directly solves this problem.

The above solution is probably not a legitimate method. In the first place, vscode developers may not expect to refer to other debug configuration such as extends.