[PATCH] D74790: [Sema][CodeComplete] Handle symlinks for include code completion
David Goldman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 18 13:31:02 PST 2020
dgoldman created this revision.
dgoldman added a reviewer: sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Previously any symlinks would be ignored since the directory
traversal doesn't follow them.
With this change we now follow symlinks (via a `stat` call
in order to figure out the target type of the symlink if it
is valid).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74790
Files:
clang/lib/Sema/SemaCodeComplete.cpp
Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -8776,7 +8776,19 @@
if (++Count == 2500) // If we happen to hit a huge directory,
break; // bail out early so we're not too slow.
StringRef Filename = llvm::sys::path::filename(It->path());
- switch (It->type()) {
+
+ // We need to manually resolve symlinks since the directory_iterator
+ // doesn't do it for us. Alternatively we could use a heuristic such as
+ // file extension, but this should be okay as long as there aren't many
+ // symlinks.
+ auto Type = It->type();
+ if (Type == llvm::sys::fs::file_type::symlink_file) {
+ auto FileStatus = FS.status(It->path());
+ if (FileStatus) {
+ Type = FileStatus->getType();
+ }
+ }
+ switch (Type) {
case llvm::sys::fs::file_type::directory_file:
// All entries in a framework directory must have a ".framework" suffix,
// but the suffix does not appear in the source code's include/import.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74790.245247.patch
Type: text/x-patch
Size: 1173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200218/a76fb239/attachment-0001.bin>
More information about the cfe-commits
mailing list