VSCode blank defines added through CMake are incorrectly handled/parsed in editor

This CMake fragment adds a global define to the firmware build that resolves to no tokens. It is equivalent to

#define EXAMPLE

This is necessary to reuse some code that I'm sharing with another project (not an NCS project). This builds as expected so the compiler is getting the correct definition from CMake

However the nRF VSCode extension is instead resolving it as an empty string literal as shown ^^.

This is an issue because it breaks the parsing for suggestions when the define is used anywhere a string literal is not valid for anything using the library

Parents
  • Hi

    Thank you for reporting this. The VSCode extension team has been notified. Initially it looks like something CMake does. In the compile_commands.json output file, the entry you mention turns into -DEXAMPLE="", which we just pass on. 

    As mentioend, the team is looking into if this is actually the case and if we can automatically convert it before passing it to intellisense, but we have to do some checks to see if that breaks anything else first.

    I'll keep you posted w.r.t. the progress on this when I hear something more form the extension developers

    Kind regards,
    Andreas

  • Looking at the C/C++ extension logs from another project that's using CMake tools (and ^^ formulation works)

    sending compilation args for <project>\main.cpp
    ...
      define: EXAMPLE=

    in nRF connect (where it errors), the same log message includes the quotes

    sending compilation args for <project>\main.cpp
    ...
      define: EXAMPLE=""

    The compiler definitely receives it as -DEXAMPLE="" (CMake exported compile commands show that clearly). The C/C++ extension might be mishandling them though :/

    CMake Tools errors on the obvious: target_compile_definitions(app PRIVATE EXAMPLE)
    (gives the EXAMPLE macro the value `1` in editor) which has been reported, but I'm currently stuck in the middle needing both editors to work

Reply
  • Looking at the C/C++ extension logs from another project that's using CMake tools (and ^^ formulation works)

    sending compilation args for <project>\main.cpp
    ...
      define: EXAMPLE=

    in nRF connect (where it errors), the same log message includes the quotes

    sending compilation args for <project>\main.cpp
    ...
      define: EXAMPLE=""

    The compiler definitely receives it as -DEXAMPLE="" (CMake exported compile commands show that clearly). The C/C++ extension might be mishandling them though :/

    CMake Tools errors on the obvious: target_compile_definitions(app PRIVATE EXAMPLE)
    (gives the EXAMPLE macro the value `1` in editor) which has been reported, but I'm currently stuck in the middle needing both editors to work

Children
Related