@@ -36,9 +36,12 @@ namespace {
3636using ::testing::ElementsAre;
3737using ::testing::IsEmpty;
3838
39- std::vector<InlayHint> hintsOfKind (ParsedAST &AST, InlayHintKind Kind) {
39+ constexpr InlayHintOptions DefaultInlayHintOpts{};
40+
41+ std::vector<InlayHint> hintsOfKind (ParsedAST &AST, InlayHintKind Kind,
42+ InlayHintOptions Opts) {
4043 std::vector<InlayHint> Result;
41- for (auto &Hint : inlayHints (AST, /* RestrictRange=*/ std::nullopt )) {
44+ for (auto &Hint : inlayHints (AST, /* RestrictRange=*/ std::nullopt , Opts )) {
4245 if (Hint.kind == Kind)
4346 Result.push_back (Hint);
4447 }
@@ -90,26 +93,26 @@ Config noHintsConfig() {
9093
9194template <typename ... ExpectedHints>
9295void assertHintsWithHeader (InlayHintKind Kind, llvm::StringRef AnnotatedSource,
93- llvm::StringRef HeaderContent,
96+ llvm::StringRef HeaderContent, InlayHintOptions Opts,
9497 ExpectedHints... Expected) {
9598 Annotations Source (AnnotatedSource);
9699 TestTU TU = TestTU::withCode (Source.code ());
97100 TU.ExtraArgs .push_back (" -std=c++23" );
98101 TU.HeaderCode = HeaderContent;
99102 auto AST = TU.build ();
100103
101- EXPECT_THAT (hintsOfKind (AST, Kind),
104+ EXPECT_THAT (hintsOfKind (AST, Kind, Opts ),
102105 ElementsAre (HintMatcher (Expected, Source)...));
103106 // Sneak in a cross-cutting check that hints are disabled by config.
104107 // We'll hit an assertion failure if addInlayHint still gets called.
105108 WithContextValue WithCfg (Config::Key, noHintsConfig ());
106- EXPECT_THAT (inlayHints (AST, std::nullopt ), IsEmpty ());
109+ EXPECT_THAT (inlayHints (AST, std::nullopt , Opts ), IsEmpty ());
107110}
108111
109112template <typename ... ExpectedHints>
110113void assertHints (InlayHintKind Kind, llvm::StringRef AnnotatedSource,
111- ExpectedHints... Expected) {
112- return assertHintsWithHeader (Kind, AnnotatedSource, " " ,
114+ InlayHintOptions Opts, ExpectedHints... Expected) {
115+ return assertHintsWithHeader (Kind, AnnotatedSource, " " , Opts,
113116 std::move (Expected)...);
114117}
115118
@@ -120,14 +123,16 @@ template <typename... ExpectedHints>
120123void assertParameterHints (llvm::StringRef AnnotatedSource,
121124 ExpectedHints... Expected) {
122125 ignore (Expected.Side = Left...);
123- assertHints (InlayHintKind::Parameter, AnnotatedSource, Expected...);
126+ assertHints (InlayHintKind::Parameter, AnnotatedSource, DefaultInlayHintOpts,
127+ Expected...);
124128}
125129
126130template <typename ... ExpectedHints>
127131void assertTypeHints (llvm::StringRef AnnotatedSource,
128132 ExpectedHints... Expected) {
129133 ignore (Expected.Side = Right...);
130- assertHints (InlayHintKind::Type, AnnotatedSource, Expected...);
134+ assertHints (InlayHintKind::Type, AnnotatedSource, DefaultInlayHintOpts,
135+ Expected...);
131136}
132137
133138template <typename ... ExpectedHints>
@@ -136,16 +141,25 @@ void assertDesignatorHints(llvm::StringRef AnnotatedSource,
136141 Config Cfg;
137142 Cfg.InlayHints .Designators = true ;
138143 WithContextValue WithCfg (Config::Key, std::move (Cfg));
139- assertHints (InlayHintKind::Designator, AnnotatedSource, Expected...);
144+ assertHints (InlayHintKind::Designator, AnnotatedSource, DefaultInlayHintOpts,
145+ Expected...);
140146}
141147
142148template <typename ... ExpectedHints>
143- void assertBlockEndHints (llvm::StringRef AnnotatedSource,
144- ExpectedHints... Expected) {
149+ void assertBlockEndHintsWithOpts (llvm::StringRef AnnotatedSource,
150+ InlayHintOptions Opts,
151+ ExpectedHints... Expected) {
145152 Config Cfg;
146153 Cfg.InlayHints .BlockEnd = true ;
147154 WithContextValue WithCfg (Config::Key, std::move (Cfg));
148- assertHints (InlayHintKind::BlockEnd, AnnotatedSource, Expected...);
155+ assertHints (InlayHintKind::BlockEnd, AnnotatedSource, Opts, Expected...);
156+ }
157+
158+ template <typename ... ExpectedHints>
159+ void assertBlockEndHints (llvm::StringRef AnnotatedSource,
160+ ExpectedHints... Expected) {
161+ assertBlockEndHintsWithOpts (AnnotatedSource, DefaultInlayHintOpts,
162+ Expected...);
149163}
150164
151165TEST (ParameterHints, Smoke) {
@@ -1226,7 +1240,9 @@ TEST(ParameterHints, IncludeAtNonGlobalScope) {
12261240 ASSERT_TRUE (bool (AST));
12271241
12281242 // Ensure the hint for the call in foo.inc is NOT materialized in foo.cc.
1229- EXPECT_EQ (hintsOfKind (*AST, InlayHintKind::Parameter).size (), 0u );
1243+ EXPECT_EQ (
1244+ hintsOfKind (*AST, InlayHintKind::Parameter, DefaultInlayHintOpts).size (),
1245+ 0u );
12301246}
12311247
12321248TEST (TypeHints, Smoke) {
@@ -1488,12 +1504,12 @@ TEST(DefaultArguments, Smoke) {
14881504 void baz(int = 5) { if (false) baz($unnamed[[)]]; };
14891505 )cpp" ;
14901506
1491- assertHints (InlayHintKind::DefaultArgument, Code,
1507+ assertHints (InlayHintKind::DefaultArgument, Code, DefaultInlayHintOpts,
14921508 ExpectedHint{" A: 4" , " default1" , Left},
14931509 ExpectedHint{" , B: 1, C: foo()" , " default2" , Left},
14941510 ExpectedHint{" 5" , " unnamed" , Left});
14951511
1496- assertHints (InlayHintKind::Parameter, Code,
1512+ assertHints (InlayHintKind::Parameter, Code, DefaultInlayHintOpts,
14971513 ExpectedHint{" A: " , " explicit" , Left});
14981514}
14991515
@@ -1528,14 +1544,14 @@ TEST(DefaultArguments, WithoutParameterNames) {
15281544 }
15291545 )cpp" ;
15301546
1531- assertHints (InlayHintKind::DefaultArgument, Code,
1547+ assertHints (InlayHintKind::DefaultArgument, Code, DefaultInlayHintOpts,
15321548 ExpectedHint{" ..." , " abbreviated" , Left},
15331549 ExpectedHint{" , Baz{}" , " paren" , Left},
15341550 ExpectedHint{" , Baz{}" , " brace1" , Left},
15351551 ExpectedHint{" , Baz{}" , " brace2" , Left},
15361552 ExpectedHint{" , Baz{}" , " brace3" , Left});
15371553
1538- assertHints (InlayHintKind::Parameter, Code);
1554+ assertHints (InlayHintKind::Parameter, Code, DefaultInlayHintOpts );
15391555}
15401556
15411557TEST (TypeHints, Deduplication) {
@@ -1573,7 +1589,8 @@ TEST(TypeHints, Aliased) {
15731589 TU.ExtraArgs .push_back (" -xc" );
15741590 auto AST = TU.build ();
15751591
1576- EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type), IsEmpty ());
1592+ EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type, DefaultInlayHintOpts),
1593+ IsEmpty ());
15771594}
15781595
15791596TEST (TypeHints, CallingConvention) {
@@ -1590,7 +1607,7 @@ TEST(TypeHints, CallingConvention) {
15901607 auto AST = TU.build ();
15911608
15921609 EXPECT_THAT (
1593- hintsOfKind (AST, InlayHintKind::Type),
1610+ hintsOfKind (AST, InlayHintKind::Type, DefaultInlayHintOpts ),
15941611 ElementsAre (HintMatcher (ExpectedHint{" -> void" , " lambda" }, Source)));
15951612}
15961613
@@ -1673,7 +1690,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
16731690 )cpp" ;
16741691
16751692 assertHintsWithHeader (
1676- InlayHintKind::Type, VectorIntPtr, Header,
1693+ InlayHintKind::Type, VectorIntPtr, Header, DefaultInlayHintOpts,
16771694 ExpectedHint{" : int *" , " no_modifier" },
16781695 ExpectedHint{" : int **" , " ptr_modifier" },
16791696 ExpectedHint{" : int *&" , " ref_modifier" },
@@ -1697,7 +1714,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
16971714 )cpp" ;
16981715
16991716 assertHintsWithHeader (
1700- InlayHintKind::Type, VectorInt, Header,
1717+ InlayHintKind::Type, VectorInt, Header, DefaultInlayHintOpts,
17011718 ExpectedHint{" : int" , " no_modifier" },
17021719 ExpectedHint{" : int *" , " ptr_modifier" },
17031720 ExpectedHint{" : int &" , " ref_modifier" },
@@ -1724,6 +1741,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
17241741 )cpp" ;
17251742
17261743 assertHintsWithHeader (InlayHintKind::Type, TypeAlias, Header,
1744+ DefaultInlayHintOpts,
17271745 ExpectedHint{" : Short" , " short_name" },
17281746 ExpectedHint{" : static_vector<int>" , " vector_name" });
17291747}
@@ -2124,30 +2142,41 @@ TEST(BlockEndHints, PrintRefs) {
21242142 R"cpp(
21252143 namespace ns {
21262144 int Var;
2127- int func();
2145+ int func1();
2146+ int func2(int, int);
21282147 struct S {
21292148 int Field;
2130- int method() const;
2149+ int method1() const;
2150+ int method2(int, int) const;
21312151 }; // suppress
21322152 } // suppress
21332153 void foo() {
2154+ int int_a {};
21342155 while (ns::Var) {
21352156 $var[[}]]
21362157
2137- while (ns::func()) {
2138- $func[[}]]
2158+ while (ns::func1()) {
2159+ $func1[[}]]
2160+
2161+ while (ns::func2(int_a, int_a)) {
2162+ $func2[[}]]
21392163
21402164 while (ns::S{}.Field) {
21412165 $field[[}]]
21422166
2143- while (ns::S{}.method()) {
2144- $method[[}]]
2167+ while (ns::S{}.method1()) {
2168+ $method1[[}]]
2169+
2170+ while (ns::S{}.method2(int_a, int_a)) {
2171+ $method2[[}]]
21452172 } // suppress
21462173 )cpp" ,
21472174 ExpectedHint{" // while Var" , " var" },
2148- ExpectedHint{" // while func" , " func" },
2175+ ExpectedHint{" // while func1()" , " func1" },
2176+ ExpectedHint{" // while func2(...)" , " func2" },
21492177 ExpectedHint{" // while Field" , " field" },
2150- ExpectedHint{" // while method" , " method" });
2178+ ExpectedHint{" // while method1()" , " method1" },
2179+ ExpectedHint{" // while method2(...)" , " method2" });
21512180}
21522181
21532182TEST (BlockEndHints, PrintConversions) {
@@ -2307,7 +2336,7 @@ TEST(BlockEndHints, PointerToMemberFunction) {
23072336 $ptrmem[[}]]
23082337 } // suppress
23092338 )cpp" ,
2310- ExpectedHint{" // if" , " ptrmem" });
2339+ ExpectedHint{" // if () " , " ptrmem" });
23112340}
23122341
23132342// FIXME: Low-hanging fruit where we could omit a type hint:
0 commit comments