[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.
Viktoriia Bakalova via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 16 01:30:39 PDT 2023
VitaNuo updated this revision to Diff 532044.
VitaNuo marked 2 inline comments as done.
VitaNuo added a comment.
Simplify.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153015/new/
https://reviews.llvm.org/D153015
Files:
clang-tools-extra/clangd/Hover.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
@@ -22,6 +22,7 @@
#include "gtest/gtest.h"
#include <functional>
+#include <optional>
#include <string>
#include <vector>
@@ -3722,6 +3723,34 @@
EXPECT_EQ(*HI->Value, "&bar");
}
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+ struct {
+ const char *const Code;
+ const std::optional<std::string> HoverValue;
+ } Cases[] = {
+ {R"cpp(
+ // error-ok testing behavior on invalid decl
+ class Foo {};
+ void foo(Foo p^aram = nullptr);
+ )cpp",
+ std::nullopt},
+ {R"cpp(
+ class Foo {};
+ void foo(Foo *p^aram = nullptr);
+ )cpp",
+ "nullptr"},
+ };
+
+ for (const auto &C : Cases) {
+ Annotations T(C.Code);
+ TestTU TU = TestTU::withCode(T.code());
+ auto AST = TU.build();
+ auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ ASSERT_TRUE(HI);
+ ASSERT_EQ(HI->Value, C.HoverValue);
+ }
+}
+
TEST(Hover, DisableShowAKA) {
Annotations T(R"cpp(
using m_int = int;
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,7 @@
HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
// Fill in value with evaluated initializer if possible.
- if (const auto *Var = dyn_cast<VarDecl>(D)) {
+ if (const auto *Var = dyn_cast<VarDecl>(D); Var && !Var->isInvalidDecl()) {
if (const Expr *Init = Var->getInit())
HI.Value = printExprValue(Init, Ctx);
} else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153015.532044.patch
Type: text/x-patch
Size: 1893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230616/9ab4ff90/attachment.bin>
More information about the cfe-commits
mailing list