ArduinoJson icon indicating copy to clipboard operation
ArduinoJson copied to clipboard

VisualMicro + ESP32 = Intellisense Errors

Open avidNewb opened this issue 4 years ago β€’ 32 comments

I'm using VS2019 with vMicro installed to compile code for an MH-ET Live ESP32 MiniKit. I'm seeing an issue that was mentioned on a closed issue before. As soon as I add ArduinoJson I receive hundreds of intellisense errors. I have not been able to make these errors go away. The code does compile but this renders intellisense completely useless.

I've also noticed that intellisense doesn't recognize classes and functions from ArduinoJson. For instance DynamicJsonDocument does not show up in the list when I begin typing and appears with a red line underneath after typing. I can put ARDUINOJSON_NAMESPACE:: in front of it and it shows up. This doesn't resolve the functions though such as serializeJson because they are not in a namespace.

avidNewb avatar Feb 08 '20 06:02 avidNewb

After checking again, I noticed that the functions are in a namespace so I don't know why it doesn't fix them.

avidNewb avatar Feb 08 '20 06:02 avidNewb

Hi @avidNewb,

I installed Visual Micro on VS2019, and Intellisense seems to be working fine.

I'm seeing an issue that was mentioned on a closed issue before

Which issue?

I receive hundreds of intellisense errors.

What errors?

All functions and classes of ArduinoJson are in the namespace ArduinoJson. When you include ArduinoJson.h (and not ArduinoJson.hpp), a using namespace ArduinoJson; brings all symbols in the global namespace.

ARDUINOJSON_NAMESPACE is a macro that dynamically defines the name of another private namespace. The generated name includes the version number and the compile-time options, which allows embedding multiple versions of the library in the same binary. The actual name is something like ArduinoJson6141_0000010. Unfortunately, Intellisense shows this namespace instead of the public one, and I don't think there is any way to fix this.

Best regards, Benoit

bblanchon avatar Feb 08 '20 08:02 bblanchon

I was referring to https://github.com/bblanchon/ArduinoJson/issues/483

Interesting. I have included ArduinoJson.h. Putting "using namespace ArduinoJson;" shows an error but it does make most of the other errors go away in my project. Using your progmem example though it doesn't fix the errors. I get 311 errors. If I add "using namespace ArduinoJson;" it is then 312. Including, "ARDUINOJSON_NAMESPACE" makes the classes show up but not the functions, even in the example project and does nothing for the other errors. I'm going to move to another machine just to confirm it's not an issue with this one.

avidNewb avatar Feb 08 '20 16:02 avidNewb

I apologize. My other machine doesn't have this issue at all. Interesting that it's only with this library. Updating Arduino IDE and reinstalling vMicro hasn't helped. I'm currently repairing my IDE. If I figure out what is causing it, I'll comment here in case anyone else has the issue.

avidNewb avatar Feb 08 '20 17:02 avidNewb

I'll comment here in case anyone else has the issue.

Excellent idea! Let me know if I can help you.

bblanchon avatar Feb 09 '20 17:02 bblanchon

I am having exactly the same issue. I upgrade from ArduinoJson 6.13 (no issue with intellisense at that time) to 6.14.1 (which exhibit the issue). I will try to downgrade to 6.13.

Tintin4000 avatar Feb 21 '20 15:02 Tintin4000

I can confirm that the downgrade to 6.13 fixed the intellisense issue in VS2019. I have tried with 6.14 and 6.14.1, identical behavior.

Tintin4000 avatar Feb 21 '20 16:02 Tintin4000

I can confirm that the downgrade to 6.13 fixed the intellisense issue in VS2019. I have tried with 6.14 and 6.14.1, identical behavior.

Can you confirm what board you are using? I think we have narrowed it down to ESP32 boards in the vmicro forum.

https://www.visualmicro.com/forums/YaBB.pl?num=1581276046/20#23

avidNewb avatar Feb 21 '20 16:02 avidNewb

