Skip to content

Commit 0945fa7

Browse files
committed
Correct relative column and remove unwanted comment
1 parent e33f611 commit 0945fa7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Sources/DocumentationLanguageService/DocumentationLanguageService.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ package actor DocumentationLanguageService: LanguageService, Sendable {
195195
return
196196
}
197197

198-
let relativeColumn = target.column - range.lowerBound.column - 3
198+
// Symbol links are delimited by two backticks (``Foo/bar``),
199+
// so the destination starts two columns past the start of the link.
200+
let destinationStartColumn = range.lowerBound.column + 2
201+
let relativeColumn = target.column - destinationStartColumn
202+
guard relativeColumn >= 0 else {
203+
return
204+
}
199205
let components = destination.split(separator: "/")
200206
var currentLength = 0
201207

@@ -264,9 +270,7 @@ package actor DocumentationLanguageService: LanguageService, Sendable {
264270
return line.utf8.distance(from: line.startIndex, to: stringIndex)
265271
}
266272

267-
/// The inverse of `utf8Offset(inLine:forUTF16Offset:)`. Diagnostics need this because we go the
268-
/// other direction from go-to-definition: swift-markdown hands us a UTF-8 column for a symbol
269-
/// link it found, and we need to turn that into the UTF-16 column LSP `Position` expects.
273+
/// The inverse of `utf8Offset(inLine:forUTF16Offset:)`
270274
private func utf16Offset(inLine line: String, forUTF8Offset utf8Offset: Int) -> Int {
271275
let utf8View = line.utf8
272276
guard

0 commit comments

Comments
 (0)