vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.42k stars 237 forks source link

LLDB: Overwrite Launch Configurations from Cargo.toml #1099

Open punowo opened 1 month ago

punowo commented 1 month ago

Would something like this be needed / accepted ? I find myself copying, creating .vscode/launch.json and pasting the contents of the already existing similar command a lot and I would love to just have a command that does all this.

I'm already creating a mini vscode extension that acts as a wrapper around "lldb.getCargoLaunchConfigs" but I was thinking maybe something like this can be a pull request for this extension.

function activate(context) {
  let disposable = vscode.commands.registerCommand(
    "cargo-quick-config.generateStuff",
    async function () {
      await vscode.commands.executeCommand("lldb.getCargoLaunchConfigs");
      if (vscode.window.activeTextEditor.document.isUntitled) {
        const content = vscode.window.activeTextEditor.document.getText();
        const workSpaceFolder = vscode.workspace.workspaceFolders
          ? vscode.workspace.workspaceFolders[0].uri.fsPath
          : null;

        if (workSpaceFolder) {
          const filePath = path.join(workSpaceFolder, "MyNewLaunch.json");
          fs.writeFileSync(filePath, content);
          await vscode.commands.executeCommand(
            "workbench.action.revertAndCloseActiveEditor"
          );

          // Use the command to close the active editor
          await vscode.commands.executeCommand(
            "workbench.action.closeActiveEditor"
          );
        } else {
          vscode.window.showWarningMessage("No workspace folder found.");
        }
      }
    }
  );

  context.subscriptions.push(disposable);
}