Hi,

@Tintin4000, thank you for narrowing down the issue to version 6.14.0 and ESP32.

ArduinoJson 6.14.0 automatically enables support for std::string and std::stream when it detects the required headers. It seems that enabling std::stream triggers a bunch of errors.

I don't know if it's a problem with ArduinoJson or with the ESP32 core.

Until we get a better understanding of the problem, you can manually disable the support for std::stream by setting ARDUINOJSON_ENABLE_STD_STREAM to 0.

Best regards, Benoit

bblanchon avatar Feb 21 '20 17:02 bblanchon

Yes, indeed I am using ESP32. The previous post fix the intellisense issue. Since I am not using stream in my code, I am fine. Thank you so much for your help and a great library. I revert back to 6.14.1.

Tintin4000 avatar Feb 21 '20 19:02 Tintin4000

We also experience similar intellisense issues using VisualStudio, VisualMicro, ESP32 and including ArduinoJson.h (all in very recent versions). Intellisense is working for most cases but not all e.g.

  • "DynamicJsonDocument doc(256)" is recognized

  • "serializeJson(doc, buffer, sizeof(buffer))" is not recognized

Is this the same issue described in this topic?

smuellener avatar Mar 25 '20 07:03 smuellener

@smuellener, yes, that's the same setup. Did you try to set ARDUINOJSON_ENABLE_STD_STREAM to 0?

bblanchon avatar Mar 25 '20 08:03 bblanchon

@bblanchon yes I have in the following way:

#define ARDUINOJSON_ENABLE_STD_STREAM 0 #include <ArduinoJson.h>

instead of

#include <ArduinoJson.h>

in the .Ino file. but with no success. We are including ArduinoJson.h in different other files (libraries) in the solution. I did not do this in all the files (I guess this is not needed).

I will try to investigate a bit more. If you would want to have a look yourself but do not have a setup, I also could arrange a way to remotely access.

smuellener avatar Mar 25 '20 08:03 smuellener

Following - tested with 6.15.2 and still the problem persists. Downgraded to 13 and the intellisense works again

Connect-and-Exchange avatar Jun 14 '20 11:06 Connect-and-Exchange

@bblanchon How can we improve this? We can not really make out where the issue is.. is it even a problem of this library or a problem of VisualStudio?

smuellener avatar Jul 15 '20 16:07 smuellener

@smuellener, I would say it's a problem with Visual Micro that doesn't distribute the complete STL.

I'm surprised that setting both ARDUINOJSON_ENABLE_STD_STREAM and ARDUINOJSON_ENABLE_STD_STRING to 0 doesn't fix the issue. I'm pretty sure I made the error disappear last time.

bblanchon avatar Jul 15 '20 16:07 bblanchon

