Skip to content

Commit b5f5d33

Browse files
committed
Create progress for indexing
1 parent 29042c4 commit b5f5d33

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
3333
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider)
3434

3535
private lateinit var client: LanguageClient
36-
private lateinit var progressFactory: Progress.Factory
3736

3837
private val async = AsyncExecutor()
38+
private var progressFactory: Progress.Factory = Progress.Factory.None
39+
set(factory: Progress.Factory) {
40+
field = factory
41+
sourcePath.progressFactory = factory
42+
}
3943

4044
override fun connect(client: LanguageClient) {
4145
this.client = client

server/src/main/kotlin/org/javacs/kt/SourcePath.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.javacs.kt.util.fileExtension
66
import org.javacs.kt.util.filePath
77
import org.javacs.kt.util.describeURI
88
import org.javacs.kt.index.SymbolIndex
9+
import org.javacs.kt.progress.Progress
910
import com.intellij.lang.Language
1011
import com.intellij.psi.PsiFile
1112
import com.intellij.openapi.fileTypes.FileType
@@ -34,6 +35,12 @@ class SourcePath(
3435
var indexEnabled = true
3536
var beforeCompileCallback: () -> Unit = {}
3637

38+
var progressFactory: Progress.Factory = Progress.Factory.None
39+
set(factory: Progress.Factory) {
40+
field = factory
41+
index.progressFactory = factory
42+
}
43+
3744
private inner class SourceFile(
3845
val uri: URI,
3946
var content: String,

server/src/main/kotlin/org/javacs/kt/index/SymbolIndex.kt

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
99
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
1010
import org.jetbrains.kotlin.name.FqName
1111
import org.javacs.kt.LOG
12+
import org.javacs.kt.progress.Progress
1213
import org.jetbrains.exposed.sql.Database
1314
import org.jetbrains.exposed.sql.SqlExpressionBuilder.like
1415
import org.jetbrains.exposed.sql.insert
@@ -26,6 +27,8 @@ class SymbolIndex {
2627
private val db = Database.connect("jdbc:h2:mem:symbolindex;DB_CLOSE_DELAY=-1", "org.h2.Driver")
2728
private var initialized = false
2829

30+
var progressFactory: Progress.Factory = Progress.Factory.None
31+
2932
init {
3033
transaction(db) {
3134
SchemaUtils.create(Symbols)
@@ -40,37 +43,41 @@ class SymbolIndex {
4043
val started = System.currentTimeMillis()
4144
LOG.info("Updating symbol index...")
4245

43-
try {
44-
val descriptors = allDescriptors(module)
46+
progressFactory.create("Indexing").thenApply { progress ->
47+
try {
48+
val descriptors = allDescriptors(module)
4549

46-
// TODO: Incremental updates
47-
transaction(db) {
48-
Symbols.deleteAll()
50+
// TODO: Incremental updates
51+
transaction(db) {
52+
Symbols.deleteAll()
4953

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>()
5357

54-
for (descriptor in descriptors) {
55-
val fqn = descriptor.fqNameSafe
58+
for (descriptor in descriptors) {
59+
val fqn = descriptor.fqNameSafe
5660

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+
}
6368
}
6469
}
65-
}
6670

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)
7078
}
71-
} catch (e: Exception) {
72-
LOG.error("Error while updating symbol index")
73-
LOG.printStackTrace(e)
79+
80+
progress.close()
7481
}
7582
}
7683

0 commit comments

Comments
 (0)