From 2db90e910576bd59ef5140cf7b3f2f43a00a1e43 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 23 Apr 2014 00:24:11 +0000 Subject: [PATCH] [IDE] For the syntax node of functions, set the name range to the range of the function signature. Swift SVN r16680 --- include/swift/AST/Decl.h | 3 +++ lib/AST/Decl.cpp | 7 +++++++ lib/IDE/SyntaxModel.cpp | 5 ++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 9a4bd61caea..cbb3f766fda 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -3419,6 +3419,9 @@ public: /// Retrieve the source range of the function body. SourceRange getBodySourceRange() const; + /// Retrieve the source range of the function declaration name + patterns. + SourceRange getSignatureSourceRange() const; + CaptureInfo &getCaptureInfo() { return Captures; } const CaptureInfo &getCaptureInfo() const { return Captures; } diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 507d7fd3467..bacb51ea635 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -2172,6 +2172,13 @@ SourceRange AbstractFunctionDecl::getBodySourceRange() const { } } +SourceRange AbstractFunctionDecl::getSignatureSourceRange() const { + auto Pats = getBodyParamPatterns(); + if (Pats.empty()) + return getNameLoc(); + return SourceRange(getNameLoc(), Pats.back()->getEndLoc()); +} + ObjCSelector AbstractFunctionDecl::getObjCSelector() const { if (auto func = dyn_cast(this)) return func->getObjCSelector(); diff --git a/lib/IDE/SyntaxModel.cpp b/lib/IDE/SyntaxModel.cpp index 5db17d83131..1edb0551c8e 100644 --- a/lib/IDE/SyntaxModel.cpp +++ b/lib/IDE/SyntaxModel.cpp @@ -318,9 +318,8 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { SN.Range = charSourceRangeFromSourceRange(SM, AFD->getSourceRange()); SN.BodyRange = innerCharSourceRangeFromSourceRange(SM, AFD->getBodySourceRange()); - SourceLoc NRStart = AFD->getNameLoc(); - SourceLoc NREnd = NRStart.getAdvancedLoc(AFD->getName().getLength()); - SN.NameRange = CharSourceRange(SM, NRStart, NREnd); + SN.NameRange = charSourceRangeFromSourceRange(SM, + AFD->getSignatureSourceRange()); SN.Attrs = AFD->getAttrs(); pushStructureNode(SN); }