File tree Expand file tree Collapse file tree 5 files changed +20
-8
lines changed Expand file tree Collapse file tree 5 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -315,15 +315,15 @@ struct Fragment {
315
315
// / AngledHeaders (i.e. a header matches a regex in both QuotedHeaders and
316
316
// / AngledHeaders), system headers use <> and non-system headers use "".
317
317
// / These can match any suffix of the header file in question.
318
- // / Matching is performed against the header text, not its absolute path
318
+ // / Matching is performed against the absolute path of the header
319
319
// / within the project.
320
320
std::vector<Located<std::string>> QuotedHeaders;
321
321
// / List of regexes for headers that should always be included with a
322
322
// / <>-style include. By default, and in case of a conflict with
323
323
// / AngledHeaders (i.e. a header matches a regex in both QuotedHeaders and
324
324
// / AngledHeaders), system headers use <> and non-system headers use "".
325
325
// / These can match any suffix of the header file in question.
326
- // / Matching is performed against the header text, not its absolute path
326
+ // / Matching is performed against the absolute path of the header
327
327
// / within the project.
328
328
std::vector<Located<std::string>> AngledHeaders;
329
329
};
Original file line number Diff line number Diff line change @@ -304,16 +304,17 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader,
304
304
// FIXME: should we allow (some limited number of) "../header.h"?
305
305
if (llvm::sys::path::is_absolute (Suggested))
306
306
return std::nullopt;
307
+ auto HeaderPath = llvm::sys::path::convert_to_slash (InsertedHeader.File );
307
308
bool IsAngled = false ;
308
309
for (auto &Filter : AngledHeaders) {
309
- if (Filter (Suggested )) {
310
+ if (Filter (HeaderPath )) {
310
311
IsAngled = true ;
311
312
break ;
312
313
}
313
314
}
314
315
bool IsQuoted = false ;
315
316
for (auto &Filter : QuotedHeaders) {
316
- if (Filter (Suggested )) {
317
+ if (Filter (HeaderPath )) {
317
318
IsQuoted = true ;
318
319
break ;
319
320
}
@@ -324,7 +325,7 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader,
324
325
if (IsAngled && IsQuoted) {
325
326
elog (" Header '{0}' matches both quoted and angled regexes, default will "
326
327
" be used." ,
327
- Suggested );
328
+ HeaderPath );
328
329
}
329
330
IsAngled = IsAngledByDefault;
330
331
}
Original file line number Diff line number Diff line change @@ -938,7 +938,7 @@ TEST(CompletionTest, IncludeInsertionRespectsQuotedAngledConfig) {
938
938
{
939
939
Config C;
940
940
C.Style .AngledHeaders .push_back (
941
- [](auto header) { return header == " bar.h" ; });
941
+ [](auto header) { return header. contains ( " bar.h" ) ; });
942
942
WithContextValue WithCfg (Config::Key, std::move (C));
943
943
Results = completions (TU, Test.point (), {Sym});
944
944
EXPECT_THAT (Results.Completions ,
@@ -947,7 +947,7 @@ TEST(CompletionTest, IncludeInsertionRespectsQuotedAngledConfig) {
947
947
{
948
948
Config C;
949
949
C.Style .QuotedHeaders .push_back (
950
- [](auto header) { return header == " bar.h" ; });
950
+ [](auto header) { return header. contains ( " bar.h" ) ; });
951
951
WithContextValue WithCfg (Config::Key, std::move (C));
952
952
Results = completions (TU, Test.point (), {Sym});
953
953
EXPECT_THAT (Results.Completions ,
Original file line number Diff line number Diff line change @@ -344,6 +344,17 @@ TEST_F(HeadersTest, ShortenIncludesInSearchPathBracketed) {
344
344
EXPECT_EQ (calculate (BarHeader), " <sub/bar.h>" );
345
345
}
346
346
347
+ TEST_F (HeadersTest, ShortenIncludesInSearchPathBracketedFilterByFullPath) {
348
+ // The filter receives the full path of the header, so it is able to filter by
349
+ // the parent directory, even if it is part of the include search path
350
+ AngledHeaders.push_back ([](auto Path) {
351
+ llvm::Regex Pattern (" sub/.*" );
352
+ return Pattern.match (Path);
353
+ });
354
+ std::string BarHeader = testPath (" sub/bar.h" );
355
+ EXPECT_EQ (calculate (BarHeader), " <bar.h>" );
356
+ }
357
+
347
358
TEST_F (HeadersTest, ShortenedIncludeNotInSearchPath) {
348
359
std::string BarHeader =
349
360
llvm::sys::path::convert_to_slash (testPath (" sub-2/bar.h" ));
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ struct Header {
136
136
}
137
137
StringRef verbatim () const { return std::get<Verbatim>(Storage); }
138
138
139
- // / For phiscal files, either absolute path or path relative to the execution
139
+ // / For physical files, either absolute path or path relative to the execution
140
140
// / root. Otherwise just the spelling without surrounding quotes/brackets.
141
141
llvm::StringRef resolvedPath () const ;
142
142
You can’t perform that action at this time.
0 commit comments