mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-03 07:38:57 +00:00
[clang][HeaderSuggestion] Handle the case of dotdot with an absolute path
Summary: Include insertion in clangd was inserting absolute paths when the include directory was an absolute path with a double dot. This patch makes sure double dots are handled both with absolute and relative paths. Reviewers: sammccall Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60873 llvm-svn: 359078
This commit is contained in:
parent
dcfa59c7d4
commit
936c67d3ef
@ -213,6 +213,11 @@ TEST_F(HeadersTest, DoNotInsertIfInSameFile) {
|
||||
TEST_F(HeadersTest, ShortenedInclude) {
|
||||
std::string BarHeader = testPath("sub/bar.h");
|
||||
EXPECT_EQ(calculate(BarHeader), "\"bar.h\"");
|
||||
|
||||
SearchDirArg = (llvm::Twine("-I") + Subdir + "/..").str();
|
||||
CDB.ExtraClangFlags = {SearchDirArg.c_str()};
|
||||
BarHeader = testPath("sub/bar.h");
|
||||
EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
|
||||
}
|
||||
|
||||
TEST_F(HeadersTest, NotShortenedInclude) {
|
||||
|
@ -1685,11 +1685,10 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
|
||||
|
||||
StringRef Dir = SearchDirs[I].getDir()->getName();
|
||||
llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
|
||||
if (!WorkingDir.empty() && !path::is_absolute(Dir)) {
|
||||
if (!WorkingDir.empty() && !path::is_absolute(Dir))
|
||||
fs::make_absolute(WorkingDir, DirPath);
|
||||
path::remove_dots(DirPath, /*remove_dot_dot=*/true);
|
||||
Dir = DirPath;
|
||||
}
|
||||
path::remove_dots(DirPath, /*remove_dot_dot=*/true);
|
||||
Dir = DirPath;
|
||||
for (auto NI = path::begin(File), NE = path::end(File),
|
||||
DI = path::begin(Dir), DE = path::end(Dir);
|
||||
/*termination condition in loop*/; ++NI, ++DI) {
|
||||
|
@ -100,5 +100,12 @@ TEST_F(HeaderSearchTest, BackSlash) {
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(HeaderSearchTest, DotDotsWithAbsPath) {
|
||||
addSearchDir("/x/../y/");
|
||||
EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z",
|
||||
/*WorkingDir=*/""),
|
||||
"z");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace clang
|
||||
|
Loading…
x
Reference in New Issue
Block a user