Skip to content

Commit a6891c3

Browse files
committed
Support ranged CollectVariableType requests
1 parent fdf3b44 commit a6891c3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,16 +1061,12 @@ extension SwiftLanguageServer {
10611061
}
10621062

10631063
let uri = req.params.textDocument.uri
1064-
variableTypeInfos(uri) { infosResult in
1064+
variableTypeInfos(uri, req.params.range) { infosResult in
10651065
do {
10661066
let infos = try infosResult.get()
10671067
let hints = infos
10681068
.lazy
1069-
.filter { info in
1070-
// TODO: Include range in CollectVariableType request directly
1071-
(req.params.range?.contains(info.range.upperBound) ?? true)
1072-
&& !info.hasExplicitType
1073-
}
1069+
.filter { !$0.hasExplicitType }
10741070
.map { info in
10751071
InlayHint(
10761072
position: info.range.upperBound,

Sources/SourceKitLSP/Swift/VariableTypeInfo.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extension SwiftLanguageServer {
5353
/// Must be called on self.queue.
5454
private func _variableTypeInfos(
5555
_ uri: DocumentURI,
56+
_ range: Range<Position>? = nil,
5657
_ completion: @escaping (Swift.Result<[VariableTypeInfo], VariableTypeInfoError>) -> Void
5758
) {
5859
dispatchPrecondition(condition: .onQueue(queue))
@@ -67,6 +68,13 @@ extension SwiftLanguageServer {
6768
skreq[keys.request] = requests.variable_type
6869
skreq[keys.sourcefile] = snapshot.document.uri.pseudoPath
6970

71+
if let range = range,
72+
let start = snapshot.utf8Offset(of: range.lowerBound),
73+
let end = snapshot.utf8Offset(of: range.upperBound) {
74+
skreq[keys.offset] = start
75+
skreq[keys.length] = end - start
76+
}
77+
7078
// FIXME: SourceKit should probably cache this for us
7179
if let compileCommand = self.commandsByFile[uri] {
7280
skreq[keys.compilerargs] = compileCommand.compilerArgs
@@ -107,10 +115,11 @@ extension SwiftLanguageServer {
107115
/// - completion: Completion block to asynchronously receive the VariableTypeInfos, or error.
108116
func variableTypeInfos(
109117
_ uri: DocumentURI,
118+
_ range: Range<Position>? = nil,
110119
_ completion: @escaping (Swift.Result<[VariableTypeInfo], VariableTypeInfoError>) -> Void
111120
) {
112121
queue.async {
113-
self._variableTypeInfos(uri, completion)
122+
self._variableTypeInfos(uri, range, completion)
114123
}
115124
}
116125
}

0 commit comments

Comments
 (0)