15#include "clang/Lex/PreprocessorOptions.h"
16#include "llvm/Support/Error.h"
17#include "gmock/gmock.h"
18#include "gtest/gtest.h"
25TEST(FeatureModulesTest, ContributesTweak) {
26 static constexpr const char *TweakID =
"ModuleTweak";
28 struct ModuleTweak final :
public Tweak {
29 const char *id()
const override {
return TweakID; }
30 bool prepare(
const Selection &Sel)
override {
return true; }
31 Expected<Effect> apply(
const Selection &Sel)
override {
32 return error(
"not implemented");
34 std::string title()
const override {
return id(); }
35 llvm::StringLiteral kind()
const override {
36 return llvm::StringLiteral(
"");
40 void contributeTweaks(std::vector<std::unique_ptr<Tweak>> &Out)
override {
41 Out.emplace_back(
new ModuleTweak);
46 Set.
add(std::make_unique<TweakContributingModule>());
54 ASSERT_TRUE(
bool(Actual));
55 EXPECT_EQ(Actual->get()->id(), TweakID);
58TEST(FeatureModulesTest, SuppressDiags) {
60 struct Listener :
public FeatureModule::ASTListener {
61 void sawDiagnostic(
const clang::Diagnostic &Info,
62 clangd::Diag &Diag)
override {
63 Diag.Severity = DiagnosticsEngine::Ignored;
66 std::unique_ptr<ASTListener> astListeners()
override {
67 return std::make_unique<Listener>();
71 FMS.
add(std::make_unique<DiagModifierModule>());
75 TU.
Code = Code.code().str();
78 auto AST = TU.build();
79 EXPECT_THAT(
AST.getDiagnostics(), testing::Not(testing::IsEmpty()));
82 TU.FeatureModules = &FMS;
84 auto AST = TU.build();
85 EXPECT_THAT(
AST.getDiagnostics(), testing::IsEmpty());
89TEST(FeatureModulesTest, BeforeExecute) {
91 struct Listener :
public FeatureModule::ASTListener {
92 void beforeExecute(CompilerInstance &CI)
override {
93 CI.getPreprocessor().SetSuppressIncludeNotFoundError(
true);
96 std::unique_ptr<ASTListener> astListeners()
override {
97 return std::make_unique<Listener>();
101 FMS.
add(std::make_unique<BeforeExecuteModule>());
105 #include "not_found.h"
108 #include "not_found_not_preamble.h"
113 auto AST = TU.build();
114 EXPECT_THAT(
AST.getDiagnostics(), testing::Not(testing::IsEmpty()));
117 TU.FeatureModules = &FMS;
119 auto AST = TU.build();
120 EXPECT_THAT(
AST.getDiagnostics(), testing::IsEmpty());
Same as llvm::Annotations, but adjusts functions to LSP-specific types for positions and ranges.
A FeatureModuleSet is a collection of feature modules installed in clangd.
void add(std::unique_ptr< FeatureModule > M)
A FeatureModule contributes a vertical feature to clangd.
static SelectionTree createRight(ASTContext &AST, const syntax::TokenBuffer &Tokens, unsigned Begin, unsigned End)
llvm::Error error(std::error_code, std::string &&)
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
llvm::Expected< std::unique_ptr< Tweak > > prepareTweak(StringRef ID, const Tweak::Selection &S, const FeatureModuleSet *Modules)
TEST(BackgroundQueueTest, Priority)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static TestTU withCode(llvm::StringRef Code)
Input to prepare and apply tweaks.