Skip to content

Commit 3f5fb86

Browse files
committed
Update InlayHint to follow the current proposal
See microsoft/language-server-protocol#1249
1 parent c44a332 commit 3f5fb86

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

Sources/LanguageServerProtocol/SupportTypes/InlayHint.swift

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,37 @@
1212

1313
/// Represents an inline annotation displayed by the editor in a source file.
1414
public struct InlayHint: ResponseType, Codable, Hashable {
15-
/// The range of the token to be annotated.
16-
@CustomCodable<PositionRange>
17-
public var range: Range<Position>
18-
19-
/// The side of the token on which to place the hint.
20-
public var side: InlayHintSide
15+
/// The position within the code that this hint is attached to.
16+
public var position: Position
2117

2218
/// The hint's kind, used for more flexible client-side styling.
23-
public let kind: InlayHintKind
19+
public let category: InlayHintCategory?
2420

2521
/// The hint's text, e.g. a printed type
2622
public let label: String
2723

2824
public init(
29-
range: Range<Position>,
30-
side: InlayHintSide = .after,
31-
kind: InlayHintKind,
25+
position: Position,
26+
category: InlayHintCategory? = nil,
3227
label: String
3328
) {
34-
self.range = range
35-
self.side = side
36-
self.kind = kind
29+
self.position = position
30+
self.category = category
3731
self.label = label
3832
}
3933
}
4034

41-
/// The side of a token on which to place an inlay hint.
42-
public enum InlayHintSide: Int, Codable, Hashable {
43-
case before = 0
44-
case after = 1
45-
}
46-
4735
/// A hint's kind, used for more flexible client-side styling.
48-
public enum InlayHintKind: Int, Codable, Hashable {
49-
/// let x: Hint
50-
case bindingType = 0
51-
/// { (x: Hint) in
52-
case parameterType = 1
53-
/// .method(): Hint
54-
case methodChainType = 2
36+
public struct InlayHintCategory: RawRepresentable, Codable, Hashable {
37+
public var rawValue: String
38+
39+
public init(rawValue: String) {
40+
self.rawValue = rawValue
41+
}
42+
43+
/// A parameter label. Note that this case is not used by
44+
/// Swift, since Swift already has explicit parameter labels.
45+
public static let parameter: InlayHintCategory = InlayHintCategory(rawValue: "parameter")
46+
/// An inferred type.
47+
public static let type: InlayHintCategory = InlayHintCategory(rawValue: "type")
5548
}

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,9 +1044,8 @@ extension SwiftLanguageServer {
10441044
case .success(let infos):
10451045
let hints = infos.map { info in
10461046
InlayHint(
1047-
range: info.range,
1048-
side: .after,
1049-
kind: .bindingType, // TODO: perform actual classification here
1047+
position: info.range.upperBound,
1048+
category: .type,
10501049
label: info.printedType
10511050
)
10521051
}

0 commit comments

Comments
 (0)