Formatting to a .clang-format file that requires Clang10

Sysprogs forums Forums VisualGDB Formatting to a .clang-format file that requires Clang10

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #31985
    DanielBoehmer
    Participant

    I have recently updated to Visual Studio 2022.

    When using a native Win32 C++ solution formatting code with Clang works really well, even with my own .clang-format file. You can specify an own clang-format.exe (works since VS 2019), so using Clang-format version 13 is no problem.

    However, VisualGDB 5.6 does not respect that setting. At least the outcome of the formatting is something very different than expected. There is the nice setting “Automatically configure clang-format from VS settings” in C/C++ (VisualGDB( but that does not seem to work. Am I missing something here. Is it possible to disable VisualGDBs formatting at all?

    #31999
    support
    Keymaster

    Hi,

    VisualGDB indeed relies on a rather deep integration with clang-format in order to support various advanced features (e.g. computing smart indent for new lines based on clang-format rules). So, instead of using an external clang-format executable, our IntelliSense engine includes a copy of the clang-format logic.

    We are planning to update to the latest Clang later this year, although we cannot give a specific timeframe yet, as it usually requires a lot of non-trivial changes and testing on our side.

    As a workaround, you can indeed prevent VisualGDB from formatting the code automatically via Tools->Options->Text Editor->C/C++(VisualGDB)->Formatting->Automatic Formatting->Auto-format when <…> , and then launch the regular clang-format as a custom shortcut (configurable via VisualGDB Project Properties) or as a git trigger.

    The “Automatically configure clang-format from VS settings” setting currently only covers the basics (tabs/spaces, simple indentation rules). Advanced formatting settings can be configured via our graphical clang-format file editor by simply opening the .clang-format file, although it will only work for settings present in clang-format 6.0.

    #32007
    DanielBoehmer
    Participant

    Yeah. As far as I have seen, the shortcuts in VisualGDB can not be triggered on something like “the currently opened/shown file”

    At the moment you are overwriting two perfectly working shortcuts (CTRL-K, CTRL-D) and (CTRL-K, CTRL-F). Is there a chance to disable or reset that?

    #32025
    support
    Keymaster

    Due to the way Visual Studio handles programming language extensions, using Clang IntelliSense automatically redirects all IntelliSense-related functionality to VisualGDB, including the formatting. There is no easy way to call the formatting logic from the regular VC++ IntelliSense while still using the Clang one.

    Regarding the currently opened file, we can gladly add a new variable (e.g. $(ActiveSourcePath)) that will resolve to the currently open source file when used with custom shortcuts, if it helps you configure the formatting workaround.

    #32030
    DanielBoehmer
    Participant

    Yes, Actually I think variables like $(ActiveSourcePath) could be very beneficial for multiple scripts. Can we also apply any keyboard-shortcuts to the execution of VisualGDB custom scripts aswell?

    #32040
    support
    Keymaster

    No problem, please try this build: VisualGDB-5.6.102.4523.msi. We have added the following variables to it:

    • ActiveSourcePath
    • ActiveSourceDir
    • ActiveSourceFileName

    The variables will work in the custom shortcuts and throughout the debug settings for all project types. They will also work in the build settings for the projects that are built directly by VisualGDB (e.g. Advanced CMake, Arduino, ESP-IDF).

    Unfortunately Visual Studio does not allow easily assigning keyboard shortcuts to dynamically defined commands (such as VisualGDB Custom Shortcuts), however you can still launch the formatting action quickly by selecting it as an active shortcut in the VisualGDB toolbar, and then clicking the “run selected shortcut” button to the right of the shortcut combo box.

    #32045
    DanielBoehmer
    Participant

    Thanks a lot.

    #32049
    DanielBoehmer
    Participant

    Hi

    It seems that $(ActiveSourcePath) does not update once it was used.
    Its only working on the first file the shortcut is applied. Afterwards, when the source (or header) file is changed, the old value is still forwarded to my scripts.

    #32050
    support
    Keymaster

    Thanks for pointing this out. Indeed, the value of ActiveSourcePath was incorrectly cached in some of the cases. We have fixed the issue in VisualGDB 5.6R3 that can be downloaded here: https://visualgdb.com/download/

    #32496
    cesaretiveron
    Participant

    Hi,

    I’m adding feedback here because I also need an updated version of the clang-format engine.

    Thank you

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.