Skip to content

Commit c43fa37

Browse files
authored
Merge pull request #75123 from hamishknight/solvar-6.0
[6.0] [CursorInfo] Resolve solver-based in VarDecls
2 parents 43e5bdc + 1f7cf2c commit c43fa37

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/IDE/CursorInfo.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ class NodeFinder : ASTWalker {
174174
}
175175

176176
PreWalkAction walkToDeclPre(Decl *D) override {
177-
if (!rangeContainsLocToResolve(D->getSourceRangeIncludingAttrs())) {
177+
// If the decl doesn't contain the location to resolve, we can skip walking
178+
// it. One exception to this is for VarDecls, they can contain accessors
179+
// which are not included in their SourceRange. For e.g `var x: Int { 0 }`,
180+
// the VarDecl's range is just `x`, but the location may be in the accessor.
181+
if (!isa<VarDecl>(D) &&
182+
!rangeContainsLocToResolve(D->getSourceRangeIncludingAttrs())) {
178183
return Action::SkipNode();
179184
}
180185

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
func foo(_ x: Int) -> Int {}
2+
func foo(_ x: String) -> Int {}
3+
4+
// rdar://131135631 - Make sure we can resolve solver-based cursor info in a
5+
// VarDecl's accessor.
6+
var x: Int {
7+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):3 %s -- %s | %FileCheck %s
8+
foo()
9+
}
10+
11+
// CHECK-DAG: source.lang.swift.ref.function.free (1:6-1:19)
12+
// CHECK-DAG: source.lang.swift.ref.function.free (2:6-2:22)

0 commit comments

Comments
 (0)