Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit b489a8f

Browse files
elektronikworkshopadiazulay
authored andcommitted
Run IntelliSense analysis for every build
* Run IntelliSense analysis for every build * Added global enum for log level
1 parent 88e544a commit b489a8f

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

src/arduino/arduino.ts

+17-24
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { IArduinoSettings } from "./arduinoSettings";
1616
import { BoardManager } from "./boardManager";
1717
import { ExampleManager } from "./exampleManager";
1818
import { AnalysisManager,
19-
ICoCoPaContext,
2019
isCompilerParserEnabled,
2120
makeCompilerParserContext } from "./intellisense";
2221
import { LibraryManager } from "./libraryManager";
@@ -202,7 +201,8 @@ export class ArduinoApp {
202201
const dc = DeviceContext.getInstance();
203202
const args: string[] = [];
204203
let restoreSerialMonitor: boolean = false;
205-
let cocopa: ICoCoPaContext;
204+
const cocopa = makeCompilerParserContext(dc);
205+
const verbose = VscodeSettings.getInstance().logLevel === constants.LogLevel.Verbose;
206206

207207
if (!this.boardManager.currentBoard) {
208208
if (buildMode !== BuildMode.Analyze) {
@@ -277,7 +277,6 @@ export class ArduinoApp {
277277
await selectSerial();
278278
return false;
279279
}
280-
281280
if (!compile && !this.useArduinoCli()) {
282281
arduinoChannel.error("This command is only available when using the Arduino CLI");
283282
return false;
@@ -302,12 +301,10 @@ export class ArduinoApp {
302301
}
303302

304303
args.push("--port", dc.port);
305-
} else if (buildMode === BuildMode.Analyze) {
306-
cocopa = makeCompilerParserContext(dc);
307304
if (!this.useArduinoCli()) {
308-
args.push("--verify", "--verbose");
305+
args.push("--verify");
309306
} else {
310-
args.push("compile", "--verbose", "-b", boardDescriptor);
307+
args.push("compile", "-b", boardDescriptor);
311308
}
312309
} else {
313310
if (!this.useArduinoCli()) {
@@ -317,10 +314,8 @@ export class ArduinoApp {
317314
}
318315
}
319316

320-
const verbose = VscodeSettings.getInstance().logLevel === "verbose";
321-
if (buildMode !== BuildMode.Analyze && verbose) {
322-
args.push("--verbose");
323-
}
317+
// We always build verbosely but filter the output based on the settings
318+
args.push("--verbose");
324319

325320
await vscode.workspace.saveAll(false);
326321

@@ -365,33 +360,31 @@ export class ArduinoApp {
365360
args.push(path.join(ArduinoWorkspace.rootPath, dc.sketch));
366361

367362
const cleanup = async () => {
368-
if (cocopa) {
369-
await cocopa.conclude();
370-
}
363+
await cocopa.conclude();
371364
if (buildMode === BuildMode.Upload || buildMode === BuildMode.UploadProgrammer) {
372365
UsbDetector.getInstance().resumeListening();
373366
if (restoreSerialMonitor) {
374367
await SerialMonitor.getInstance().openSerialMonitor();
375368
}
376369
}
377370
}
371+
const stdoutcb = (line: string) => {
372+
cocopa.callback(line);
373+
if (verbose) {
374+
arduinoChannel.channel.append(line);
375+
}
376+
}
377+
const stderrcb = (line: string) => {
378+
arduinoChannel.channel.append(line);
379+
}
378380

379381
return await util.spawn(
380382
this._settings.commandPath,
381383
args,
382384
undefined,
383-
{
384-
channel: !cocopa || cocopa && verbose ? arduinoChannel.channel : undefined,
385-
stdout: cocopa ? cocopa.callback : undefined,
386-
},
385+
{ stdout: stdoutcb, stderr: stderrcb },
387386
).then(async () => {
388387
await cleanup();
389-
if (buildMode !== BuildMode.Analyze) {
390-
const cmd = os.platform() === "darwin"
391-
? "Cmd + Alt + I"
392-
: "Ctrl + Alt + I";
393-
arduinoChannel.info(`To rebuild your IntelliSense configuration run "${cmd}"`);
394-
}
395388
arduinoChannel.end(`${buildMode} sketch '${dc.sketch}'${os.EOL}`);
396389
return true;
397390
}, async (reason) => {

src/arduino/intellisense.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
import * as ccp from "cocopa";
55
import * as fs from "fs";
6+
import * as os from "os";
67
import * as path from "path";
78
import * as tp from "typed-promisify";
89

910
import * as constants from "../common/constants";
1011
import { arduinoChannel } from "../common/outputChannel";
1112
import { ArduinoWorkspace } from "../common/workspace";
1213
import { DeviceContext } from "../deviceContext";
13-
1414
import { VscodeSettings } from "./vscodeSettings";
1515

1616
export interface ICoCoPaContext {
@@ -103,6 +103,10 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
103103
const estr = JSON.stringify(e);
104104
arduinoChannel.error(`Failed to read or write IntelliSense configuration: ${estr}`);
105105
}
106+
const cmd = os.platform() === "darwin"
107+
? "Cmd + Alt + I"
108+
: "Ctrl + Alt + I";
109+
arduinoChannel.info(`To manually rebuild your IntelliSense configuration run "${cmd}"`);
106110
};
107111
return {
108112
callback: runner.callback(),

src/common/constants.ts

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export const CPP_CONFIG_FILE = path.join(".vscode", "c_cpp_properties.json");
1010
/** The name of the intellisense configuration managed by vscode-arduino. */
1111
export const C_CPP_PROPERTIES_CONFIG_NAME = "Arduino";
1212

13+
export enum LogLevel {
14+
Info = "info",
15+
Verbose = "verbose",
16+
};
17+
1318
export const ARDUINO_MODE: vscode.DocumentSelector = [
1419
{ language: "cpp", scheme: "file" },
1520
{ language: "arduino", scheme: "file" },

src/debug/configurationProvider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ArduinoActivator from "../arduinoActivator";
99
import ArduinoContext from "../arduinoContext";
1010

1111
import { VscodeSettings } from "../arduino/vscodeSettings";
12+
import * as constants from "../common/constants";
1213
import * as platform from "../common/platform";
1314
import * as util from "../common/util";
1415
import { ArduinoWorkspace } from "../common/workspace";
@@ -77,7 +78,7 @@ export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurat
7778
await ArduinoActivator.activate();
7879
}
7980

80-
if (VscodeSettings.getInstance().logLevel === "verbose" && !config.logging) {
81+
if (VscodeSettings.getInstance().logLevel === constants.LogLevel.Verbose && !config.logging) {
8182
config = {
8283
...config, logging: {
8384
engineLogging: true,

0 commit comments

Comments
 (0)