summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/Headers.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2018-02-19 18:48:44 +0000
committerEric Liu <ioeric@google.com>2018-02-19 18:48:44 +0000
commit709bde886d9b6f27e17d427a81938ba8f885466f (patch)
tree1c86207b15b1145068ce3e2e239107a28beaad91 /clang-tools-extra/clangd/Headers.cpp
parent7fac6e92a70b8860e41d228ea03dd24fcf5f83bb (diff)
downloadbcm5719-llvm-709bde886d9b6f27e17d427a81938ba8f885466f.tar.gz
bcm5719-llvm-709bde886d9b6f27e17d427a81938ba8f885466f.zip
[clangd] Fixes for #include insertion.
Summary: o Avoid inserting a header include into the header itself. o Avoid inserting non-header files (by not indexing symbols in main files at all). o Canonicalize include paths for symbols in dynamic index. Reviewers: sammccall, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43462 llvm-svn: 325523
Diffstat (limited to 'clang-tools-extra/clangd/Headers.cpp')
-rw-r--r--clang-tools-extra/clangd/Headers.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index faf73c7f99f..db8029b2ac0 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -16,6 +16,7 @@
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/Support/Path.h"
namespace clang {
namespace clangd {
@@ -45,10 +46,17 @@ private:
/// FIXME(ioeric): we might not want to insert an absolute include path if the
/// path is not shortened.
llvm::Expected<std::string>
-shortenIncludePath(llvm::StringRef File, llvm::StringRef Code,
- llvm::StringRef Header,
- const tooling::CompileCommand &CompileCommand,
- IntrusiveRefCntPtr<vfs::FileSystem> FS) {
+calculateIncludePath(llvm::StringRef File, llvm::StringRef Code,
+ llvm::StringRef Header,
+ const tooling::CompileCommand &CompileCommand,
+ IntrusiveRefCntPtr<vfs::FileSystem> FS) {
+ assert(llvm::sys::path::is_absolute(File) &&
+ llvm::sys::path::is_absolute(Header));
+
+ if (File == Header)
+ return "";
+ FS->setCurrentWorkingDirectory(CompileCommand.Directory);
+
// Set up a CompilerInstance and create a preprocessor to collect existing
// #include headers in \p Code. Preprocesor also provides HeaderSearch with
// which we can calculate the shortest include path for \p Header.
OpenPOWER on IntegriCloud