Skip to content

Commit 6e97863

Browse files
author
Akos Kitta
committed
Can enable debug logging of the gRPC calls.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 4c62431 commit 6e97863

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-preferences.ts

+9
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ export const ArduinoConfigSchema: PreferenceSchema = {
174174
),
175175
default: 'https://auth.arduino.cc/login#/register',
176176
},
177+
'arduino.cli.daemon.debug': {
178+
type: 'boolean',
179+
description: nls.localize(
180+
'arduino/preferences/cli.daemonDebug',
181+
"Enable debug logging of the gRPC calls to the Arduino CLI. A restart of the IDE is needed for this setting to take effect. It's false by default."
182+
),
183+
default: false,
184+
},
177185
},
178186
};
179187

@@ -198,6 +206,7 @@ export interface ArduinoConfiguration {
198206
'arduino.auth.domain': string;
199207
'arduino.auth.audience': string;
200208
'arduino.auth.registerUri': string;
209+
'arduino.cli.daemon.debug': boolean;
201210
}
202211

203212
export const ArduinoPreferences = Symbol('ArduinoPreferences');

Diff for: arduino-ide-extension/src/node/arduino-daemon-impl.ts

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { join } from 'path';
2+
import { promises as fs } from 'fs';
23
import { inject, injectable, named } from '@theia/core/shared/inversify';
34
import { spawn, ChildProcess } from 'child_process';
45
import { FileUri } from '@theia/core/lib/node/file-uri';
@@ -142,9 +143,12 @@ export class ArduinoDaemonImpl
142143
}
143144

144145
protected async getSpawnArgs(): Promise<string[]> {
145-
const configDirUri = await this.envVariablesServer.getConfigDirUri();
146+
const [configDirUri, debug] = await Promise.all([
147+
this.envVariablesServer.getConfigDirUri(),
148+
this.debugDaemon(),
149+
]);
146150
const cliConfigPath = join(FileUri.fsPath(configDirUri), CLI_CONFIG);
147-
return [
151+
const args = [
148152
'daemon',
149153
'--format',
150154
'jsonmini',
@@ -156,6 +160,41 @@ export class ArduinoDaemonImpl
156160
'--log-format',
157161
'json',
158162
];
163+
if (debug) {
164+
args.push('--debug');
165+
}
166+
return args;
167+
}
168+
169+
private async debugDaemon(): Promise<boolean> {
170+
// Poor man's preferences on the backend. (https://github.com/arduino/arduino-ide/issues/1056#issuecomment-1153975064)
171+
const configDirUri = await this.envVariablesServer.getConfigDirUri();
172+
const configDirPath = FileUri.fsPath(configDirUri);
173+
try {
174+
const raw = await fs.readFile(join(configDirPath, 'settings.json'), {
175+
encoding: 'utf8',
176+
});
177+
const json = this.tryParse(raw);
178+
if (json) {
179+
const value = json['arduino.cli.daemon.debug'];
180+
return typeof value === 'boolean' && !!value;
181+
}
182+
return false;
183+
} catch (error) {
184+
if ('code' in error && error.code === 'ENOENT') {
185+
return false;
186+
}
187+
throw error;
188+
}
189+
}
190+
191+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
192+
private tryParse(raw: string): any | undefined {
193+
try {
194+
return JSON.parse(raw);
195+
} catch {
196+
return undefined;
197+
}
159198
}
160199

161200
protected async spawnDaemonProcess(): Promise<{

Diff for: i18n/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
"board.certificates": "List of certificates that can be uploaded to boards",
230230
"browse": "Browse",
231231
"choose": "Choose",
232+
"cli.daemonDebug": "Enable debug logging of the gRPC calls to the Arduino CLI. A restart of the IDE is needed for this setting to take effect. It's false by default.",
232233
"cloud.enabled": "True if the sketch sync functions are enabled. Defaults to true.",
233234
"cloud.pull.warn": "True if users should be warned before pulling a cloud sketch. Defaults to true.",
234235
"cloud.push.warn": "True if users should be warned before pushing a cloud sketch. Defaults to true.",

0 commit comments

Comments
 (0)