@@ -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) {
@@ -1589,7 +1606,8 @@ TEST(TypeHints, CallingConvention) {
15891606 TU.PredefineMacros = true ; // for the __cdecl
15901607 auto AST = TU.build ();
15911608
1592- EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type), IsEmpty ());
1609+ EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type, DefaultInlayHintOpts),
1610+ IsEmpty ());
15931611}
15941612
15951613TEST (TypeHints, Decltype) {
@@ -1671,7 +1689,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
16711689 )cpp" ;
16721690
16731691 assertHintsWithHeader (
1674- InlayHintKind::Type, VectorIntPtr, Header,
1692+ InlayHintKind::Type, VectorIntPtr, Header, DefaultInlayHintOpts,
16751693 ExpectedHint{" : int *" , " no_modifier" },
16761694 ExpectedHint{" : int **" , " ptr_modifier" },
16771695 ExpectedHint{" : int *&" , " ref_modifier" },
@@ -1695,7 +1713,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
16951713 )cpp" ;
16961714
16971715 assertHintsWithHeader (
1698- InlayHintKind::Type, VectorInt, Header,
1716+ InlayHintKind::Type, VectorInt, Header, DefaultInlayHintOpts,
16991717 ExpectedHint{" : int" , " no_modifier" },
17001718 ExpectedHint{" : int *" , " ptr_modifier" },
17011719 ExpectedHint{" : int &" , " ref_modifier" },
@@ -1722,6 +1740,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
17221740 )cpp" ;
17231741
17241742 assertHintsWithHeader (InlayHintKind::Type, TypeAlias, Header,
1743+ DefaultInlayHintOpts,
17251744 ExpectedHint{" : Short" , " short_name" },
17261745 ExpectedHint{" : static_vector<int>" , " vector_name" });
17271746}
@@ -2122,30 +2141,41 @@ TEST(BlockEndHints, PrintRefs) {
21222141 R"cpp(
21232142 namespace ns {
21242143 int Var;
2125- int func();
2144+ int func1();
2145+ int func2(int, int);
21262146 struct S {
21272147 int Field;
2128- int method() const;
2148+ int method1() const;
2149+ int method2(int, int) const;
21292150 }; // suppress
21302151 } // suppress
21312152 void foo() {
2153+ int int_a {};
21322154 while (ns::Var) {
21332155 $var[[}]]
21342156
2135- while (ns::func()) {
2136- $func[[}]]
2157+ while (ns::func1()) {
2158+ $func1[[}]]
2159+
2160+ while (ns::func2(int_a, int_a)) {
2161+ $func2[[}]]
21372162
21382163 while (ns::S{}.Field) {
21392164 $field[[}]]
21402165
2141- while (ns::S{}.method()) {
2142- $method[[}]]
2166+ while (ns::S{}.method1()) {
2167+ $method1[[}]]
2168+
2169+ while (ns::S{}.method2(int_a, int_a)) {
2170+ $method2[[}]]
21432171 } // suppress
21442172 )cpp" ,
21452173 ExpectedHint{" // while Var" , " var" },
2146- ExpectedHint{" // while func" , " func" },
2174+ ExpectedHint{" // while func1()" , " func1" },
2175+ ExpectedHint{" // while func2(...)" , " func2" },
21472176 ExpectedHint{" // while Field" , " field" },
2148- ExpectedHint{" // while method" , " method" });
2177+ ExpectedHint{" // while method1()" , " method1" },
2178+ ExpectedHint{" // while method2(...)" , " method2" });
21492179}
21502180
21512181TEST (BlockEndHints, PrintConversions) {
@@ -2305,7 +2335,7 @@ TEST(BlockEndHints, PointerToMemberFunction) {
23052335 $ptrmem[[}]]
23062336 } // suppress
23072337 )cpp" ,
2308- ExpectedHint{" // if" , " ptrmem" });
2338+ ExpectedHint{" // if () " , " ptrmem" });
23092339}
23102340
23112341// FIXME: Low-hanging fruit where we could omit a type hint:
0 commit comments