Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/clangd/unittests/HoverTests.cpp
Show First 20 Lines • Show All 472 Lines • ▼ Show 20 Lines | class Foo {})cpp"; | ||||
} | } | ||||
)cpp", | )cpp", | ||||
[](HoverInfo &HI) { | [](HoverInfo &HI) { | ||||
HI.Name = "auto"; | HI.Name = "auto"; | ||||
HI.Kind = index::SymbolKind::TypeAlias; | HI.Kind = index::SymbolKind::TypeAlias; | ||||
HI.Definition = "Foo<int>"; | HI.Definition = "Foo<int>"; | ||||
}}, | }}, | ||||
// macro | // variable-like macro | ||||
{R"cpp( | |||||
#define MACRO 41 | |||||
int x = [[MAC^RO]]; | |||||
)cpp", | |||||
[](HoverInfo &HI) { | |||||
HI.Name = "MACRO"; | |||||
HI.Kind = index::SymbolKind::Macro; | |||||
HI.Definition = "#define MACRO 41"; | |||||
HI.MacroExpansion = "41"; | |||||
sammccall: this is redundant with the definition, ideally I think we'd omit one (the output is pretty… | |||||
I suppose if we don't have good way to detect nested object-like macro, just leave both definition and expansion is a better idea since people could simply ignore the redundant part. Though I don't have a strong opinion on this and could change that if you really want. daiyousei-qz: I suppose if we don't have good way to detect nested object-like macro, just leave both… | |||||
Not Done ReplyInline ActionsOK, I also don't feel strongly, so let's go with what you have now. sammccall: OK, I also don't feel strongly, so let's go with what you have now. | |||||
}}, | |||||
// function-like macro | |||||
nit: these are known as "object-like" macros, I don't really know why sammccall: nit: these are known as "object-like" macros, I don't really know why | |||||
{R"cpp( | {R"cpp( | ||||
// Best MACRO ever. | // Best MACRO ever. | ||||
#define MACRO(x,y,z) void foo(x, y, z); | #define MACRO(x,y,z) void foo(x, y, z) | ||||
[[MAC^RO]](int, double d, bool z = false); | [[MAC^RO]](int, double d, bool z = false); | ||||
)cpp", | )cpp", | ||||
[](HoverInfo &HI) { | [](HoverInfo &HI) { | ||||
HI.Name = "MACRO", HI.Kind = index::SymbolKind::Macro, | HI.Name = "MACRO"; | ||||
HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z);"; | HI.Kind = index::SymbolKind::Macro; | ||||
HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z)"; | |||||
HI.MacroExpansion = "void foo(int, double d, bool z = false)"; | |||||
}}, | |||||
// nested macro | |||||
{R"cpp( | |||||
#define STRINGIFY_AUX(s) #s | |||||
#define STRINGIFY(s) STRINGIFY_AUX(s) | |||||
#define DECL_STR(NAME, VALUE) const char *v_##NAME = STRINGIFY(VALUE) | |||||
#define FOO 41 | |||||
[[DECL^_STR]](foo, FOO); | |||||
)cpp", | |||||
[](HoverInfo &HI) { | |||||
HI.Name = "DECL_STR"; | |||||
HI.Kind = index::SymbolKind::Macro; | |||||
HI.Definition = "#define DECL_STR(NAME, VALUE) const char *v_##NAME = " | |||||
"STRINGIFY(VALUE)"; | |||||
HI.MacroExpansion = "const char *v_foo = \"41\""; | |||||
}}, | }}, | ||||
// constexprs | // constexprs | ||||
{R"cpp( | {R"cpp( | ||||
constexpr int add(int a, int b) { return a + b; } | constexpr int add(int a, int b) { return a + b; } | ||||
int [[b^ar]] = add(1, 2); | int [[b^ar]] = add(1, 2); | ||||
)cpp", | )cpp", | ||||
[](HoverInfo &HI) { | [](HoverInfo &HI) { | ||||
▲ Show 20 Lines • Show All 567 Lines • ▼ Show 20 Lines | for (const auto &Case : Cases) { | ||||
Case.ExpectedBuilder(Expected); | Case.ExpectedBuilder(Expected); | ||||
EXPECT_EQ(H->NamespaceScope, Expected.NamespaceScope); | EXPECT_EQ(H->NamespaceScope, Expected.NamespaceScope); | ||||
EXPECT_EQ(H->LocalScope, Expected.LocalScope); | EXPECT_EQ(H->LocalScope, Expected.LocalScope); | ||||
EXPECT_EQ(H->Name, Expected.Name); | EXPECT_EQ(H->Name, Expected.Name); | ||||
EXPECT_EQ(H->Kind, Expected.Kind); | EXPECT_EQ(H->Kind, Expected.Kind); | ||||
EXPECT_EQ(H->Documentation, Expected.Documentation); | EXPECT_EQ(H->Documentation, Expected.Documentation); | ||||
EXPECT_EQ(H->Definition, Expected.Definition); | EXPECT_EQ(H->Definition, Expected.Definition); | ||||
EXPECT_EQ(H->MacroExpansion, Expected.MacroExpansion); | |||||
EXPECT_EQ(H->Type, Expected.Type); | EXPECT_EQ(H->Type, Expected.Type); | ||||
EXPECT_EQ(H->ReturnType, Expected.ReturnType); | EXPECT_EQ(H->ReturnType, Expected.ReturnType); | ||||
EXPECT_EQ(H->Parameters, Expected.Parameters); | EXPECT_EQ(H->Parameters, Expected.Parameters); | ||||
EXPECT_EQ(H->TemplateParameters, Expected.TemplateParameters); | EXPECT_EQ(H->TemplateParameters, Expected.TemplateParameters); | ||||
EXPECT_EQ(H->SymRange, Expected.SymRange); | EXPECT_EQ(H->SymRange, Expected.SymRange); | ||||
EXPECT_EQ(H->Value, Expected.Value); | EXPECT_EQ(H->Value, Expected.Value); | ||||
EXPECT_EQ(H->Size, Expected.Size); | EXPECT_EQ(H->Size, Expected.Size); | ||||
EXPECT_EQ(H->Offset, Expected.Offset); | EXPECT_EQ(H->Offset, Expected.Offset); | ||||
▲ Show 20 Lines • Show All 481 Lines • ▼ Show 20 Lines | const std::function<void(HoverInfo &)> ExpectedBuilder; | ||||
R"cpp(// Macro | R"cpp(// Macro | ||||
#define MACRO 0 | #define MACRO 0 | ||||
int main() { return ^[[MACRO]]; } | int main() { return ^[[MACRO]]; } | ||||
)cpp", | )cpp", | ||||
[](HoverInfo &HI) { | [](HoverInfo &HI) { | ||||
HI.Name = "MACRO"; | HI.Name = "MACRO"; | ||||
HI.Kind = index::SymbolKind::Macro; | HI.Kind = index::SymbolKind::Macro; | ||||
HI.Definition = "#define MACRO 0"; | HI.Definition = "#define MACRO 0"; | ||||
HI.MacroExpansion = "0"; | |||||
}}, | }}, | ||||
{ | { | ||||
R"cpp(// Macro | R"cpp(// Macro | ||||
#define MACRO 0 | #define MACRO 0 | ||||
#define MACRO2 ^[[MACRO]] | #define MACRO2 ^[[MACRO]] | ||||
)cpp", | )cpp", | ||||
[](HoverInfo &HI) { | [](HoverInfo &HI) { | ||||
HI.Name = "MACRO"; | HI.Name = "MACRO"; | ||||
HI.Kind = index::SymbolKind::Macro; | HI.Kind = index::SymbolKind::Macro; | ||||
HI.Definition = "#define MACRO 0"; | HI.Definition = "#define MACRO 0"; | ||||
// FIXME: expansion of MACRO isn't available in macro | |||||
// definition/arguments | |||||
}}, | }}, | ||||
{ | { | ||||
R"cpp(// Macro | R"cpp(// Macro | ||||
#define MACRO {\ | #define MACRO {\ | ||||
return 0;\ | return 0;\ | ||||
} | } | ||||
int main() ^[[MACRO]] | int main() ^[[MACRO]] | ||||
)cpp", | )cpp", | ||||
[](HoverInfo &HI) { | [](HoverInfo &HI) { | ||||
HI.Name = "MACRO"; | HI.Name = "MACRO"; | ||||
HI.Kind = index::SymbolKind::Macro; | HI.Kind = index::SymbolKind::Macro; | ||||
HI.Definition = | HI.Definition = | ||||
R"cpp(#define MACRO \ | R"cpp(#define MACRO \ | ||||
{ return 0; })cpp"; | { return 0; })cpp"; | ||||
HI.MacroExpansion = "{ return 0; }"; | |||||
}}, | }}, | ||||
{ | { | ||||
R"cpp(// Forward class declaration | R"cpp(// Forward class declaration | ||||
class Foo; | class Foo; | ||||
class Foo {}; | class Foo {}; | ||||
[[F^oo]]* foo(); | [[F^oo]]* foo(); | ||||
)cpp", | )cpp", | ||||
[](HoverInfo &HI) { | [](HoverInfo &HI) { | ||||
▲ Show 20 Lines • Show All 1,018 Lines • ▼ Show 20 Lines | for (const auto &Case : Cases) { | ||||
SCOPED_TRACE(H->present().asPlainText()); | SCOPED_TRACE(H->present().asPlainText()); | ||||
EXPECT_EQ(H->NamespaceScope, Expected.NamespaceScope); | EXPECT_EQ(H->NamespaceScope, Expected.NamespaceScope); | ||||
EXPECT_EQ(H->LocalScope, Expected.LocalScope); | EXPECT_EQ(H->LocalScope, Expected.LocalScope); | ||||
EXPECT_EQ(H->Name, Expected.Name); | EXPECT_EQ(H->Name, Expected.Name); | ||||
EXPECT_EQ(H->Kind, Expected.Kind); | EXPECT_EQ(H->Kind, Expected.Kind); | ||||
EXPECT_EQ(H->Documentation, Expected.Documentation); | EXPECT_EQ(H->Documentation, Expected.Documentation); | ||||
EXPECT_EQ(H->Definition, Expected.Definition); | EXPECT_EQ(H->Definition, Expected.Definition); | ||||
EXPECT_EQ(H->MacroExpansion, Expected.MacroExpansion); | |||||
EXPECT_EQ(H->Type, Expected.Type); | EXPECT_EQ(H->Type, Expected.Type); | ||||
EXPECT_EQ(H->ReturnType, Expected.ReturnType); | EXPECT_EQ(H->ReturnType, Expected.ReturnType); | ||||
EXPECT_EQ(H->Parameters, Expected.Parameters); | EXPECT_EQ(H->Parameters, Expected.Parameters); | ||||
EXPECT_EQ(H->TemplateParameters, Expected.TemplateParameters); | EXPECT_EQ(H->TemplateParameters, Expected.TemplateParameters); | ||||
EXPECT_EQ(H->SymRange, Expected.SymRange); | EXPECT_EQ(H->SymRange, Expected.SymRange); | ||||
EXPECT_EQ(H->Value, Expected.Value); | EXPECT_EQ(H->Value, Expected.Value); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 600 Lines • Show Last 20 Lines |
this is redundant with the definition, ideally I think we'd omit one (the output is pretty heavyweight).
It's *almost* correct to omit the expansion for object-like macros, the problem with this is:
Still, this is probably rare enough that it's better to not show expansions for object-like macros on balance?
(It would be possible to actually check for nested expansions but I doubt it's worth the complexity, certainly not in this patch)