o Avoid inserting a header include into the header itself.
o Avoid inserting non-header files.
o Canonicalize include paths for symbols in dynamic index.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
| clangd/Headers.cpp | ||
|---|---|---|
| 45 ↗ | (On Diff #134904) | There is another list of header extensions in ClangdServer::switchSourceHeader, let's reuse the list of extensions used here and there. |
| 48 ↗ | (On Diff #134904) | Maybe use llvm::sys::path::extension and search it in HeaderExtensions using StringRef::equals_lower? |
| 60 ↗ | (On Diff #134904) | Maybe replace !hasHeaderExtension(Header) to hasSourceExtension(Header)? |
| clangd/index/FileIndex.cpp | ||
| 18 ↗ | (On Diff #134904) | Maybe store a static inside the function body (to properly free memory) and return a const reference (to avoid mutating shared data)? const CanonicalIncludes &CanonicalIncludesForSystemHeaders() {
static CanonicalInclude Includes = []() -> CanonicalHeader {
CanonicalInclude Includes;
addSystemHeadersMapping(Includes);
return Includes;
};
return Includes;
}Also Sam mentioned that CanonicalIncludes is not thread-safe, as the Regex's match() mutates. |
| unittests/clangd/FileIndexTests.cpp | ||
| 173 ↗ | (On Diff #134904) | Why not on Windows? |
| clangd/Headers.cpp | ||
|---|---|---|
| 42–43 ↗ | (On Diff #134904) | As discussed offline, this seems dubious.
(later we'll want a flag on the symbol for whether it's public, so we can support find-symbol-by-name for mainfile-declared symbols) |
- Stop indexing main files in dynamic index; addressed review comments.
| clangd/Headers.cpp | ||
|---|---|---|
| 45 ↗ | (On Diff #134904) | Acked. (The change is not relevant anymore.) |
| clangd/index/FileIndex.cpp | ||
| 18 ↗ | (On Diff #134904) | As discussed offline, we want to avoid destructing static objects because ... Made CanonicalIncludes thread-safe by adding a mutex around matches. |
| unittests/clangd/FileIndexTests.cpp | ||
| 173 ↗ | (On Diff #134904) | because our system header map doesn't really support windows... |
| clangd/Headers.h | ||
|---|---|---|
| 26 ↗ | (On Diff #134932) | File also needs to be absolute. |
| clangd/index/FileIndex.cpp | ||
| 36 ↗ | (On Diff #134932) | if this is always true now, we could remove the option? |
| 37 ↗ | (On Diff #134932) | This is not going to handle IWYU right? |
| clangd/Headers.cpp | ||
|---|---|---|
| 60 ↗ | (On Diff #134932) | Not related to this patch, but just noticed that we don't call FS->setCurrentWorkingDirectory(CompileCommand.Directory) here. |
| clangd/index/CanonicalIncludes.cpp | ||
| 21 ↗ | (On Diff #134932) | Technically, if one thread initializes CanonicalIncludes and the other thread reads from it, this is a data race. |
| clangd/index/FileIndex.cpp | ||
| 18 ↗ | (On Diff #134932) | NIT: lowerCase the function name. |
| 38 ↗ | (On Diff #134932) | NIT: remove local var, replace with CollectorOpts.Includes = CanonicalIncludesForSystemHeaders()? |
| unittests/clangd/FileIndexTests.cpp | ||
| 173 ↗ | (On Diff #134904) | Thanks for clarification. |
| clangd/index/CanonicalIncludes.cpp | ||
|---|---|---|
| 21 ↗ | (On Diff #134932) | As Sam pointed out, it's fine the way it is right now. We don't want any thread-safety guarantees from the non-const methods of the class. |
| clangd/Headers.cpp | ||
|---|---|---|
| 60 ↗ | (On Diff #134932) | This was done in ClangdServer, but we should probably do it here as you suggested. |
| clangd/index/FileIndex.cpp | ||
| 36 ↗ | (On Diff #134932) | Will do this in a followup patch. Added a FIXME |
| 37 ↗ | (On Diff #134932) | You are right :( I'll prepare a followup patch to handle this. Added a FIXME. |