1
+ package dotty .tools .scaladoc
2
+
3
+ import scala .io .Source
4
+ import dotty .tools .scaladoc .PageEntry
5
+ import org .scalajs .dom .webworkers .Worker
6
+ import org .scalajs .dom ._
7
+ import scala .scalajs .js .{ JSON , Dynamic }
8
+ import scala .collection .mutable .ListBuffer
9
+ import scala .scalajs .js
10
+ import scala .scalajs .js .timers ._
11
+ import org .scalajs .dom .ext .Ajax
12
+ import scala .scalajs .js .URIUtils
13
+
14
+ class InkuireJSSearchEngine {
15
+
16
+ val scriptPath = Globals .pathToRoot + " scripts/"
17
+ val worker = new Worker (s " ${scriptPath}inkuire-worker.js " )
18
+
19
+ def dynamicToPageEntry (d : Dynamic ): PageEntry = {
20
+ PageEntry (
21
+ d.functionName.asInstanceOf [String ],
22
+ d.prettifiedSignature.asInstanceOf [String ],
23
+ d.pageLocation.asInstanceOf [String ],
24
+ d.functionName.asInstanceOf [String ],
25
+ List .empty
26
+ )
27
+ }
28
+
29
+ def query (s : String )(callback : PageEntry => Node ): List [PageEntry ] = {
30
+ worker.onmessage = _ => ()
31
+ val res = ListBuffer [PageEntry ]()
32
+ val func = (msg : MessageEvent ) => {
33
+ msg.data.asInstanceOf [String ] match {
34
+ case " engine_ready" =>
35
+ case " new_query" =>
36
+ case q =>
37
+ val matches = JSON .parse(q).matches
38
+ val actualMatches = matches.asInstanceOf [js.Array [Dynamic ]].map(dynamicToPageEntry)
39
+ actualMatches.foreach(callback)
40
+ }
41
+ }
42
+ worker.onmessage = func
43
+ worker.postMessage(s)
44
+ res.toList
45
+ }
46
+
47
+ }
0 commit comments