lh123 updated this revision to Diff 390158.
lh123 retitled this revision from "[clangd] Add a way to enable a.k.a print
through config" to "[clangd] Make a.k.a printing configurable.".
lh123 added a comment.
fix testcase.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114665/new/
https://reviews.llvm.org/D114665
Files:
clang-tools-extra/clangd/Config.h
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/ConfigFragment.h
clang-tools-extra/clangd/ConfigYAML.cpp
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -8,6 +8,7 @@
#include "AST.h"
#include "Annotations.h"
+#include "Config.h"
#include "Hover.h"
#include "TestIndex.h"
#include "TestTU.h"
@@ -979,6 +980,9 @@
// fixed one to make sure tests passes on different platform.
TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
auto AST = TU.build();
+ Config Cfg;
+ Cfg.Hover.AKAPrint = true;
+ WithContextValue WithCfg(Config::Key, std::move(Cfg));
auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
ASSERT_TRUE(H);
@@ -2510,7 +2514,9 @@
// fixed one to make sure tests passes on different platform.
TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
auto AST = TU.build();
-
+ Config Cfg;
+ Cfg.Hover.AKAPrint = true;
+ WithContextValue WithCfg(Config::Key, std::move(Cfg));
auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
ASSERT_TRUE(H);
HoverInfo Expected;
@@ -2873,6 +2879,9 @@
for (const auto &C : Cases) {
HoverInfo HI;
C.Builder(HI);
+ Config Cfg;
+ Cfg.Hover.AKAPrint = true;
+ WithContextValue WithCfg(Config::Key, std::move(Cfg));
EXPECT_EQ(HI.present().asPlainText(), C.ExpectedRender);
}
}
Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -215,6 +215,19 @@
ASSERT_EQ(Results.size(), 1u);
EXPECT_THAT(Results[0].Completion.AllScopes, testing::Eq(llvm::None));
}
+
+TEST(ParseYAML, AKAPrint) {
+ CapturedDiags Diags;
+ Annotations YAML(R"yaml(
+Hover:
+ AKAPrint: True
+ )yaml");
+ auto Results =
+ Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+ ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+ ASSERT_EQ(Results.size(), 1u);
+ EXPECT_THAT(Results[0].Hover.AKAPrint, llvm::ValueIs(Val(true)));
+}
} // namespace
} // namespace config
} // namespace clangd
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -10,6 +10,7 @@
#include "AST.h"
#include "CodeCompletionStrings.h"
+#include "Config.h"
#include "FindTarget.h"
#include "ParsedAST.h"
#include "Selection.h"
@@ -159,7 +160,9 @@
}
QT.print(OS, PP);
OS.flush();
- if (!QT.isNull()) {
+
+ const Config &Cfg = Config::current();
+ if (!QT.isNull() && Cfg.Hover.AKAPrint) {
bool ShouldAKA = false;
QualType DesugaredTy = clang::desugarForDiagnostic(ASTCtx, QT, ShouldAKA);
if (ShouldAKA)
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===================================================================
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -65,6 +65,7 @@
Dict.handle("Style", [&](Node &N) { parse(F.Style, N); });
Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); });
Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); });
+ Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); });
Dict.parse(N);
return !(N.failed() || HadError);
}
@@ -204,6 +205,19 @@
Dict.parse(N);
}
+ void parse(Fragment::HoverBlock &F, Node &N) {
+ DictParser Dict("Hover", this);
+ Dict.handle("AKAPrint", [&](Node &N) {
+ if (auto Value = scalarValue(N, "AKAPrint")) {
+ if (auto AKAPrint = llvm::yaml::parseBool(**Value))
+ F.AKAPrint = *AKAPrint;
+ else
+ warning("AKAPrint should be a boolean", N);
+ }
+ });
+ Dict.parse(N);
+ }
+
// Helper for parsing mapping nodes (dictionaries).
// We don't use YamlIO as we want to control over unknown keys.
class DictParser {
Index: clang-tools-extra/clangd/ConfigFragment.h
===================================================================
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -266,6 +266,13 @@
llvm::Optional<Located<bool>> AllScopes;
};
CompletionBlock Completion;
+
+ /// Describes hover preferences.
+ struct HoverBlock {
+ /// Whether hover show a.k.a type.
+ llvm::Optional<Located<bool>> AKAPrint;
+ };
+ HoverBlock Hover;
};
} // namespace config
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===================================================================
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -196,6 +196,7 @@
compile(std::move(F.Index));
compile(std::move(F.Diagnostics));
compile(std::move(F.Completion));
+ compile(std::move(F.Hover));
}
void compile(Fragment::IfBlock &&F) {
@@ -507,6 +508,14 @@
}
}
+ void compile(Fragment::HoverBlock &&F) {
+ if (F.AKAPrint) {
+ Out.Apply.push_back([AKAPrint(**F.AKAPrint)](const Params &, Config &C) {
+ C.Hover.AKAPrint = AKAPrint;
+ });
+ }
+ }
+
constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
constexpr static llvm::SourceMgr::DiagKind Warning =
llvm::SourceMgr::DK_Warning;
Index: clang-tools-extra/clangd/Config.h
===================================================================
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -116,6 +116,12 @@
/// scopes.
bool AllScopes = true;
} Completion;
+
+ /// Configures hover feature.
+ struct {
+ /// Whether hover show a.k.a type.
+ bool AKAPrint = false;
+ } Hover;
};
} // namespace clangd
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits