@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
9
9
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
10
10
import org.jetbrains.kotlin.name.FqName
11
11
import org.javacs.kt.LOG
12
+ import org.javacs.kt.progress.Progress
12
13
import org.jetbrains.exposed.sql.Database
13
14
import org.jetbrains.exposed.sql.SqlExpressionBuilder.like
14
15
import org.jetbrains.exposed.sql.insert
@@ -26,6 +27,8 @@ class SymbolIndex {
26
27
private val db = Database .connect(" jdbc:h2:mem:symbolindex;DB_CLOSE_DELAY=-1" , " org.h2.Driver" )
27
28
private var initialized = false
28
29
30
+ var progressFactory: Progress .Factory = Progress .Factory .None
31
+
29
32
init {
30
33
transaction(db) {
31
34
SchemaUtils .create(Symbols )
@@ -40,37 +43,41 @@ class SymbolIndex {
40
43
val started = System .currentTimeMillis()
41
44
LOG .info(" Updating symbol index..." )
42
45
43
- try {
44
- val descriptors = allDescriptors(module)
46
+ progressFactory.create(" Indexing" ).thenApply { progress ->
47
+ try {
48
+ val descriptors = allDescriptors(module)
45
49
46
- // TODO: Incremental updates
47
- transaction(db) {
48
- Symbols .deleteAll()
50
+ // TODO: Incremental updates
51
+ transaction(db) {
52
+ Symbols .deleteAll()
49
53
50
- // TODO: Workaround, since insertIgnore seems to throw UnsupportedByDialectExceptions
51
- // when used with H2.
52
- val addedFqns = mutableSetOf<FqName >()
54
+ // TODO: Workaround, since insertIgnore seems to throw UnsupportedByDialectExceptions
55
+ // when used with H2.
56
+ val addedFqns = mutableSetOf<FqName >()
53
57
54
- for (descriptor in descriptors) {
55
- val fqn = descriptor.fqNameSafe
58
+ for (descriptor in descriptors) {
59
+ val fqn = descriptor.fqNameSafe
56
60
57
- if (! addedFqns.contains(fqn)) {
58
- addedFqns.add(fqn)
59
- Symbols .insert {
60
- it[fqName] = fqn.toString()
61
- it[shortName] = fqn.shortName().toString()
62
- it[kind] = descriptor.accept(ExtractSymbolKind , Unit ).rawValue
61
+ if (! addedFqns.contains(fqn)) {
62
+ addedFqns.add(fqn)
63
+ Symbols .insert {
64
+ it[fqName] = fqn.toString()
65
+ it[shortName] = fqn.shortName().toString()
66
+ it[kind] = descriptor.accept(ExtractSymbolKind , Unit ).rawValue
67
+ }
63
68
}
64
69
}
65
- }
66
70
67
- val finished = System .currentTimeMillis()
68
- val count = Symbols .slice(Symbols .fqName.count()).selectAll().first()[Symbols .fqName.count()]
69
- LOG .info(" Updated symbol index in ${finished - started} ms! (${count} symbol(s))" )
71
+ val finished = System .currentTimeMillis()
72
+ val count = Symbols .slice(Symbols .fqName.count()).selectAll().first()[Symbols .fqName.count()]
73
+ LOG .info(" Updated symbol index in ${finished - started} ms! (${count} symbol(s))" )
74
+ }
75
+ } catch (e: Exception ) {
76
+ LOG .error(" Error while updating symbol index" )
77
+ LOG .printStackTrace(e)
70
78
}
71
- } catch (e: Exception ) {
72
- LOG .error(" Error while updating symbol index" )
73
- LOG .printStackTrace(e)
79
+
80
+ progress.close()
74
81
}
75
82
}
76
83
0 commit comments