clangd support in extension

Hi,

I am trying to use the clangd extension with nRF Connect SDK, as it does a much better job than intellisense. I added 

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

To the top of my CMakeLists.txt, and symlinked compile_commands.json in the root of my project to <build dir>/application/compile_commands.json. This works great, however it doesn't update when switching between different build configurations. As far as I can see, there isn't any way to do that automatically, because there isn't any way to get the active build configuration from the nrf connect extension. One way to enable this would be to add a "active_build" action to task bindings, to enable the extension to trigger a task when switching active build. This would enable me to create a task to update the symlink or .clangd configuration and restart clangd. It would be great if the extension natively supported clangd either, but I suspect that would be more work (and it might be useful to have a "active_build" action anyway for other purposes)

Parents
  • For now I have added the following to the top of my CMakeLists.txt file. However, it needs a pristine build (so CMake reconfigures) and manually restarting clangd.

    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
    cmake_language(DEFER CALL file CREATE_LINK 
        ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json     
        ${CMAKE_CURRENT_SOURCE_DIR}/../compile_commands.json # my application is in application directory, so should be created in parent directory
        SYMBOLIC)

Reply
  • For now I have added the following to the top of my CMakeLists.txt file. However, it needs a pristine build (so CMake reconfigures) and manually restarting clangd.

    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
    cmake_language(DEFER CALL file CREATE_LINK 
        ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json     
        ${CMAKE_CURRENT_SOURCE_DIR}/../compile_commands.json # my application is in application directory, so should be created in parent directory
        SYMBOLIC)

Children
Related