Skip to content

Commit fb4ed65

Browse files
committed
Support Range when hovering
By getting the token at hovering position, then get the token position.
1 parent e93b7ed commit fb4ed65

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,19 @@ extension SwiftLanguageService {
741741
"""
742742
}
743743

744+
var tokenRange: Range<Position>?
745+
746+
if let snapshot = try? await latestSnapshot(for: uri) {
747+
let tree = await syntaxTreeManager.syntaxTree(for: snapshot)
748+
if let token = tree.token(at: snapshot.absolutePosition(of: position)) {
749+
let range: Range<Position> = snapshot.absolutePositionRange(of: token.position..<token.endPosition)
750+
tokenRange = range
751+
}
752+
}
753+
744754
return HoverResponse(
745755
contents: .markupContent(MarkupContent(kind: .markdown, value: joinedDocumentation)),
746-
range: nil
756+
range: tokenRange
747757
)
748758
}
749759

0 commit comments

Comments
 (0)