diff options
author | Sam McCall <sam.mccall@gmail.com> | 2022-01-06 02:01:13 +0100 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2022-01-10 10:26:48 +0100 |
commit | 22a34e01066004c9bd8d7ad418df90b8fbcb3749 (patch) | |
tree | 940b73f0bc8ba2eb69230842575fa65f4061e998 /clang-tools-extra/clangd/unittests/InlayHintTests.cpp | |
parent | ad1b8772cf6b16c1162bb8ff425679f5ff046ae9 (diff) | |
download | llvm-maain.tar.gz |
[clangd] Support configuration of inlay hints.maain
The idea is that the feature will always be advertised at the LSP level, but
depending on config we'll return partial or no responses.
We try to avoid doing the analysis for hints we're not going to return.
Examples of syntax:
```
InlayHints:
Enabled: No
---
InlayHints:
ParameterNames: No
---
InlayHints:
ParameterNames: Yes
DeducedTypes: Yes
```
Differential Revision: https://reviews.llvm.org/D116713
Diffstat (limited to 'clang-tools-extra/clangd/unittests/InlayHintTests.cpp')
-rw-r--r-- | clang-tools-extra/clangd/unittests/InlayHintTests.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp index e8880981c1a4..992ec0e012ae 100644 --- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp +++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp @@ -6,11 +6,13 @@ // //===----------------------------------------------------------------------===// #include "Annotations.h" +#include "Config.h" #include "InlayHints.h" #include "Protocol.h" #include "TestTU.h" #include "TestWorkspace.h" #include "XRefs.h" +#include "support/Context.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -24,6 +26,8 @@ std::ostream &operator<<(std::ostream &Stream, const InlayHint &Hint) { namespace { using ::testing::ElementsAre; +using ::testing::IsEmpty; +using ::testing::UnorderedElementsAre; std::vector<InlayHint> hintsOfKind(ParsedAST &AST, InlayHintKind Kind) { std::vector<InlayHint> Result; @@ -56,6 +60,13 @@ MATCHER_P2(HintMatcher, Expected, Code, "") { MATCHER_P(labelIs, Label, "") { return arg.label == Label; } +Config noHintsConfig() { + Config C; + C.InlayHints.Parameters = false; + C.InlayHints.DeducedTypes = false; + return C; +} + template <typename... ExpectedHints> void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource, ExpectedHints... Expected) { @@ -66,6 +77,10 @@ void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource, 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, llvm::None), IsEmpty()); } // Hack to allow expression-statements operating on parameter packs in C++14. |