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

Commit

Permalink
Run IntelliSense analysis for every build
Browse files Browse the repository at this point in the history
* Run IntelliSense analysis for every build
* Added global enum for log level
  • Loading branch information
elektronikworkshop authored and adiazulay committed Jan 19, 2021
1 parent 88e544a commit b489a8f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
41 changes: 17 additions & 24 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { IArduinoSettings } from "./arduinoSettings";
import { BoardManager } from "./boardManager";
import { ExampleManager } from "./exampleManager";
import { AnalysisManager,
ICoCoPaContext,
isCompilerParserEnabled,
makeCompilerParserContext } from "./intellisense";
import { LibraryManager } from "./libraryManager";
Expand Down Expand Up @@ -202,7 +201,8 @@ export class ArduinoApp {
const dc = DeviceContext.getInstance();
const args: string[] = [];
let restoreSerialMonitor: boolean = false;
let cocopa: ICoCoPaContext;
const cocopa = makeCompilerParserContext(dc);
const verbose = VscodeSettings.getInstance().logLevel === constants.LogLevel.Verbose;

if (!this.boardManager.currentBoard) {
if (buildMode !== BuildMode.Analyze) {
Expand Down Expand Up @@ -277,7 +277,6 @@ export class ArduinoApp {
await selectSerial();
return false;
}

if (!compile && !this.useArduinoCli()) {
arduinoChannel.error("This command is only available when using the Arduino CLI");
return false;
Expand All @@ -302,12 +301,10 @@ export class ArduinoApp {
}

args.push("--port", dc.port);
} else if (buildMode === BuildMode.Analyze) {
cocopa = makeCompilerParserContext(dc);
if (!this.useArduinoCli()) {
args.push("--verify", "--verbose");
args.push("--verify");
} else {
args.push("compile", "--verbose", "-b", boardDescriptor);
args.push("compile", "-b", boardDescriptor);
}
} else {
if (!this.useArduinoCli()) {
Expand All @@ -317,10 +314,8 @@ export class ArduinoApp {
}
}

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

await vscode.workspace.saveAll(false);

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

const cleanup = async () => {
if (cocopa) {
await cocopa.conclude();
}
await cocopa.conclude();
if (buildMode === BuildMode.Upload || buildMode === BuildMode.UploadProgrammer) {
UsbDetector.getInstance().resumeListening();
if (restoreSerialMonitor) {
await SerialMonitor.getInstance().openSerialMonitor();
}
}
}
const stdoutcb = (line: string) => {
cocopa.callback(line);
if (verbose) {
arduinoChannel.channel.append(line);
}
}
const stderrcb = (line: string) => {
arduinoChannel.channel.append(line);
}

return await util.spawn(
this._settings.commandPath,
args,
undefined,
{
channel: !cocopa || cocopa && verbose ? arduinoChannel.channel : undefined,
stdout: cocopa ? cocopa.callback : undefined,
},
{ stdout: stdoutcb, stderr: stderrcb },
).then(async () => {
await cleanup();
if (buildMode !== BuildMode.Analyze) {
const cmd = os.platform() === "darwin"
? "Cmd + Alt + I"
: "Ctrl + Alt + I";
arduinoChannel.info(`To rebuild your IntelliSense configuration run "${cmd}"`);
}
arduinoChannel.end(`${buildMode} sketch '${dc.sketch}'${os.EOL}`);
return true;
}, async (reason) => {
Expand Down
6 changes: 5 additions & 1 deletion src/arduino/intellisense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import * as ccp from "cocopa";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as tp from "typed-promisify";

import * as constants from "../common/constants";
import { arduinoChannel } from "../common/outputChannel";
import { ArduinoWorkspace } from "../common/workspace";
import { DeviceContext } from "../deviceContext";

import { VscodeSettings } from "./vscodeSettings";

export interface ICoCoPaContext {
Expand Down Expand Up @@ -103,6 +103,10 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
const estr = JSON.stringify(e);
arduinoChannel.error(`Failed to read or write IntelliSense configuration: ${estr}`);
}
const cmd = os.platform() === "darwin"
? "Cmd + Alt + I"
: "Ctrl + Alt + I";
arduinoChannel.info(`To manually rebuild your IntelliSense configuration run "${cmd}"`);
};
return {
callback: runner.callback(),
Expand Down
5 changes: 5 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export const CPP_CONFIG_FILE = path.join(".vscode", "c_cpp_properties.json");
/** The name of the intellisense configuration managed by vscode-arduino. */
export const C_CPP_PROPERTIES_CONFIG_NAME = "Arduino";

export enum LogLevel {
Info = "info",
Verbose = "verbose",
};

export const ARDUINO_MODE: vscode.DocumentSelector = [
{ language: "cpp", scheme: "file" },
{ language: "arduino", scheme: "file" },
Expand Down
3 changes: 2 additions & 1 deletion src/debug/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ArduinoActivator from "../arduinoActivator";
import ArduinoContext from "../arduinoContext";

import { VscodeSettings } from "../arduino/vscodeSettings";
import * as constants from "../common/constants";
import * as platform from "../common/platform";
import * as util from "../common/util";
import { ArduinoWorkspace } from "../common/workspace";
Expand Down Expand Up @@ -77,7 +78,7 @@ export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurat
await ArduinoActivator.activate();
}

if (VscodeSettings.getInstance().logLevel === "verbose" && !config.logging) {
if (VscodeSettings.getInstance().logLevel === constants.LogLevel.Verbose && !config.logging) {
config = {
...config, logging: {
engineLogging: true,
Expand Down

0 comments on commit b489a8f

Please sign in to comment.