@bblanchon ok after trying out different things the following worked (setting both to 0 resulted in the problem of #1045 )

ARDUINOJSON_ENABLE_STD_STREAM=0;ARDUINOJSON_ENABLE_STD_STRING=1

smuellener avatar Jul 17 '20 10:07 smuellener

I think this is a problem with the ESP32 headers. We can easily reproduce the problem without ArduinoJson, simply by including the standard <ios> header:

#include <ios>

Also, I noticed that VisualMicro/Intellisense tends to pick the wrong headers when the Arduino core doesn't provide them. For example, if you try to include <ios> on AVR, instead of saying cannot find source file "ios", it falls back to the classic MSVC headers and therefore displays a bunch of Intellisense errors.

I was not able to find a workaround, so I don't think I can fix this error. @smuellener, could you report this issue to the corresponding projects?

bblanchon avatar Jul 22 '20 06:07 bblanchon

Guys, is there any update on this?

bblanchon avatar Sep 25 '20 07:09 bblanchon

Guys, is there any update on this?

To be honest, I do not know where to raise this issue and what headers are responsible for this. But what I can say is that it works for us with the defines described above.

smuellener avatar Sep 25 '20 07:09 smuellener

Any chance an update might have resolved the issue without you noticing it?

bblanchon avatar Sep 25 '20 08:09 bblanchon

I finally got around to doing some more testing on my system here. I have not found any combination of namespaces and defines as discussed above that work for me. I have however noticed that it is only failing when I compile for HelTec ESP32 WiFi Kit 32. They have their own .h file and the conflicts are around the String definition. As long as I don't use any of the json namespaces it compiles, but of course intellisense gives warnings. If I use the json namespace I get "String is ambiguous" and it won't compile/link.

MartinNohr avatar Sep 28 '20 18:09 MartinNohr

@MartinNohr, ArduinoJson contains a String class in the ARDUINOJSON_NAMESPACE. This namespace is private and is reserved for internal use. In your application, you should use only the ArduinoJson namespace.

bblanchon avatar Sep 28 '20 19:09 bblanchon

I have this #include <ArduinoJson.h> using namespace ArduinoJson #include <BLEDevice.h> #include <BLEUtils.h> #include <BLEServer.h> #include <BLE2902.h> #include <ringbufcpp.h>

I get this error when compiling: esp_bt_defs.h: 22:1: error: expected ';' before 'extern extern "C" {

If it remove the namespace it compiles just fine. Here is part of that file: #include <stdint.h> #include <stdbool.h>

#ifdef __cplusplus extern "C" { #endif

#define ESP_BLUEDROID_STATUS_CHECK(status)
if (esp_bluedroid_get_status() != (status)) {
return ESP_ERR_INVALID_STATE;
}

/* relate to BT_STATUS_xxx in bt_def.h / /// Status Return Value typedef enum { ESP_BT_STATUS_SUCCESS = 0, / relate to BT_STATUS_SUCCESS in bt_def.h / ESP_BT_STATUS_FAIL, / relate to BT_STATUS_FAIL in bt_def.h */

Anything else you'd like to see? I only see this error with the Heltec ESP32 WIFI kit.

MartinNohr avatar Sep 30 '20 03:09 MartinNohr

Hi @MartinNohr,

You're missing a semicolon after using namespace ArduinoJson, that's probably the reason for the error. Anyway, you don't need to add this line, since ArduinoJson.h already imports the namespace.

BTW, are you using VisualMicro, and are you seeing Intellisense errors? It looks like your problem is unrelated to the current issue.

Best regards, Benoit

bblanchon avatar Sep 30 '20 07:09 bblanchon

Well, that's embarrassing, a missing ; . I've been a programmer using C and C++ (and others) for 40 years. :-) I must be getting old... Anyway, yes, I'm using VisualMicro. Yes, I see intellisense errors in that symbols are declared as undefined, even though they compile just fine. Here's a picture showing some undefined symbols. image The red squiggly underlines means undefined symbol, but it compiles just fine. Very strange.

MartinNohr avatar Oct 01 '20 19:10 MartinNohr

And even more curious, if I select one of those, F12 does take me to the definition correctly, which is what it is supposed to do.

MartinNohr avatar Oct 01 '20 19:10 MartinNohr

This might be interesting. image

MartinNohr avatar Oct 01 '20 19:10 MartinNohr

Intellisense is basing its syntax support on the includes that are defined in .vscode/c_cpp_properties.json file. Adapting this file to point to the right include directories helps a lot. UPDATE : this remark is maybe not applicable to Visual Micro, but as it is a derivative from visual studio could possibly help. image

vortex314 avatar Jan 14 '21 16:01 vortex314

Maybe it's time to close this issue... is the error still occurring?

bblanchon avatar May 19 '21 12:05 bblanchon

Yes it is…

Connect-and-Exchange avatar May 19 '21 13:05 Connect-and-Exchange

I showed in a previous comment that this bug is not specific to ArduinoJson. Did anyone report it to VisualMicro?

bblanchon avatar May 19 '21 14:05 bblanchon