llvm-project/clang-tools-extra/clangd
Sam McCall 62e2472321 [clangd] Include insertion: require header guards, drop other heuristics, treat .def like .inc.
Summary:
We do have some reports of include insertion behaving badly in some
codebases. Requiring header guards both makes sense in principle, and is
likely to disable this "nice-to-have" feature in codebases where headers don't
follow the expected pattern.

With this we can drop some other heuristics, such as looking at file
extensions to detect known non-headers - implementation files have no guards.

One wrinkle here is #import - objc headers may not have guards because
they're intended to be used via #import. If the header is the main file
or is #included, we won't collect locations - merge should take care of
this if we see the file #imported somewhere. Seems likely to be OK.

Headers which have a canonicalization (stdlib, IWYU) are exempt from this check.
*.inc files continue to be handled by looking up to the including file.
This patch also adds *.def here - tablegen wants this pattern too.

In terms of code structure, the division between SymbolCollector and
CanonicalIncludes has shifted: SymbolCollector is responsible for more.
This is because SymbolCollector has all the SourceManager/HeaderSearch access
needed for checking for guards, and we interleave these checks with the *.def
checks in a loop (potentially).
We could hand all the info into CanonicalIncludes and put the logic there
if that's preferable.

Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60316

llvm-svn: 358571
2019-04-17 10:36:02 +00:00
..
benchmarks Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
clients/clangd-vscode [clangd] Bump vscode-clangd v0.0.12. 2019-03-27 16:01:25 +00:00
fuzzer clangd-fuzzer: repair the build 2019-04-10 19:16:14 +00:00
include-mapping [clangd] Add std subnamespace symbols to the symbol map. 2019-03-25 13:14:10 +00:00
index [clangd] Include insertion: require header guards, drop other heuristics, treat .def like .inc. 2019-04-17 10:36:02 +00:00
indexer gn build: Add check-clang-tools to run clang-tools-extra lit tests 2019-03-29 02:49:13 +00:00
refactor gn build: Add some build files for clangd 2019-03-28 16:53:32 +00:00
tool [clangd] Enable clang-tidy by default. 2019-04-12 13:07:48 +00:00
xpc gn build: Add build files for clangd xpc framework code 2019-04-03 12:33:19 +00:00
AST.cpp [clangd] Print template arguments helper 2019-04-12 10:09:14 +00:00
AST.h [clangd] Print template arguments helper 2019-04-12 10:09:14 +00:00
CMakeLists.txt Use a cmake check for linux that actually works. 2019-04-04 13:54:01 +00:00
Cancellation.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Cancellation.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ClangdLSPServer.cpp [clangd] Return clangd::TextEdit in ClangdServer::rename. NFC 2019-04-03 07:18:43 +00:00
ClangdLSPServer.h clangd: fix the build with XPC 2019-04-10 16:48:52 +00:00
ClangdServer.cpp [clangd] Wait for compile command in ASTWorker instead of ClangdServer 2019-04-15 12:32:28 +00:00
ClangdServer.h [clangd] Wait for compile command in ASTWorker instead of ClangdServer 2019-04-15 12:32:28 +00:00
ClangdUnit.cpp [clangd] Use identifiers in file as completion candidates when build is not ready. 2019-04-11 09:36:36 +00:00
ClangdUnit.h [clangd] Stop passing around PCHContainerOperations, just create it in place. NFC 2019-04-04 12:56:03 +00:00
CodeComplete.cpp [clangd] Check file path of declaring header when deciding whether to insert include. 2019-04-16 14:35:49 +00:00
CodeComplete.h [clangd] Use identifiers in file as completion candidates when build is not ready. 2019-04-11 09:36:36 +00:00
CodeCompletionStrings.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeCompletionStrings.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Compiler.cpp [clangd] Stop passing around PCHContainerOperations, just create it in place. NFC 2019-04-04 12:56:03 +00:00
Compiler.h [clangd] Wait for compile command in ASTWorker instead of ClangdServer 2019-04-15 12:32:28 +00:00
Context.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Context.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Diagnostics.cpp [clangd] Add Source to clangd::Diagnostic. 2019-03-06 10:51:38 +00:00
Diagnostics.h [clangd] Add Source to clangd::Diagnostic. 2019-03-06 10:51:38 +00:00
DraftStore.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
DraftStore.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ExpectedTypes.cpp Added missing license headers 2019-02-28 14:01:11 +00:00
ExpectedTypes.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
FS.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
FS.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
FSProvider.cpp [clangd] Unlink VFS working dir from OS working dir. Reland of r351051 2019-02-15 11:04:25 +00:00
FSProvider.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Features.inc.in [clangd] XPC transport layer 2019-01-16 00:24:22 +00:00
FileDistance.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
FileDistance.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
FindSymbols.cpp [clangd] Show template argument list in workspacesymbols and documentsymbols responses 2019-04-12 10:09:37 +00:00
FindSymbols.h [clangd] Add support for type hierarchy (super types only for now) 2019-03-19 09:27:04 +00:00
Function.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
FuzzyMatch.cpp [clangd] Tune the fuzzy-matching algorithm 2019-03-15 14:00:49 +00:00
FuzzyMatch.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
GlobalCompilationDatabase.cpp [clangd] Wait for compile command in ASTWorker instead of ClangdServer 2019-04-15 12:32:28 +00:00
GlobalCompilationDatabase.h [clangd] Filter out plugin related flags and move all commandline manipulations into OverlayCDB. 2019-01-22 09:10:20 +00:00
Headers.cpp [clangd] Check file path of declaring header when deciding whether to insert include. 2019-04-16 14:35:49 +00:00
Headers.h [clangd] Check file path of declaring header when deciding whether to insert include. 2019-04-16 14:35:49 +00:00
IncludeFixer.cpp [clangd] Check file path of declaring header when deciding whether to insert include. 2019-04-16 14:35:49 +00:00
IncludeFixer.h Moved Symbol into its own header and implementation file 2019-02-28 13:23:03 +00:00
JSONTransport.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Logger.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Logger.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Path.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Protocol.cpp Fix MSVC "not all control paths return a value" warning. NFCI. 2019-03-29 13:43:00 +00:00
Protocol.h [clangd] Support UTF-32 (i.e. codepoint) offsets. 2019-03-28 14:37:51 +00:00
Quality.cpp Moved Ref into its own header and implementation file 2019-02-28 13:49:25 +00:00
Quality.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
RIFF.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
RIFF.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Selection.cpp [clangd] Fix a crash in Selection 2019-02-20 19:26:39 +00:00
Selection.h [clangd] Lib to compute and represent selection under cursor. 2019-02-01 15:05:11 +00:00
SourceCode.cpp [clangd] Use identifiers in file as completion candidates when build is not ready. 2019-04-11 09:36:36 +00:00
SourceCode.h [clangd] Use identifiers in file as completion candidates when build is not ready. 2019-04-11 09:36:36 +00:00
StdSymbolMap.inc [clangd] Add std subnamespace symbols to the symbol map. 2019-03-25 13:14:10 +00:00
TUScheduler.cpp [clangd] Wait for compile command in ASTWorker instead of ClangdServer 2019-04-15 12:32:28 +00:00
TUScheduler.h [clangd] Wait for compile command in ASTWorker instead of ClangdServer 2019-04-15 12:32:28 +00:00
Threading.cpp clangd: Change Windows.h to windows.h. 2019-04-17 03:02:18 +00:00
Threading.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Trace.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Trace.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Transport.h [clangd] Use #if CLANGD_BUILD_XPC because it may be defined as 0 2019-04-10 15:45:54 +00:00
URI.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
URI.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
XRefs.cpp [clangd] Add support for type hierarchy (super types only for now) 2019-03-19 09:27:04 +00:00
XRefs.h [clangd] Add support for type hierarchy (super types only for now) 2019-03-19 09:27:04 +00:00