[clang-tools-extra] [clangd] Remove unused getQualification overload (PR #248703)
James Cowsert via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 3 15:01:54 PST 2026
https://github.com/J-Cowsert created https://github.com/llvm/llvm-project/pull/248703
Remove the `getQualification()` overload that takes an `ArrayRef<std::string> of VisibleNamespaces`.
No non-test callers since
d4af86581e80 ("[clangd] Fix type printing in the presence of qualifiers", https://reviews.llvm.org/D94259)
Test Changes:
- Removed `VisibleNamespaces` from test cases
- Removed now redundant test case for the removed overload (It doesn't test anything the first `GetQualification` test case doesn't).
Follow up to #242500
Assisted-by: Claude Opus 5.5
>From 9a3e3546afd0ae9d3d94daf25960970fe5ddd9b1 Mon Sep 17 00:00:00 2001
From: J-Cowsert <cowsert.jsec at proton.me>
Date: Thu, 3 Dec 2026 16:27:34 -0600
Subject: [PATCH] [clangd] Remove unused getQualification overload
Remove the getQualification() overload that takes an
ArrayRef<std::string> of VisibleNamespaces.
No non-test callers since
d4af86581e80 ("[clangd] Fix type printing in the presence of qualifiers", https://reviews.llvm.org/D94259)
Test Changes:
- Removed VisibleNamespaces from test cases
- Removed now redundant test case for the removed overload (It doesn't
test anything the first GetQualification test case doesn't).
Follow up to #242500
---
clang-tools-extra/clangd/AST.cpp | 19 ----------
clang-tools-extra/clangd/AST.h | 18 +---------
.../clangd/unittests/ASTTests.cpp | 35 +++----------------
3 files changed, 6 insertions(+), 66 deletions(-)
diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index 48b556e663cb81..1b9e1f2a704dfd 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -717,25 +717,6 @@ std::string getQualification(ASTContext &Context,
});
}
-std::string getQualification(ASTContext &Context,
- const DeclContext *DestContext,
- const NamedDecl *ND,
- llvm::ArrayRef<std::string> VisibleNamespaces) {
- for (llvm::StringRef NS : VisibleNamespaces) {
- assert(NS.ends_with("::"));
- (void)NS;
- }
- return getQualification(
- Context, DestContext, ND->getDeclContext(), [&](const Decl *D) {
- return llvm::any_of(VisibleNamespaces, [&](llvm::StringRef Namespace) {
- std::string NS;
- llvm::raw_string_ostream OS(NS);
- D->print(OS, Context.getPrintingPolicy());
- return OS.str() == Namespace;
- });
- });
-}
-
bool hasUnstableLinkage(const Decl *D) {
// Linkage of a ValueDecl depends on the type.
// If that's not deduced yet, deducing it may change the linkage.
diff --git a/clang-tools-extra/clangd/AST.h b/clang-tools-extra/clangd/AST.h
index ab03b117771d7f..417b8cef9701a6 100644
--- a/clang-tools-extra/clangd/AST.h
+++ b/clang-tools-extra/clangd/AST.h
@@ -195,7 +195,7 @@ std::vector<const Attr *> getAttributes(const DynTypedNode &);
/// function will return bar. Note that the result might be sub-optimal for
/// classes, e.g. when the \p ND is a member of the base class.
///
-/// This version considers all the using namespace directives before \p
+/// This considers all the using namespace directives before \p
/// InsertionPoint. i.e, if you have `using namespace
/// clang::clangd::bar`, this function will return an empty string for the
/// example above since no qualification is necessary in that case.
@@ -206,22 +206,6 @@ std::string getQualification(ASTContext &Context,
SourceLocation InsertionPoint,
const NamedDecl *ND);
-/// This function uses the \p VisibleNamespaces to figure out if a shorter
-/// qualification is sufficient for \p ND, and ignores any using namespace
-/// directives. It can be useful if there's no AST for the DestContext, but some
-/// pseudo-parsing is done. i.e. if \p ND is ns1::ns2::X and \p DestContext is
-/// ns1::, users can provide `ns2::` as visible to change the result to be
-/// empty.
-/// Elements in VisibleNamespaces should be in the form: `ns::`, with trailing
-/// "::".
-/// Note that this is just textual and might be incorrect. e.g. when there are
-/// two namespaces ns1::a and ns2::a, the function will early exit if "a::" is
-/// present in \p VisibleNamespaces, no matter whether it is from ns1:: or ns2::
-std::string getQualification(ASTContext &Context,
- const DeclContext *DestContext,
- const NamedDecl *ND,
- llvm::ArrayRef<std::string> VisibleNamespaces);
-
/// Whether we must avoid computing linkage for D during code completion.
/// Clang aggressively caches linkage computation, which is stable after the AST
/// is built. Unfortunately the AST is incomplete during code completion, so
diff --git a/clang-tools-extra/clangd/unittests/ASTTests.cpp b/clang-tools-extra/clangd/unittests/ASTTests.cpp
index 172c21b212dcc1..94cda41a3b9f2a 100644
--- a/clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -373,11 +373,9 @@ TEST(ClangdAST, GetQualification) {
// This is done to get an appropriate DeclContext for the insertion location.
// Qualifications are the required nested name specifier to spell `Foo` at the
// `insert`ion location.
- // VisibleNamespaces are assumed to be visible at every insertion location.
const struct {
llvm::StringRef Test;
std::vector<llvm::StringRef> Qualifications;
- std::vector<std::string> VisibleNamespaces;
} Cases[] = {
{
R"cpp(
@@ -397,7 +395,6 @@ TEST(ClangdAST, GetQualification) {
void insert(); // Foo
)cpp",
{"ns1::ns2::", "ns2::", "", "", "ns2::", ""},
- {},
},
{
R"cpp(
@@ -418,21 +415,6 @@ TEST(ClangdAST, GetQualification) {
)cpp",
{"ns1::ns2::Bar::", "ns2::Bar::", "Bar::", "Bar::", "ns2::Bar::",
"Bar::"},
- {},
- },
- {
- R"cpp(
- namespace ns1 { namespace ns2 { void Foo(); } }
- void insert(); // ns1::ns2::Foo
- namespace ns1 {
- void insert(); // ns2::Foo
- namespace ns2 {
- void insert(); // Foo
- }
- }
- )cpp",
- {"ns1::ns2::", "ns2::", ""},
- {"ns1::"},
},
{
R"cpp(
@@ -444,7 +426,6 @@ TEST(ClangdAST, GetQualification) {
void insert(); // ns::Foo
)cpp",
{"ns::"},
- {},
},
};
for (const auto &Case : Cases) {
@@ -467,17 +448,11 @@ TEST(ClangdAST, GetQualification) {
ASSERT_EQ(InsertionPoints.size(), Case.Qualifications.size());
for (size_t I = 0, E = InsertionPoints.size(); I != E; ++I) {
const Decl *D = InsertionPoints[I];
- if (Case.VisibleNamespaces.empty()) {
- EXPECT_EQ(getQualification(AST.getASTContext(),
- D->getLexicalDeclContext(), D->getBeginLoc(),
- TargetDecl),
- Case.Qualifications[I]);
- } else {
- EXPECT_EQ(getQualification(AST.getASTContext(),
- D->getLexicalDeclContext(), TargetDecl,
- Case.VisibleNamespaces),
- Case.Qualifications[I]);
- }
+
+ EXPECT_EQ(getQualification(AST.getASTContext(),
+ D->getLexicalDeclContext(), D->getBeginLoc(),
+ TargetDecl),
+ Case.Qualifications[I]);
}
}
}
More information about the cfe-commits
mailing list