Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 21faecd

Browse files
committedApr 21, 2025·
Review comments
1 parent 1dceb5b commit 21faecd

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed
 

‎clang-tools-extra/clangd/InlayHints.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ namespace clangd {
2323
class ParsedAST;
2424

2525
struct InlayHintOptions {
26-
// Minimum lines for BlockEnd inlay-hints to be shown
27-
int HintMinLineLimit{2};
26+
// Minimum height of a code block in lines for a BlockEnd hint to be shown
27+
// Includes the lines containing the braces
28+
int HintMinLineLimit = 10;
2829
};
2930

3031
/// Compute and return inlay hints for a file.

‎clang-tools-extra/clangd/unittests/InlayHintTests.cpp

+26-17
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace {
3636
using ::testing::ElementsAre;
3737
using ::testing::IsEmpty;
3838

39-
constexpr InlayHintOptions DefaultInlayHintOpts{};
39+
constexpr InlayHintOptions DefaultOptsForTests{2};
4040

4141
std::vector<InlayHint> hintsOfKind(ParsedAST &AST, InlayHintKind Kind,
4242
InlayHintOptions Opts) {
@@ -123,15 +123,15 @@ template <typename... ExpectedHints>
123123
void assertParameterHints(llvm::StringRef AnnotatedSource,
124124
ExpectedHints... Expected) {
125125
ignore(Expected.Side = Left...);
126-
assertHints(InlayHintKind::Parameter, AnnotatedSource, DefaultInlayHintOpts,
126+
assertHints(InlayHintKind::Parameter, AnnotatedSource, DefaultOptsForTests,
127127
Expected...);
128128
}
129129

130130
template <typename... ExpectedHints>
131131
void assertTypeHints(llvm::StringRef AnnotatedSource,
132132
ExpectedHints... Expected) {
133133
ignore(Expected.Side = Right...);
134-
assertHints(InlayHintKind::Type, AnnotatedSource, DefaultInlayHintOpts,
134+
assertHints(InlayHintKind::Type, AnnotatedSource, DefaultOptsForTests,
135135
Expected...);
136136
}
137137

@@ -141,7 +141,7 @@ void assertDesignatorHints(llvm::StringRef AnnotatedSource,
141141
Config Cfg;
142142
Cfg.InlayHints.Designators = true;
143143
WithContextValue WithCfg(Config::Key, std::move(Cfg));
144-
assertHints(InlayHintKind::Designator, AnnotatedSource, DefaultInlayHintOpts,
144+
assertHints(InlayHintKind::Designator, AnnotatedSource, DefaultOptsForTests,
145145
Expected...);
146146
}
147147

@@ -158,7 +158,7 @@ void assertBlockEndHintsWithOpts(llvm::StringRef AnnotatedSource,
158158
template <typename... ExpectedHints>
159159
void assertBlockEndHints(llvm::StringRef AnnotatedSource,
160160
ExpectedHints... Expected) {
161-
assertBlockEndHintsWithOpts(AnnotatedSource, DefaultInlayHintOpts,
161+
assertBlockEndHintsWithOpts(AnnotatedSource, DefaultOptsForTests,
162162
Expected...);
163163
}
164164

@@ -1241,7 +1241,7 @@ TEST(ParameterHints, IncludeAtNonGlobalScope) {
12411241

12421242
// Ensure the hint for the call in foo.inc is NOT materialized in foo.cc.
12431243
EXPECT_EQ(
1244-
hintsOfKind(*AST, InlayHintKind::Parameter, DefaultInlayHintOpts).size(),
1244+
hintsOfKind(*AST, InlayHintKind::Parameter, DefaultOptsForTests).size(),
12451245
0u);
12461246
}
12471247

@@ -1504,12 +1504,12 @@ TEST(DefaultArguments, Smoke) {
15041504
void baz(int = 5) { if (false) baz($unnamed[[)]]; };
15051505
)cpp";
15061506

1507-
assertHints(InlayHintKind::DefaultArgument, Code, DefaultInlayHintOpts,
1507+
assertHints(InlayHintKind::DefaultArgument, Code, DefaultOptsForTests,
15081508
ExpectedHint{"A: 4", "default1", Left},
15091509
ExpectedHint{", B: 1, C: foo()", "default2", Left},
15101510
ExpectedHint{"5", "unnamed", Left});
15111511

1512-
assertHints(InlayHintKind::Parameter, Code, DefaultInlayHintOpts,
1512+
assertHints(InlayHintKind::Parameter, Code, DefaultOptsForTests,
15131513
ExpectedHint{"A: ", "explicit", Left});
15141514
}
15151515

@@ -1544,14 +1544,14 @@ TEST(DefaultArguments, WithoutParameterNames) {
15441544
}
15451545
)cpp";
15461546

1547-
assertHints(InlayHintKind::DefaultArgument, Code, DefaultInlayHintOpts,
1547+
assertHints(InlayHintKind::DefaultArgument, Code, DefaultOptsForTests,
15481548
ExpectedHint{"...", "abbreviated", Left},
15491549
ExpectedHint{", Baz{}", "paren", Left},
15501550
ExpectedHint{", Baz{}", "brace1", Left},
15511551
ExpectedHint{", Baz{}", "brace2", Left},
15521552
ExpectedHint{", Baz{}", "brace3", Left});
15531553

1554-
assertHints(InlayHintKind::Parameter, Code, DefaultInlayHintOpts);
1554+
assertHints(InlayHintKind::Parameter, Code, DefaultOptsForTests);
15551555
}
15561556

15571557
TEST(TypeHints, Deduplication) {
@@ -1589,7 +1589,7 @@ TEST(TypeHints, Aliased) {
15891589
TU.ExtraArgs.push_back("-xc");
15901590
auto AST = TU.build();
15911591

1592-
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type, DefaultInlayHintOpts),
1592+
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type, DefaultOptsForTests),
15931593
IsEmpty());
15941594
}
15951595

@@ -1606,7 +1606,7 @@ TEST(TypeHints, CallingConvention) {
16061606
TU.PredefineMacros = true; // for the __cdecl
16071607
auto AST = TU.build();
16081608

1609-
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type, DefaultInlayHintOpts),
1609+
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type, DefaultOptsForTests),
16101610
IsEmpty());
16111611
}
16121612

@@ -1689,7 +1689,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
16891689
)cpp";
16901690

16911691
assertHintsWithHeader(
1692-
InlayHintKind::Type, VectorIntPtr, Header, DefaultInlayHintOpts,
1692+
InlayHintKind::Type, VectorIntPtr, Header, DefaultOptsForTests,
16931693
ExpectedHint{": int *", "no_modifier"},
16941694
ExpectedHint{": int **", "ptr_modifier"},
16951695
ExpectedHint{": int *&", "ref_modifier"},
@@ -1713,7 +1713,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
17131713
)cpp";
17141714

17151715
assertHintsWithHeader(
1716-
InlayHintKind::Type, VectorInt, Header, DefaultInlayHintOpts,
1716+
InlayHintKind::Type, VectorInt, Header, DefaultOptsForTests,
17171717
ExpectedHint{": int", "no_modifier"},
17181718
ExpectedHint{": int *", "ptr_modifier"},
17191719
ExpectedHint{": int &", "ref_modifier"},
@@ -1740,7 +1740,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
17401740
)cpp";
17411741

17421742
assertHintsWithHeader(InlayHintKind::Type, TypeAlias, Header,
1743-
DefaultInlayHintOpts,
1743+
DefaultOptsForTests,
17441744
ExpectedHint{": Short", "short_name"},
17451745
ExpectedHint{": static_vector<int>", "vector_name"});
17461746
}
@@ -2033,6 +2033,7 @@ TEST(BlockEndHints, If) {
20332033
assertBlockEndHints(
20342034
R"cpp(
20352035
void foo(bool cond) {
2036+
void* ptr;
20362037
if (cond)
20372038
;
20382039
@@ -2058,13 +2059,17 @@ TEST(BlockEndHints, If) {
20582059
20592060
if (int i = 0; i > 10) {
20602061
$init_cond[[}]]
2062+
2063+
if (ptr != nullptr) {
2064+
$null_check[[}]]
20612065
} // suppress
20622066
)cpp",
20632067
ExpectedHint{" // if cond", "simple"},
20642068
ExpectedHint{" // if cond", "ifelse"}, ExpectedHint{" // if", "elseif"},
20652069
ExpectedHint{" // if !cond", "inner"},
20662070
ExpectedHint{" // if cond", "outer"}, ExpectedHint{" // if X", "init"},
2067-
ExpectedHint{" // if i > 10", "init_cond"});
2071+
ExpectedHint{" // if i > 10", "init_cond"},
2072+
ExpectedHint{" // if ptr != nullptr", "null_check"});
20682073
}
20692074

20702075
TEST(BlockEndHints, Loops) {
@@ -2339,6 +2344,10 @@ TEST(BlockEndHints, PointerToMemberFunction) {
23392344
}
23402345

23412346
TEST(BlockEndHints, MinLineLimit) {
2347+
InlayHintOptions Opts;
2348+
Opts.HintMinLineLimit = 10;
2349+
2350+
// namespace ns below is exactly 10 lines
23422351
assertBlockEndHintsWithOpts(
23432352
R"cpp(
23442353
namespace ns {
@@ -2372,7 +2381,7 @@ TEST(BlockEndHints, MinLineLimit) {
23722381
$method2[[}]]
23732382
$foo[[}]]
23742383
)cpp",
2375-
InlayHintOptions{10}, ExpectedHint{" // namespace ns", "namespace"},
2384+
Opts, ExpectedHint{" // namespace ns", "namespace"},
23762385
ExpectedHint{" // foo", "foo"});
23772386
}
23782387

0 commit comments

Comments
 (0)
Please sign in to comment.