diff options
author | David Goldman <davg@google.com> | 2020-02-18 16:21:12 -0500 |
---|---|---|
committer | David Goldman <davg@google.com> | 2020-02-19 11:45:58 -0500 |
commit | f50fe5eb6d2ec0adb5b2fd91a4023fc1573e061f (patch) | |
tree | 02bb0adea78c099074806f678d0eff6dcd3092a9 /clang/lib/Sema/SemaCodeComplete.cpp | |
parent | f12fb2d99b8dd0dbef1c79f1d401200150f2d0bd (diff) | |
download | llvm-f50fe5eb6d2ec0adb5b2fd91a4023fc1573e061f.zip llvm-f50fe5eb6d2ec0adb5b2fd91a4023fc1573e061f.tar.gz llvm-f50fe5eb6d2ec0adb5b2fd91a4023fc1573e061f.tar.bz2 |
[Sema][CodeComplete] Handle symlinks for include code completion
Summary:
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).
Reviewers: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D74790
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 487ba46..6ba4040 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -8776,7 +8776,16 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) { 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()) { + + // To know whether a symlink should be treated as file or a directory, we + // have to stat it. This should be cheap enough as there shouldn't be many + // symlinks. + llvm::sys::fs::file_type Type = It->type(); + if (Type == llvm::sys::fs::file_type::symlink_file) { + if (auto FileStatus = FS.status(It->path())) + 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. |