Skip to content

Commit a923ac3

Browse files
authored
Merge pull request #2225 from bnbarham/hover-no-trivia
Do not include trivia in the hover range
2 parents cc50129 + 5402fba commit a923ac3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ extension SwiftLanguageService {
787787
if let snapshot = try? await latestSnapshot(for: uri) {
788788
let tree = await syntaxTreeManager.syntaxTree(for: snapshot)
789789
if let token = tree.token(at: snapshot.absolutePosition(of: position)) {
790-
tokenRange = snapshot.absolutePositionRange(of: token.position..<token.endPosition)
790+
tokenRange = snapshot.absolutePositionRange(of: token.trimmedRange)
791791
}
792792
}
793793

Tests/SourceKitLSPTests/HoverTests.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class HoverTests: XCTestCase {
3232
3333
Details.
3434
""",
35-
expectedRange: Position(line: 3, utf16index: 7)..<Position(line: 3, utf16index: 9)
35+
expectedRange: Position(line: 3, utf16index: 7)..<Position(line: 3, utf16index: 8)
3636
)
3737
}
3838

@@ -173,6 +173,24 @@ final class HoverTests: XCTestCase {
173173
expectedRange: Position(line: 3, utf16index: 5)..<Position(line: 3, utf16index: 13)
174174
)
175175
}
176+
177+
func testTrivia() async throws {
178+
try await assertHover(
179+
"""
180+
func foo() {}
181+
func bar() {
182+
/*some comment*/1️⃣foo/*more comment*/()
183+
}
184+
""",
185+
expectedContent: """
186+
```swift
187+
func foo()
188+
```
189+
190+
""",
191+
expectedRange: Position(line: 2, utf16index: 18)..<Position(line: 2, utf16index: 21)
192+
)
193+
}
176194
}
177195

178196
private func assertHover(

0 commit comments

Comments
 (0)