File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -1037,12 +1037,13 @@ extension SwiftLanguageService {
1037
1037
at position: Position ,
1038
1038
in snapshot: DocumentSnapshot
1039
1039
) async -> ( position: Position ? , usr: String ? , functionLikeRange: Range < Position > ? ) {
1040
+ let startOfIdentifierPosition = await adjustPositionToStartOfIdentifier ( position, in: snapshot)
1040
1041
let symbolInfo = try ? await self . symbolInfo (
1041
- SymbolInfoRequest ( textDocument: TextDocumentIdentifier ( snapshot. uri) , position: position )
1042
+ SymbolInfoRequest ( textDocument: TextDocumentIdentifier ( snapshot. uri) , position: startOfIdentifierPosition )
1042
1043
)
1043
1044
1044
- guard let functionLikeRange = await findFunctionLikeRange ( of: position , in: snapshot) else {
1045
- return ( position , symbolInfo? . only? . usr, nil )
1045
+ guard let functionLikeRange = await findFunctionLikeRange ( of: startOfIdentifierPosition , in: snapshot) else {
1046
+ return ( startOfIdentifierPosition , symbolInfo? . only? . usr, nil )
1046
1047
}
1047
1048
if let onlySymbol = symbolInfo? . only, onlySymbol. kind == . constructor {
1048
1049
// We have a rename like `MyStruct(x: 1)`, invoked from `x`.
Original file line number Diff line number Diff line change @@ -51,8 +51,9 @@ func assertSingleFileRename(
51
51
return
52
52
}
53
53
for marker in positions. allMarkers {
54
+ let position = positions [ marker]
54
55
let prepareRenameResponse = try await testClient. send (
55
- PrepareRenameRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ marker ] )
56
+ PrepareRenameRequest ( textDocument: TextDocumentIdentifier ( uri) , position: position )
56
57
)
57
58
if let prepareRenameResponse {
58
59
XCTAssertEqual (
@@ -62,9 +63,11 @@ func assertSingleFileRename(
62
63
file: file,
63
64
line: line
64
65
)
66
+ // VS Code considers the upper bound of a range as part of the identifier so both `contains` and equality in
67
+ // `upperBound` are fine.
65
68
XCTAssert (
66
- prepareRenameResponse. range. contains ( positions [ marker ] ) ,
67
- " Prepare rename range \( prepareRenameResponse. range) does not contain rename position \( positions [ marker ] ) " ,
69
+ prepareRenameResponse. range. contains ( position ) || prepareRenameResponse . range . upperBound == position ,
70
+ " Prepare rename range \( prepareRenameResponse. range) does not contain rename position \( position ) " ,
68
71
file: file,
69
72
line: line
70
73
)
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ final class RenameTests: XCTestCase {
18
18
func testRenameVariableBaseName( ) async throws {
19
19
try await assertSingleFileRename (
20
20
"""
21
- let 1️⃣foo = 1
22
- print(2️⃣foo )
21
+ let 1️⃣foo2️⃣ = 1
22
+ print(3️⃣foo4️⃣ )
23
23
""" ,
24
24
newName: " bar " ,
25
25
expectedPrepareRenamePlaceholder: " foo " ,
You can’t perform that action at this time.
0 commit comments