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 94ceefd

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Can enable debug logging of the gRPC calls.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 27dd120 commit 94ceefd

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
@@ -182,6 +182,14 @@ export const ArduinoConfigSchema: PreferenceSchema = {
182182
),
183183
default: true,
184184
},
185+
'arduino.cli.daemon.debug': {
186+
type: 'boolean',
187+
description: nls.localize(
188+
'arduino/preferences/cli.daemonDebug',
189+
"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."
190+
),
191+
default: false,
192+
},
185193
},
186194
};
187195

@@ -207,6 +215,7 @@ export interface ArduinoConfiguration {
207215
'arduino.auth.audience': string;
208216
'arduino.auth.registerUri': string;
209217
'arduino.survey.notification': boolean;
218+
'arduino.cli.daemon.debug': boolean;
210219
}
211220

212221
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. 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)

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