Skip to content

Commit b19330e

Browse files
committed
Apply various PR suggestions regarding inlay hints
1 parent 7584d2a commit b19330e

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

Sources/LanguageServerProtocol/Requests/InlayHintsRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct InlayHintsRequest: TextDocumentRequest, Hashable {
2626
/// The document for which to provide the inlay hints.
2727
public var textDocument: TextDocumentIdentifier
2828

29-
/// The range the inlay hints are requested for. If unset,
29+
/// The range the inlay hints are requested for. If nil,
3030
/// hints for the entire document are requested.
3131
@CustomCodable<PositionRange?>
3232
public var range: Range<Position>?

Sources/SourceKitLSP/Clang/ClangLanguageServer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ extension ClangLanguageServerShim {
491491
}
492492

493493
func inlayHints(_ req: Request<InlayHintsRequest>) {
494-
// Currently a Swift-specific, non-standard request.
495-
// Once inlay hints have been upstreamed to LSP, we
496-
// can forward them to clangd.
494+
// FIXME: Currently a Swift-specific, non-standard request.
495+
// Once inlay hints have been upstreamed to LSP, forward
496+
// them to clangd.
497497
req.reply(.success([]))
498498
}
499499

Sources/SourceKitLSP/Swift/ExpressionTypeInfo.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ enum ExpressionTypeInfoError: Error, Equatable {
5050

5151
extension SwiftLanguageServer {
5252
/// Must be called on self.queue.
53-
func _expressionTypeInfos(
53+
private func _expressionTypeInfos(
5454
_ uri: DocumentURI,
5555
_ completion: @escaping (Swift.Result<[ExpressionTypeInfo], ExpressionTypeInfoError>) -> Void
5656
) {
@@ -83,6 +83,7 @@ extension SwiftLanguageServer {
8383
}
8484

8585
var expressionTypeInfos: [ExpressionTypeInfo] = []
86+
expressionTypeInfos.reserveCapacity(skExpressionTypeInfos.count)
8687

8788
skExpressionTypeInfos.forEach { (_, skExpressionTypeInfo) -> Bool in
8889
guard let info = ExpressionTypeInfo(skExpressionTypeInfo, in: snapshot) else {

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,8 @@ extension SwiftLanguageServer {
10681068
let uri = req.params.textDocument.uri
10691069
documentSymbols(uri) { symbolsResult in
10701070
do {
1071+
/// Filters all the document symbols for which inlay type hints
1072+
/// should be displayed, i.e. variable bindings, fields and properties.
10711073
func bindings(_ symbols: [DocumentSymbol]) -> [DocumentSymbol] {
10721074
symbols
10731075
.flatMap { bindings($0.children ?? []) + ([.variable, .field, .property].contains($0.kind) ? [$0] : []) }
@@ -1088,10 +1090,11 @@ extension SwiftLanguageServer {
10881090
//
10891091
// Both `"abc" + "def"` and `"def"` are matching expressions. Since we are only
10901092
// interested in the first expression, i.e. the one that corresponds to the
1091-
// bound expression, we have to do some pre-processing here.
1093+
// bound expression, we have to do some pre-processing here. Note that this
1094+
// mechanism currently relies on the outermost expression being reported first.
10921095

10931096
var visitedPositions: Set<Position> = []
1094-
var processedInfos: [ExpressionTypeInfo] = [] // end -> start
1097+
var processedInfos: [ExpressionTypeInfo] = []
10951098

10961099
// TODO: Compute inlay hints only for the requested range/categories
10971100
// instead of filtering them afterwards.

0 commit comments

Comments
 (0)