Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5dd78be

Browse files
author
Akos Kitta
committedNov 13, 2023
feat: show progress for debug --info
1 parent ef90459 commit 5dd78be

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed
 

‎src/debug.ts

+36-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ export function activateDebug(_: vscode.ExtensionContext): vscode.Disposable {
2121
vscode.commands.registerCommand(
2222
'arduino.debug.start',
2323
async (params: StartDebugParams) => {
24-
const launchConfig = await createLaunchConfig(params);
25-
return startDebug(params.launchConfigsDirPath, launchConfig);
24+
try {
25+
const launchConfig = await createLaunchConfig(params);
26+
return startDebug(params.launchConfigsDirPath, launchConfig);
27+
} catch (err) {
28+
if (err instanceof vscode.CancellationError) {
29+
return;
30+
}
31+
throw err;
32+
}
2633
}
2734
),
2835
vscode.commands.registerCommand(
@@ -60,6 +67,10 @@ export interface StartDebugParams {
6067
* Programmer for the debugging.
6168
*/
6269
readonly programmer?: string;
70+
/**
71+
* Custom progress message to use when getting the debug information from the CLI.
72+
*/
73+
readonly message?: string;
6374
}
6475
export type StartDebugResult = boolean;
6576

@@ -124,6 +135,8 @@ async function startDebug(
124135
return vscode.debug.startDebugging(undefined, launchConfig);
125136
}
126137

138+
const getDebugInfoMessage = 'Getting debug info...';
139+
127140
async function createLaunchConfig(
128141
params: StartDebugParams
129142
): Promise<ArduinoDebugLaunchConfig> {
@@ -133,7 +146,10 @@ async function createLaunchConfig(
133146
}
134147
const { file, args } = buildDebugInfoArgs(params);
135148
const [stdout, customConfigs] = await Promise.all([
136-
exec(file, args),
149+
withProgress(
150+
() => exec(file, args),
151+
params.message ? params.message : getDebugInfoMessage
152+
),
137153
loadDebugCustomJson(params),
138154
]);
139155
const debugInfo = await parseRawDebugInfo(stdout);
@@ -151,6 +167,23 @@ async function createLaunchConfig(
151167
return launchConfig;
152168
}
153169

170+
async function withProgress<T>(
171+
task: () => Promise<T> | T,
172+
message: string
173+
): Promise<T> {
174+
return vscode.window.withProgress(
175+
{ location: vscode.ProgressLocation.Window },
176+
async (progress, token) => {
177+
if (token.isCancellationRequested) {
178+
throw new vscode.CancellationError();
179+
}
180+
progress.report({ message });
181+
const result = await task();
182+
return result as T;
183+
}
184+
);
185+
}
186+
154187
async function parseRawDebugInfo(
155188
raw: string
156189
): Promise<(DebugInfo & Executable) | undefined> {

‎src/ino.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ async function buildLanguageClient(
187187
String(daemonAddress.instance),
188188
'-fqbn',
189189
board.fqbn,
190-
'-skip-libraries-discovery-on-rebuild', // The Arduino IDE
190+
'-skip-libraries-discovery-on-rebuild', // The default Arduino IDE behavior
191191
];
192192
if (board.name) {
193193
args.push('-board-name', board.name);
@@ -201,7 +201,7 @@ async function buildLanguageClient(
201201
if (flags && flags.length) {
202202
args.push(...flags);
203203
}
204-
if (!!log) {
204+
if (log) {
205205
args.push('-log');
206206
let logPath: string | undefined = undefined;
207207
if (typeof log === 'string') {
@@ -296,6 +296,3 @@ function noopOutputChannel(name: string): vscode.OutputChannel {
296296
name,
297297
};
298298
}
299-
300-
const __tests__ = {} as const;
301-
export { __tests__ };

0 commit comments

Comments
 (0)
Please sign in to comment.