Skip to content

Commit 0ab1556

Browse files
committed
add comment
1 parent 0aaf16c commit 0ab1556

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Sources/SourceKitLSP/Workspace.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,14 @@ package final class Workspace: Sendable, BuildSystemManagerDelegate {
307307
let prefixMappings =
308308
(indexOptions.indexPrefixMap ?? [:])
309309
.sorted {
310-
if $0.original.count != $1.original.count {
311-
return $0.original.count > $1.original.count
312-
} else {
313-
return $0.original < $1.original
314-
}
310+
// Fixes an issue where remapPath might match the shortest path first when multiple common prefixes exist
311+
// Sort by path length descending to prioritize more specific paths;
312+
// when lengths are equal, sort lexicographically in ascending order
313+
if $0.original.count != $1.original.count {
314+
return $0.original.count > $1.original.count // Prefer longer paths (more specific)
315+
} else {
316+
return $0.original < $1.original // Alphabetical sort when lengths are equal, ensures stable ordering
317+
}
315318
}
316319
.map { PathMapping(original: $0.key, replacement: $0.value) }
317320
if let indexInjector = hooks.indexHooks.indexInjector {

0 commit comments

Comments
 (0)