Skip to content

Commit f1a10a0

Browse files
authored
Merge pull request #78012 from hamishknight/ume-cursor-info-6.1
[6.1] [IDE] Handle UnresolvedMemberExpr for solver-based cursor info
2 parents adc777c + 8a741ab commit f1a10a0

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

include/swift/AST/Expr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
552552
/// \c nullptr.
553553
ArgumentList *getArgs() const;
554554

555+
/// If the expression has a DeclNameLoc, returns it. Otherwise, returns
556+
/// an nullp DeclNameLoc.
557+
DeclNameLoc getNameLoc() const;
558+
555559
/// Produce a mapping from each subexpression to its parent
556560
/// expression, with the provided expression serving as the root of
557561
/// the parent map.

lib/AST/Expr.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,25 @@ ArgumentList *Expr::getArgs() const {
874874
return nullptr;
875875
}
876876

877+
DeclNameLoc Expr::getNameLoc() const {
878+
if (auto *DRE = dyn_cast<DeclRefExpr>(this))
879+
return DRE->getNameLoc();
880+
if (auto *UDRE = dyn_cast<UnresolvedDeclRefExpr>(this))
881+
return UDRE->getNameLoc();
882+
if (auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(this))
883+
return ODRE->getNameLoc();
884+
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(this))
885+
return UDE->getNameLoc();
886+
if (auto *UME = dyn_cast<UnresolvedMemberExpr>(this))
887+
return UME->getNameLoc();
888+
if (auto *MRE = dyn_cast<MemberRefExpr>(this))
889+
return MRE->getNameLoc();
890+
if (auto *DRME = dyn_cast<DynamicMemberRefExpr>(this))
891+
return DRME->getNameLoc();
892+
893+
return DeclNameLoc();
894+
}
895+
877896
llvm::DenseMap<Expr *, Expr *> Expr::getParentMap() {
878897
class RecordingTraversal : public ASTWalker {
879898
public:

lib/IDE/CursorInfo.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,6 @@ class NodeFinder : ASTWalker {
214214
return Action::Continue();
215215
}
216216

217-
/// Retrieve the name location for an expression that supports cursor info.
218-
DeclNameLoc getExprNameLoc(Expr *E) {
219-
if (auto *DRE = dyn_cast<DeclRefExpr>(E))
220-
return DRE->getNameLoc();
221-
222-
if (auto *UDRE = dyn_cast<UnresolvedDeclRefExpr>(E))
223-
return UDRE->getNameLoc();
224-
225-
if (auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(E))
226-
return ODRE->getNameLoc();
227-
228-
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(E))
229-
return UDE->getNameLoc();
230-
231-
return DeclNameLoc();
232-
}
233-
234217
PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
235218
if (auto closure = dyn_cast<ClosureExpr>(E)) {
236219
DeclContextStack.push_back(closure);
@@ -247,7 +230,7 @@ class NodeFinder : ASTWalker {
247230
}
248231
}
249232

250-
if (getExprNameLoc(E).getBaseNameLoc() != LocToResolve)
233+
if (E->getNameLoc().getBaseNameLoc() != LocToResolve)
251234
return Action::Continue(E);
252235

253236
assert(Result == nullptr);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct S {
2+
static func foo(_ x: Int) -> S {}
3+
static func foo(_ x: String) -> S {}
4+
}
5+
6+
// https://github.com/swiftlang/swift/issues/77981 - Make sure we can resolve
7+
// solver-based cursor info for UnresolvedMemberExprs.
8+
func bar() {
9+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):15 %s -- %s | %FileCheck %s
10+
let _: S = .foo()
11+
}
12+
13+
// CHECK-DAG: source.lang.swift.ref.function.method.static (2:15-2:28)
14+
// CHECK-DAG: source.lang.swift.ref.function.method.static (3:15-3:31)

0 commit comments

Comments
 (0)