Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliSense throws #include errors when working with Arduino in VS Code

I want to develop Arduino code in VS Code. Therefore, I installed the Arduino IDE and the Arduino extension vor VS Code.

Upon opening an Arduino project in VS Code the extension created the following c_cpp_properties.json file for IntelliSense (excerpt):

"includePath": [
        "/Applications/Arduino.app/Contents/Java/tools/**",
        "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/**"
],
"forcedInclude": [
        "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h"
],

The forced include Arduino.h has the following relative include:

// Some includes
#include <avr/pgmspace.h>
// Even more includes

The problem is that, although pgmspace.h does exist it is not located in the path relative to Arduino.h (it is not located in one of the two include paths either). Adding the path of pgmspace.h to the include paths does not help as IntelliSense seems to be looking for the given relative path.

My question is if there is any possibility to tell IntelliSense via the c_cpp_properties.json file to ignore relative paths and just look for the file? Or if you can think of another way to resolve this problem?

like image 386
ar-std Avatar asked Oct 24 '25 01:10

ar-std


1 Answers

I found an answer myself. If you have the same problem, try the following:

Add to settings.json:

"C_Cpp.intelliSenseEngine": "Tag Parser"

This is a downside as "Tag Parser" is not context-aware.

Add to c_cpp_properties.json:

"configurations": [
  {

    ...,

    "browse": {
      "path": [
        "/Applications/Arduino.app/Contents/Java/tools",
        "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr",
        "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include"
      ],
      "limitSymbolsToIncludedHeaders": true
    }
  }
]
like image 167
ar-std Avatar answered Oct 26 '25 15:10

ar-std