Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/SwiftIDEUtils/NameMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ public class NameMatcher: SyntaxAnyVisitor {
}

if case .stringSegment = token.tokenKind {
while let baseNamePosition = positionsToResolve.first(where: { token.rangeWithoutTrivia.contains($0) }) {
// Iterate a snapshot: `addResolvedLocIfRequested` is the only path that
// removes a position from `positionsToResolve`, and it is skipped when
// `getFirstTokenLength` returns `nil`. A `while let .first(where:)` loop
// would re-pick any such position forever.
let positionsInToken = positionsToResolve.filter { token.rangeWithoutTrivia.contains($0) }
for baseNamePosition in positionsInToken {
let positionOffsetInStringSegment = baseNamePosition.utf8Offset - token.position.utf8Offset
guard let tokenLength = getFirstTokenLength(in: token.syntaxTextBytes[positionOffsetInStringSegment...]) else {
continue
Expand Down
9 changes: 9 additions & 0 deletions Tests/SwiftIDEUtilsTest/NameMatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ class NameMatcherTests: XCTestCase {
)
}

func testStringLiteralWithPositionOnWhitespace() {
assertNameMatcherResult(
"""
"hello1️⃣ world"
""",
expected: []
)
}

func testWildcardParameter() {
assertNameMatcherResult(
"func 0️⃣foo1(_ x: Int) {}",
Expand Down