Skip to content

Commit e1a4bf3

Browse files
authored
[SourceKit] When Cursor infor resolves to the start of an expression, we always get the outermost expression. (#10738)
The reason is that for clients, getting the offspring of an expression is much easier that getting parents.
1 parent a184a6c commit e1a4bf3

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

include/swift/IDE/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class SemaLocResolver : public SourceEntityWalker {
188188
SourceLoc LocToResolve;
189189
SemaToken SemaTok;
190190
Type ContainerType;
191+
llvm::SmallVector<Expr*, 4> TrailingExprStack;
191192

192193
public:
193194
explicit SemaLocResolver(SourceFile &SrcFile) : SrcFile(SrcFile) { }
@@ -216,7 +217,6 @@ class SemaLocResolver : public SourceEntityWalker {
216217
SourceLoc Loc, bool IsRef, Type Ty = Type());
217218
bool tryResolve(ModuleEntity Mod, SourceLoc Loc);
218219
bool tryResolve(Stmt *St);
219-
bool tryResolve(Expr *Exp);
220220
bool visitSubscriptReference(ValueDecl *D, CharSourceRange Range,
221221
bool IsOpenBracket) override;
222222
};

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,6 @@ bool SemaLocResolver::tryResolve(Stmt *St) {
108108
return false;
109109
}
110110

111-
bool SemaLocResolver::tryResolve(Expr *Exp) {
112-
if (!Exp->isImplicit() && Exp->getStartLoc() == LocToResolve) {
113-
SemaTok = { Exp };
114-
return true;
115-
}
116-
return false;
117-
}
118-
119111
bool SemaLocResolver::visitSubscriptReference(ValueDecl *D, CharSourceRange Range,
120112
bool IsOpenBracket) {
121113
// We should treat both open and close brackets equally
@@ -193,14 +185,23 @@ bool SemaLocResolver::walkToExprPre(Expr *E) {
193185
ContainerType = ME->getBase()->getType();
194186
}
195187
}
188+
189+
// Keep track of trailing expressions.
190+
if (!E->isImplicit() && E->getStartLoc() == LocToResolve)
191+
TrailingExprStack.push_back(E);
196192
}
197193
return true;
198194
}
199195

200196
bool SemaLocResolver::walkToExprPost(Expr *E) {
201197
if (isDone())
202198
return false;
203-
return !tryResolve(E);
199+
if (!TrailingExprStack.empty() && TrailingExprStack.back() == E) {
200+
// We return the outtermost expression in the token info.
201+
SemaTok = { TrailingExprStack.front() };
202+
return false;
203+
}
204+
return true;
204205
}
205206

206207
bool SemaLocResolver::visitCallArgName(Identifier Name, CharSourceRange Range,

0 commit comments

Comments
 (0)