VS Code IntelliSense configuration

It is great to have VS Code as IDE. Thank You.

Yet, I do not find a valid configuration that allows me to use IntelliSense or even simple include paths during coding. The code is build fine, no problems building. But I can not jump to a declaration and I can not see errors through linting as the whole file is shown as having errors.

I have no problems with the NCS includes, just all other includes.

This is my c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "ncs",
            "includePath": [
                "${workspaceFolder}/",
                "${workspaceFolder}/include/",
                "c:\\work\\ncs\\v1.7.0\\nrf\\include/**",
                "c:\\work\\ncs\\v1.7.0\\zephyr\\include/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "c:\\work\\ncs\\v1.7.0\\toolchain\\segger_embedded_studio\\gcc\\arm-none-eabi\\bin\\cc1plus.exe",
            "cStandard": "c99",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-arm64",
            "configurationProvider": "nrf-connect"
        }
    ],
    "version": 4
}

This is my settings.json:

{
    "C_Cpp.errorSquiggles": "Enabled",
    "kconfig.zephyr.west": "c:\\work\\ncs\\v1.7.0\\toolchain\\opt\\bin\\Scripts\\west.exe",
    "kconfig.zephyr.base": "c:\\work\\ncs\\v1.7.0\\zephyr"
}

This is how my file looks like:

Is there any way to be able to jump to internal Makros, Types and Enums?

Best regards,

Lukas

Parents
  • Hi Lukas

    I am not facing this problem in my project, so it should be fixable.

    The image of your file is unreadable(too small). Are you able to re-upload this, maybe as a main.c file(If that is what you want to show)?

    A look at your CMakeLists.txt would also be useful.

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd,

    thank You for looking into this. My main issue is the IntelliSense that does not work and all the error squiggles. I don't just simply want to remove those, though.

    As for the image: I provided a small image of the file to make visible that Visual Studio Code shows errors everywhere, because no user written include file is accepted.

    I paste a small sample code image of one type and one macro from header file that builds fine but does not work in VS Code.

    Build works fine, nevertheless find below the CMakeLists.txt.

    #
    # Copyright (c) 2020 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    cmake_minimum_required(VERSION 3.13.1)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(udp)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE src/helper.c
                               src/main.c
                               src/transport.c
                               ${POST_CONFIGURE_FILE}
                               # some more files
                               ../otherproject/file.c
                               # some more files
    )
    # NORDIC SDK APP END
    
    zephyr_include_directories(src
                               include
                               ../otherproject/include/
    )
    

    Best regards,

    Lukas

  • Hi

    Sigurd Hellesvik said:
    I am not facing this problem in my project, so it should be fixable.

    Right, it is specifically for included files in another folder. ("../something"). If I do that, I face the same problem.

    I have checked with our developers, and this is a known bug. It will be fixed in a later version of our extension.

    As a temporary fix, you can either:

    Add ""${workspaceFolder}/../library_folder/**" to includePath in c_cpp_properties.json, given that VS code is opened to the project folder(Using "Open Folder...").
    or
    Just open the file manually once. Then VS Code should be able to find it.

    Does any of these work four you?

    Here is the example project I used to try to replicate your issue:

    7206.test.zip

    Regards,
    Sigurd Hellesvik

Reply
  • Hi

    Sigurd Hellesvik said:
    I am not facing this problem in my project, so it should be fixable.

    Right, it is specifically for included files in another folder. ("../something"). If I do that, I face the same problem.

    I have checked with our developers, and this is a known bug. It will be fixed in a later version of our extension.

    As a temporary fix, you can either:

    Add ""${workspaceFolder}/../library_folder/**" to includePath in c_cpp_properties.json, given that VS code is opened to the project folder(Using "Open Folder...").
    or
    Just open the file manually once. Then VS Code should be able to find it.

    Does any of these work four you?

    Here is the example project I used to try to replicate your issue:

    7206.test.zip

    Regards,
    Sigurd Hellesvik

Children
  • Thank You for Your help, Sigurd, You pushed me into the right direction through Your attached project. I found the issue.

    It was an error in CMakeLists.txt, that caused this problem, i.e. the header file included in the target_sources! I removed the header file in the code I pasted above to clarify the problem, but then the problem disappeared.

    So this shows the problematic part:

    target_sources(app PRIVATE 
                               ...
                               include/helper.h
                               ...
                               
    )

    => Never add a header file to the target sources.

    Please note, that I already had the include paths in c_cpp_properties.json set correctly, thats qhy it worked instantly once I had the file removed.

    By the way: This also works for opening the project as a workspace, not only as project folder, IMHO.

Related