llvm-project/clang-tools-extra/clangd
Nathan James b859c39c40
[clang-tidy] Add a Standalone diagnostics mode to clang-tidy
Adds a flag to `ClangTidyContext` that is used to indicate to checks that fixes will only be applied one at a time.
This is to indicate to checks that each fix emitted should not depend on any other fixes emitted across the translation unit.
I've currently implemented the `IncludeInserter`, `LoopConvertCheck` and `PreferMemberInitializerCheck` to use these support these modes.

Reasoning behind this is in use cases like `clangd` it's only possible to apply one fix at a time.
For include inserter checks, the include is only added once for the first diagnostic that requires it, this will result in subsequent fixes not having the included needed.

A similar issue is seen in the `PreferMemberInitializerCheck` where the `:` will only be added for the first member that needs fixing.

Fixes emitted in `StandaloneDiagsMode` will likely result in malformed code if they are applied all together, conversely fixes currently emitted may result in malformed code if they are applied one at a time.
For this reason invoking `clang-tidy` from the binary will always with `StandaloneDiagsMode` disabled, However using it as a library its possible to select the mode you wish to use, `clangd` always selects `StandaloneDiagsMode`.

This is an example of the current behaviour failing
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E) {
    A = D;
    B = E; // Fix Here
  }
};
```
Incorrectly transformed to:
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E), B(E) {
    A = D;
     // Fix Here
  }
};
```
In `StandaloneDiagsMode`, it gets transformed to:
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E) : B(E) {
    A = D;
     // Fix Here
  }
};
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D97121
2022-04-16 09:53:35 +01:00
..
benchmarks
fuzzer
index [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
indexer
quality
refactor Fix MSVC "not all control paths return a value" warning 2022-04-07 14:01:15 +01:00
support
test [cmake] Provide CURRENT_TOOLS_DIR centrally, replacing CLANG_TOOLS_DIR 2022-03-25 20:22:01 +01:00
tool
unittests [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
xpc
AST.cpp [clangd] Add code action to generate a constructor for a C++ class 2022-04-06 16:23:50 +02:00
AST.h [clangd] Add code action to generate a constructor for a C++ class 2022-04-06 16:23:50 +02:00
ASTSignals.cpp
ASTSignals.h
CMakeLists.txt
ClangdLSPServer.cpp
ClangdLSPServer.h
ClangdServer.cpp
ClangdServer.h
CodeComplete.cpp
CodeComplete.h
CodeCompletionStrings.cpp
CodeCompletionStrings.h
CollectMacros.cpp
CollectMacros.h
CompileCommands.cpp
CompileCommands.h
Compiler.cpp
Compiler.h
Config.cpp
Config.h [clangd] NFC: Fix doc typos 2022-04-07 12:56:56 +02:00
ConfigCompile.cpp
ConfigFragment.h [clangd] NFC: Fix doc typos 2022-04-07 12:56:56 +02:00
ConfigProvider.cpp
ConfigProvider.h
ConfigYAML.cpp
Diagnostics.cpp [clangd] Remove trivial uses of FileEntry::getName 2022-04-04 20:59:51 +02:00
Diagnostics.h
DraftStore.cpp
DraftStore.h
DumpAST.cpp Reland "[AST] Add a new TemplateKind for template decls found via a using decl."" 2022-04-14 11:04:55 +02:00
DumpAST.h
ExpectedTypes.cpp
ExpectedTypes.h
FS.cpp
FS.h
Feature.cpp
Feature.h
FeatureModule.cpp
FeatureModule.h
Features.inc.in
FileDistance.cpp
FileDistance.h
FindSymbols.cpp
FindSymbols.h
FindTarget.cpp
FindTarget.h
Format.cpp [clangd] Handle tabs in getIncrementalChangesAfterNewline() 2022-03-29 01:43:09 -04:00
Format.h
FuzzyMatch.cpp
FuzzyMatch.h
GlobalCompilationDatabase.cpp
GlobalCompilationDatabase.h
HeaderSourceSwitch.cpp [clangd] Test against path insensitivity 2022-03-21 17:27:05 +01:00
HeaderSourceSwitch.h
Headers.cpp [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
Headers.h [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
HeuristicResolver.cpp
HeuristicResolver.h
Hover.cpp
Hover.h
IncludeCleaner.cpp Reland "[clangd] IncludeCleaner: Add support for IWYU pragma private" 2022-04-05 16:57:39 +02:00
IncludeCleaner.h Reland "[clangd] IncludeCleaner: Add support for IWYU pragma private" 2022-04-05 16:57:39 +02:00
IncludeFixer.cpp [clangd] Support include-fixer inside macro arguments. 2022-03-23 17:12:33 +01:00
IncludeFixer.h
InlayHints.cpp [clangd] Add inlay hints for auto-typed parameters with one instantiation. 2022-03-23 17:26:25 +01:00
InlayHints.h
JSONTransport.cpp
LSPBinder.h
ParsedAST.cpp [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
ParsedAST.h [clangd] Code action to declare missing move/copy constructor/assignment 2022-04-06 16:14:42 +02:00
PathMapping.cpp
PathMapping.h
Preamble.cpp [clangd] Export preamble AST and serialized size as metrics 2022-04-13 14:43:06 +02:00
Preamble.h [clangd] Export preamble AST and serialized size as metrics 2022-04-13 14:43:06 +02:00
Protocol.cpp
Protocol.h
Quality.cpp
Quality.h
QueryDriverDatabase.cpp
README.md
RIFF.cpp
RIFF.h
Selection.cpp
Selection.h
SemanticHighlighting.cpp Reland "[AST] Add a new TemplateKind for template decls found via a using decl."" 2022-04-14 11:04:55 +02:00
SemanticHighlighting.h
SemanticSelection.cpp
SemanticSelection.h
SourceCode.cpp
SourceCode.h
TUScheduler.cpp [clangd] Export preamble AST and serialized size as metrics 2022-04-13 14:43:06 +02:00
TUScheduler.h
TidyProvider.cpp
TidyProvider.h
Transport.h
URI.cpp
URI.h
XRefs.cpp
XRefs.h

README.md

clangd

clangd is a language server, and provides C++ IDE features to editors. This is not its documentation.

Communication channels

If you have any questions or feedback, you can reach community and developers through one of these channels:

Building and testing clangd

For a minimal setup on building clangd:

  • Clone the LLVM repo to $LLVM_ROOT.

  • Create a build directory, for example at $LLVM_ROOT/build.

  • Inside the build directory run: cmake $LLVM_ROOT/llvm/ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra".

    • We suggest building in Release mode as building DEBUG binaries requires considerably more resources. You can check Building LLVM with CMake documentation for more details about cmake flags.
    • In addition to that using Ninja as a generator rather than default make is preferred. To do that consider passing -G Ninja to cmake invocation.
    • Finally, you can turn on assertions via -DLLVM_ENABLE_ASSERTS=On.
  • Afterwards you can build clangd with cmake --build $LLVM_ROOT/build --target clangd, similarly run tests by changing target to check-clangd.