Skip to content

Commit 7584d2a

Browse files
committed
Test inlay hints for fields
1 parent 91e5e11 commit 7584d2a

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ extension SwiftLanguageServer {
10701070
do {
10711071
func bindings(_ symbols: [DocumentSymbol]) -> [DocumentSymbol] {
10721072
symbols
1073-
.flatMap { bindings($0.children ?? []) + ($0.kind == .variable ? [$0] : []) }
1073+
.flatMap { bindings($0.children ?? []) + ([.variable, .field, .property].contains($0.kind) ? [$0] : []) }
10741074
}
10751075

10761076
let symbols = try symbolsResult.get()

Tests/SourceKitLSPTests/InlayHintsTests.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,50 @@ final class InlayHintsTests: XCTestCase {
110110
)
111111
])
112112
}
113+
114+
func testFields() {
115+
let text = """
116+
class X {
117+
let instanceMember = 3
118+
static let staticMember = "abc"
119+
}
120+
121+
struct Y {
122+
var instanceMember = "def" + "ghi"
123+
static let staticMember = 1 + 2
124+
}
125+
126+
enum Z {
127+
static let staticMember = 3.0
128+
}
129+
"""
130+
let hints = performInlayHintsRequest(text: text)
131+
XCTAssertEqual(hints, [
132+
InlayHint(
133+
position: Position(line: 1, utf16index: 24),
134+
category: .type,
135+
label: "Int"
136+
),
137+
InlayHint(
138+
position: Position(line: 2, utf16index: 33),
139+
category: .type,
140+
label: "String"
141+
),
142+
InlayHint(
143+
position: Position(line: 6, utf16index: 36),
144+
category: .type,
145+
label: "String"
146+
),
147+
InlayHint(
148+
position: Position(line: 7, utf16index: 33),
149+
category: .type,
150+
label: "Int"
151+
),
152+
InlayHint(
153+
position: Position(line: 11, utf16index: 31),
154+
category: .type,
155+
label: "Double"
156+
),
157+
])
158+
}
113159
}

Tests/SourceKitLSPTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extension InlayHintsTests {
9696
static let __allTests__InlayHintsTests = [
9797
("testBindings", testBindings),
9898
("testEmpty", testEmpty),
99+
("testFields", testFields),
99100
("testRanged", testRanged),
100101
]
101102
}

0 commit comments

Comments
 (0)