@@ -146,12 +146,37 @@ abstract class BuildTests(server: Boolean) extends munit.FunSuite {
146
146
}
147
147
148
148
test(" semantic DB" ) {
149
- val testInputs = TestInputs (
150
- os.rel / " simple.sc" ->
151
- """ val n = 2
152
- |println(s"n=$n")
153
- |""" .stripMargin
149
+ import scala .meta .internal .semanticdb .*
150
+
151
+ val scriptContents =
152
+ """ val n = 2
153
+ |println(s"n=$n")
154
+ |""" .stripMargin
155
+
156
+ val expectedSymbolOccurences = Seq (
157
+ SymbolOccurrence (
158
+ Some (Range (0 , 4 , 0 , 5 )),
159
+ " _empty_/simple.n." ,
160
+ SymbolOccurrence .Role .DEFINITION
161
+ ),
162
+ SymbolOccurrence (
163
+ Some (Range (1 , 8 , 1 , 9 )),
164
+ " scala/StringContext#s()." ,
165
+ SymbolOccurrence .Role .REFERENCE
166
+ ),
167
+ SymbolOccurrence (
168
+ Some (Range (1 , 0 , 1 , 7 )),
169
+ " scala/Predef.println(+1)." ,
170
+ SymbolOccurrence .Role .REFERENCE
171
+ ),
172
+ SymbolOccurrence (
173
+ Some (Range (1 , 13 , 1 , 14 )),
174
+ " _empty_/simple.n." ,
175
+ SymbolOccurrence .Role .REFERENCE
176
+ )
154
177
)
178
+
179
+ val testInputs = TestInputs (os.rel / " simple.sc" -> scriptContents)
155
180
val buildOptions = defaultOptions.copy(
156
181
scalaOptions = defaultOptions.scalaOptions.copy(
157
182
generateSemanticDbs = Some (true )
@@ -173,6 +198,23 @@ abstract class BuildTests(server: Boolean) extends munit.FunSuite {
173
198
val doc = TextDocuments .parseFrom(semDb)
174
199
val uris = doc.documents.map(_.uri)
175
200
expect(uris == Seq (" simple.sc" ))
201
+
202
+ val occurences = doc.documents.flatMap(_.occurrences)
203
+ expect(occurences.forall(_.range.isDefined))
204
+
205
+ val sortedOccurences = doc.documents.flatMap(_.occurrences)
206
+ .sortBy(s =>
207
+ s.range.map(r => (r.startLine, r.startCharacter)).getOrElse((Int .MaxValue , Int .MaxValue ))
208
+ )
209
+ val sortedExpectedOccurences = expectedSymbolOccurences
210
+ .sortBy(s =>
211
+ s.range.map(r => (r.startLine, r.startCharacter)).getOrElse((Int .MaxValue , Int .MaxValue ))
212
+ )
213
+
214
+ munit.Assertions .assert(
215
+ sortedOccurences == sortedExpectedOccurences,
216
+ clue = doc.documents.flatMap(_.occurrences)
217
+ )
176
218
}
177
219
}
178
220
0 commit comments