summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/TestFS.h
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2018-08-10 22:27:53 +0000
committerSimon Marchi <simon.marchi@ericsson.com>2018-08-10 22:27:53 +0000
commit25f1f7325feac42b3bf05fd408e15b6a6be7d81c (patch)
tree1fd566738ae682a9d51df0b76d627cc3e69185fa /clang-tools-extra/unittests/clangd/TestFS.h
parente99ba6e1f9f1a682292247ad7898e1e133d51fe5 (diff)
downloadbcm5719-llvm-25f1f7325feac42b3bf05fd408e15b6a6be7d81c.tar.gz
bcm5719-llvm-25f1f7325feac42b3bf05fd408e15b6a6be7d81c.zip
[clangd] Avoid duplicates in findDefinitions response
Summary: When compile_commands.json contains some source files expressed as relative paths, we can get duplicate responses to findDefinitions. The responses only differ by the URI, which are different versions of the same file: "result": [ { ... "uri": "file:///home/emaisin/src/ls-interact/cpp-test/build/../src/first.h" }, { ... "uri": "file:///home/emaisin/src/ls-interact/cpp-test/src/first.h" } ] In getAbsoluteFilePath, we try to obtain the realpath of the FileEntry by calling tryGetRealPathName. However, this can fail and return an empty string. It may be bug a bug in clang, but in any case we should fall back to computing it ourselves if it happens. I changed getAbsoluteFilePath so that if tryGetRealPathName succeeds, we return right away (a real path is always absolute). Otherwise, we try to build an absolute path, as we did before, but we also call VFS->getRealPath to make sure to get the canonical path (e.g. without any ".." in it). Reviewers: malaperle Subscribers: hokein, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48687 llvm-svn: 339483
Diffstat (limited to 'clang-tools-extra/unittests/clangd/TestFS.h')
-rw-r--r--clang-tools-extra/unittests/clangd/TestFS.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/clang-tools-extra/unittests/clangd/TestFS.h b/clang-tools-extra/unittests/clangd/TestFS.h
index 9c2a15e63d3..a0efb755d00 100644
--- a/clang-tools-extra/unittests/clangd/TestFS.h
+++ b/clang-tools-extra/unittests/clangd/TestFS.h
@@ -40,15 +40,22 @@ public:
// A Compilation database that returns a fixed set of compile flags.
class MockCompilationDatabase : public GlobalCompilationDatabase {
public:
- /// When \p UseRelPaths is true, uses relative paths in compile commands.
- /// When \p UseRelPaths is false, uses absoulte paths.
- MockCompilationDatabase(bool UseRelPaths = false);
+ /// If \p Directory is not empty, use that as the Directory field of the
+ /// CompileCommand.
+ ///
+ /// If \p RelPathPrefix is not empty, use that as a prefix in front of the
+ /// source file name, instead of using an absolute path.
+ MockCompilationDatabase(StringRef Directory = StringRef(),
+ StringRef RelPathPrefix = StringRef());
llvm::Optional<tooling::CompileCommand>
getCompileCommand(PathRef File) const override;
std::vector<std::string> ExtraClangFlags;
- const bool UseRelPaths;
+
+private:
+ StringRef Directory;
+ StringRef RelPathPrefix;
};
// Returns an absolute (fake) test directory for this OS.
OpenPOWER on IntegriCloud