From 981b63b5b08d16bdacbfe564463c0da3d58e6ea3 Mon Sep 17 00:00:00 2001 From: Adi Azulay Date: Wed, 18 Nov 2020 07:10:47 -0800 Subject: [PATCH 1/5] add hardware tool path --- src/arduino/arduino.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index 73619a7b..e6b0d104 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -577,6 +577,10 @@ Please make sure the folder is not occupied by other procedures .`); } const toolsPath = boardDescriptor.platform.rootBoardPath; result.push(path.normalize(path.join(toolsPath, "**"))); + const hardwareToolPath = path.join(toolsPath, "..", "..", "tools"); + if (fs.existsSync(hardwareToolPath)){ + result.push(path.normalize(path.join(hardwareToolPath, "**"))); + } // if (util.directoryExistsSync(path.join(toolsPath, "cores"))) { // const coreLibs = fs.readdirSync(path.join(toolsPath, "cores")); // if (coreLibs && coreLibs.length > 0) { From ea5756c0190da11b3f18b8e9d208a6499d3f8bca Mon Sep 17 00:00:00 2001 From: Adi Azulay Date: Thu, 19 Nov 2020 13:56:10 -0800 Subject: [PATCH 2/5] intellisense quick fix --- src/arduino/arduino.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index e6b0d104..7e082a01 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -320,15 +320,21 @@ export class ArduinoApp { return; } const cppConfigFile = fs.readFileSync(configFilePath, "utf8"); - const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ includePath: string[], forcedInclude: string[] }> }; + const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ + includePath: string[], + forcedInclude: string[], + defines: string[], + }> }; const libPaths = this.getDefaultPackageLibPaths(); const defaultForcedInclude = this.getDefaultForcedIncludeFiles(); + const defines = this.getDefualtDefines(); const configuration = cppConfig.configurations[0]; let cppConfigFileUpdated = false; // cpp exntension changes \\ to \\\\ in paths in JSON string, revert them first configuration.includePath = configuration.includePath.map((path) => path.replace(/\\\\/g, "\\")); configuration.forcedInclude = configuration.forcedInclude.map((path) => path.replace(/\\\\/g, "\\")); + configuration.defines = configuration.defines.map((path) => path.replace(/\\\\/g, "\\")); for (const libPath of libPaths) { if (configuration.includePath.indexOf(libPath) === -1) { @@ -343,6 +349,12 @@ export class ArduinoApp { } } + for (const define of defines) { + if (configuration.defines.indexOf(define) === -1) { + cppConfigFileUpdated = true; + configuration.defines.push(define); + } + } // remove all unexisting paths // concern mistake removal, comment temporary // for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) { @@ -386,6 +398,7 @@ export class ArduinoApp { } const defaultForcedInclude = this.getDefaultForcedIncludeFiles(); + const defaultDefines = this.getDefualtDefines(); if (!ArduinoWorkspace.rootPath) { return; @@ -444,6 +457,10 @@ export class ArduinoApp { configSection.forcedInclude = defaultForcedInclude.concat(configSection.forcedInclude); } + if (!configSection.defines) { + configSection.defines = defaultDefines; + } + fs.writeFileSync(configFilePath, JSON.stringify(deviceContext, null, 4)); } @@ -578,9 +595,15 @@ Please make sure the folder is not occupied by other procedures .`); const toolsPath = boardDescriptor.platform.rootBoardPath; result.push(path.normalize(path.join(toolsPath, "**"))); const hardwareToolPath = path.join(toolsPath, "..", "..", "tools"); - if (fs.existsSync(hardwareToolPath)){ + if (fs.existsSync(hardwareToolPath)) { result.push(path.normalize(path.join(hardwareToolPath, "**"))); - } + } + + // Add default libraries to include path + result.push(path.normalize(path.join(this._settings.defaultLibPath, "**"))); + + const userLibsPath = (path.join(this._settings.sketchbookPath, "libraries", "**")); + result.push(userLibsPath); // if (util.directoryExistsSync(path.join(toolsPath, "cores"))) { // const coreLibs = fs.readdirSync(path.join(toolsPath, "cores")); // if (coreLibs && coreLibs.length > 0) { @@ -612,6 +635,12 @@ Please make sure the folder is not occupied by other procedures .`); return result; } + public getDefualtDefines(): string[] { + const result = []; + result.push("USBCON"); + return result; + } + public openExample(example) { function tmpName(name) { let counter = 0; From 7a21b5b9928165e921ff3d1909751ce0fca7f887 Mon Sep 17 00:00:00 2001 From: Adi Azulay Date: Wed, 18 Nov 2020 07:10:47 -0800 Subject: [PATCH 3/5] add hardware tool path --- src/arduino/arduino.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index 73619a7b..e6b0d104 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -577,6 +577,10 @@ Please make sure the folder is not occupied by other procedures .`); } const toolsPath = boardDescriptor.platform.rootBoardPath; result.push(path.normalize(path.join(toolsPath, "**"))); + const hardwareToolPath = path.join(toolsPath, "..", "..", "tools"); + if (fs.existsSync(hardwareToolPath)){ + result.push(path.normalize(path.join(hardwareToolPath, "**"))); + } // if (util.directoryExistsSync(path.join(toolsPath, "cores"))) { // const coreLibs = fs.readdirSync(path.join(toolsPath, "cores")); // if (coreLibs && coreLibs.length > 0) { From 5878335cc8c7eba189ca3eaa19383bbefd960827 Mon Sep 17 00:00:00 2001 From: Adi Azulay Date: Thu, 19 Nov 2020 13:56:10 -0800 Subject: [PATCH 4/5] intellisense quick fix --- src/arduino/arduino.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index e6b0d104..7e082a01 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -320,15 +320,21 @@ export class ArduinoApp { return; } const cppConfigFile = fs.readFileSync(configFilePath, "utf8"); - const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ includePath: string[], forcedInclude: string[] }> }; + const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ + includePath: string[], + forcedInclude: string[], + defines: string[], + }> }; const libPaths = this.getDefaultPackageLibPaths(); const defaultForcedInclude = this.getDefaultForcedIncludeFiles(); + const defines = this.getDefualtDefines(); const configuration = cppConfig.configurations[0]; let cppConfigFileUpdated = false; // cpp exntension changes \\ to \\\\ in paths in JSON string, revert them first configuration.includePath = configuration.includePath.map((path) => path.replace(/\\\\/g, "\\")); configuration.forcedInclude = configuration.forcedInclude.map((path) => path.replace(/\\\\/g, "\\")); + configuration.defines = configuration.defines.map((path) => path.replace(/\\\\/g, "\\")); for (const libPath of libPaths) { if (configuration.includePath.indexOf(libPath) === -1) { @@ -343,6 +349,12 @@ export class ArduinoApp { } } + for (const define of defines) { + if (configuration.defines.indexOf(define) === -1) { + cppConfigFileUpdated = true; + configuration.defines.push(define); + } + } // remove all unexisting paths // concern mistake removal, comment temporary // for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) { @@ -386,6 +398,7 @@ export class ArduinoApp { } const defaultForcedInclude = this.getDefaultForcedIncludeFiles(); + const defaultDefines = this.getDefualtDefines(); if (!ArduinoWorkspace.rootPath) { return; @@ -444,6 +457,10 @@ export class ArduinoApp { configSection.forcedInclude = defaultForcedInclude.concat(configSection.forcedInclude); } + if (!configSection.defines) { + configSection.defines = defaultDefines; + } + fs.writeFileSync(configFilePath, JSON.stringify(deviceContext, null, 4)); } @@ -578,9 +595,15 @@ Please make sure the folder is not occupied by other procedures .`); const toolsPath = boardDescriptor.platform.rootBoardPath; result.push(path.normalize(path.join(toolsPath, "**"))); const hardwareToolPath = path.join(toolsPath, "..", "..", "tools"); - if (fs.existsSync(hardwareToolPath)){ + if (fs.existsSync(hardwareToolPath)) { result.push(path.normalize(path.join(hardwareToolPath, "**"))); - } + } + + // Add default libraries to include path + result.push(path.normalize(path.join(this._settings.defaultLibPath, "**"))); + + const userLibsPath = (path.join(this._settings.sketchbookPath, "libraries", "**")); + result.push(userLibsPath); // if (util.directoryExistsSync(path.join(toolsPath, "cores"))) { // const coreLibs = fs.readdirSync(path.join(toolsPath, "cores")); // if (coreLibs && coreLibs.length > 0) { @@ -612,6 +635,12 @@ Please make sure the folder is not occupied by other procedures .`); return result; } + public getDefualtDefines(): string[] { + const result = []; + result.push("USBCON"); + return result; + } + public openExample(example) { function tmpName(name) { let counter = 0; From 88f23ea717ced56e06a0e4b4456f55fd9cd6017e Mon Sep 17 00:00:00 2001 From: Adi Azulay Date: Thu, 19 Nov 2020 19:38:02 -0600 Subject: [PATCH 5/5] fix typo --- src/arduino/arduino.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index 7e082a01..263a5069 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -327,11 +327,11 @@ export class ArduinoApp { }> }; const libPaths = this.getDefaultPackageLibPaths(); const defaultForcedInclude = this.getDefaultForcedIncludeFiles(); - const defines = this.getDefualtDefines(); + const defines = this.getDefaultDefines(); const configuration = cppConfig.configurations[0]; let cppConfigFileUpdated = false; - // cpp exntension changes \\ to \\\\ in paths in JSON string, revert them first + // cpp extension changes \\ to \\\\ in paths in JSON string, revert them first configuration.includePath = configuration.includePath.map((path) => path.replace(/\\\\/g, "\\")); configuration.forcedInclude = configuration.forcedInclude.map((path) => path.replace(/\\\\/g, "\\")); configuration.defines = configuration.defines.map((path) => path.replace(/\\\\/g, "\\")); @@ -398,7 +398,7 @@ export class ArduinoApp { } const defaultForcedInclude = this.getDefaultForcedIncludeFiles(); - const defaultDefines = this.getDefualtDefines(); + const defaultDefines = this.getDefaultDefines(); if (!ArduinoWorkspace.rootPath) { return; @@ -635,8 +635,9 @@ Please make sure the folder is not occupied by other procedures .`); return result; } - public getDefualtDefines(): string[] { + public getDefaultDefines(): string[] { const result = []; + // USBCON is required in order for Serial to be recognized by intellisense result.push("USBCON"); return result; }