Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c84c58c

Browse files
author
Akos Kitta
committed
Can enable debug logging of the gRPC calls.
Closes #1056 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 4c62431 commit c84c58c

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

‎arduino-ide-extension/src/browser/arduino-preferences.ts‎

Lines changed: 9 additions & 0 deletions
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. 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');

‎arduino-ide-extension/src/node/arduino-daemon-impl.ts‎

Lines changed: 41 additions & 2 deletions
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+
constargs= [
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<{

‎i18n/en.json‎

Lines changed: 1 addition & 0 deletions
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. 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)

AltStyle によって変換されたページ (->オリジナル) /