Home > front end >  Why my clangd in vscode will change my header file's order to alphabetical order when I was fom
Why my clangd in vscode will change my header file's order to alphabetical order when I was fom

Time:08-07

I found my clangd plugin in VSCode will modify *.h file's order to alphabetical order. For example:

before:
-#include "c.h"
-#include "b.h"
-#include "a.h"
after:
 #include "a.h"
 #include "b.h"
 #include "c.h"

And here is my clangd's settins,How do I fix this bug.

"clangd.onConfigChanged": "restart",
    "clangd.arguments": [
        "--clang-tidy",
        "--clang-tidy-checks=performance-*,bugprone-*",
        "--compile-commands-dir=${workspaceFolder}/.vscode/",
        "--background-index",
        "--completion-style=detailed",
        "--enable-config",
        "--fallback-style=Mozilla",
        "--function-arg-placeholders=false",
        "--all-scopes-completion",
        "--header-insertion-decorators",
        "--header-insertion=iwyu",
        "--log=verbose",
        "--pch-storage=memory",
        "--pretty",
        "--ranking-model=decision_forest",
        "--cross-file-rename",
        "-j=16"
    ],
    "clangd.checkUpdates": false,

CodePudding user response:

Clangd formats your code using clang-format (or more precisely, the LibFormat library that's also used by clang-format), and respects the configuration found in the .clang-format file in the project's root directory (or a subdirectory).

See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the various formatting options supported by clang-format. The one relevant to your question is SortIncludes.

  • Related