https://github.com/quanzhuo created https://github.com/llvm/llvm-project/pull/173606
This PR fix https://github.com/clangd/clangd/issues/2573 >From 25166cf972a244e85ccc0904d36e386814edb67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=A8=E5=8D=93?= <[email protected]> Date: Fri, 26 Dec 2025 15:35:17 +0800 Subject: [PATCH] [clangd][refactor] Improve function source code qualification logic in DefineOutline --- .../clangd/refactor/tweaks/DefineOutline.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp index 45e7adeeefcd9..6e00f37ca83de 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp @@ -236,8 +236,13 @@ getFunctionSourceCode(const FunctionDecl *FD, const DeclContext *TargetContext, if (Ref.Qualifier || Ref.Targets.empty() || Ref.NameLoc.isMacroID()) return; // Only qualify return type and function name. - if (Ref.NameLoc != FD->getReturnTypeSourceRange().getBegin() && - Ref.NameLoc != FD->getLocation()) + auto ReturnTypeRange = FD->getReturnTypeSourceRange(); + if (Ref.NameLoc != FD->getLocation() && + (ReturnTypeRange.isInvalid() || + SM.isBeforeInTranslationUnit(Ref.NameLoc, + ReturnTypeRange.getBegin()) || + SM.isBeforeInTranslationUnit(ReturnTypeRange.getEnd(), + Ref.NameLoc))) return; for (const NamedDecl *ND : Ref.Targets) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
