[PATCH] D147395: [Clangd] Make the type hint length limit configurable
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 20 02:42:28 PDT 2023
hokein added a comment.
In D147395#4253753 <https://reviews.llvm.org/D147395#4253753>, @zhangyi1357 wrote:
> I dont have commit access. Could you help committing the change for me? @hokein
sure, I will land it for you (sorry for the late response).
================
Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:80
C.InlayHints.Designators = false;
+ C.InlayHints.TypeNameLimit = 1;
return C;
----------------
zhangyi1357 wrote:
> hokein wrote:
> > why do we need this change? I think it should be fine without it.
> Yes, without this line the tests will not fail. But I am a little confused about the code below without 'C.InlayHints.TypeNameLimit = 1;'.
> ```
> Config noHintsConfig() {
> Config C;
> C.InlayHints.Parameters = false;
> C.InlayHints.DeducedTypes = false;
> C.InlayHints.Designators = false;
> // C.InlayHints.TypeNameLimit = 1;
> return C;
> }
>
> template <typename... ExpectedHints>
> void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
> ExpectedHints... Expected) {
> Annotations Source(AnnotatedSource);
> TestTU TU = TestTU::withCode(Source.code());
> TU.ExtraArgs.push_back("-std=c++20");
> auto AST = TU.build();
>
> EXPECT_THAT(hintsOfKind(AST, Kind),
> ElementsAre(HintMatcher(Expected, Source)...));
> // Sneak in a cross-cutting check that hints are disabled by config.
> // We'll hit an assertion failure if addInlayHint still gets called.
> WithContextValue WithCfg(Config::Key, noHintsConfig());
> EXPECT_THAT(inlayHints(AST, std::nullopt), IsEmpty()); // Why does this succeed with TypeNameLimit = 32 ?
> }
>
> TEST(TypeHints, Smoke) {
> assertTypeHints(R"cpp(
> auto $waldo[[waldo]] = 42;
> )cpp",
> ExpectedHint{": int", "waldo"});
> }
> ```
> The dault TypeNameLimit is 32, why does the second `EXPECT_THAT` succeed with TypeNameLimit = 32.
The second `EXPECT_THAT(inlayHints(AST, std::nullopt), IsEmpty());` is expected, because we have disabled the inlay-hint by the previous statement `WithContextValue WithCfg(Config::Key, noHintsConfig());`, so the expected result is empty.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147395/new/
https://reviews.llvm.org/D147395
More information about the cfe-commits
mailing list