Skip to content

fix: use CLI config path for debug command #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-arduino-tools",
"private": true,
"version": "0.0.2-beta.7",
"version": "0.0.2-beta.8",
"publisher": "arduino",
"license": "Apache-2.0",
"author": "Arduino SA",
Expand Down
12 changes: 11 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import { promises as fs } from 'fs';
import { homedir } from 'os';
import { spawn } from 'child_process';
import deepEqual from 'deep-equal';
import WebRequest from 'web-request';
Expand Down Expand Up @@ -44,6 +45,10 @@ interface DebugConfig {
* If not defined, it falls back to `sketchPath/.vscode/launch.json`.
*/
readonly configPath?: string;
/**
* Absolute path to the `arduino-cli.yaml` file. If not specified, it falls back to `~/.arduinoIDE/arduino-cli.yaml`.
*/
readonly cliConfigPath?: string;
}

interface DebugInfo {
Expand Down Expand Up @@ -133,10 +138,15 @@ async function exec(command: string, args: string[]): Promise<{ stdout: string,
});
}

function resolveCliConfigPath(config: DebugConfig): string {
return config.cliConfigPath ?? path.join(homedir(), '.arduinoIDE', 'arduino-cli.yaml');
}

async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boolean> {
const cliConfigPath = resolveCliConfigPath(config);
let info: DebugInfo | undefined = undefined;
try {
const args = ['debug', '-I', '-b', config.board.fqbn, config.sketchPath, '--format', 'json'];
const args = ['debug', '-I', '-b', config.board.fqbn, config.sketchPath, '--format', 'json', '--config-file', cliConfigPath];
const { stdout, stderr } = await exec(config?.cliPath || '.', args);
if (!stdout && stderr) {
throw new Error(stderr);
Expand Down