Skip to content

Commit 8bfa5c7

Browse files
committed
Ignore too long symbol names in indexer for now
Fixes #274
1 parent 40f365e commit 8bfa5c7

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import org.jetbrains.exposed.sql.Database
1515
import org.jetbrains.exposed.sql.SqlExpressionBuilder.like
1616
import org.jetbrains.exposed.sql.insert
1717

18+
private val MAX_FQNAME_LENGTH = 255
19+
private val MAX_SHORT_NAME_LENGTH = 80
20+
1821
private object Symbols : Table() {
19-
val fqName = varchar("fqname", length = 255) references FqNames.fqName
22+
val fqName = varchar("fqname", length = MAX_FQNAME_LENGTH) references FqNames.fqName
2023
val kind = integer("kind")
2124
val visibility = integer("visibility")
2225
val extensionReceiverType = varchar("extensionreceivertype", length = 255).nullable()
@@ -25,8 +28,8 @@ private object Symbols : Table() {
2528
}
2629

2730
private object FqNames : Table() {
28-
val fqName = varchar("fqname", length = 255)
29-
val shortName = varchar("shortname", length = 80)
31+
val fqName = varchar("fqname", length = MAX_FQNAME_LENGTH)
32+
val shortName = varchar("shortname", length = MAX_SHORT_NAME_LENGTH)
3033

3134
override val primaryKey = PrimaryKey(fqName)
3235
}
@@ -62,18 +65,20 @@ class SymbolIndex {
6265
val descriptorFqn = descriptor.fqNameSafe
6366
val extensionReceiverFqn = descriptor.accept(ExtractSymbolExtensionReceiverType, Unit)?.takeIf { !it.isRoot }
6467

65-
for (fqn in listOf(descriptorFqn, extensionReceiverFqn).filterNotNull()) {
66-
FqNames.replace {
67-
it[fqName] = fqn.toString()
68-
it[shortName] = fqn.shortName().toString()
68+
if (canStoreFqName(descriptorFqn) && (extensionReceiverFqn?.let { canStoreFqName(it) } ?: true)) {
69+
for (fqn in listOf(descriptorFqn, extensionReceiverFqn).filterNotNull()) {
70+
FqNames.replace {
71+
it[fqName] = fqn.toString()
72+
it[shortName] = fqn.shortName().toString()
73+
}
6974
}
70-
}
7175

72-
Symbols.replace {
73-
it[fqName] = descriptorFqn.toString()
74-
it[kind] = descriptor.accept(ExtractSymbolKind, Unit).rawValue
75-
it[visibility] = descriptor.accept(ExtractSymbolVisibility, Unit).rawValue
76-
it[extensionReceiverType] = extensionReceiverFqn?.toString()
76+
Symbols.replace {
77+
it[fqName] = descriptorFqn.toString()
78+
it[kind] = descriptor.accept(ExtractSymbolKind, Unit).rawValue
79+
it[visibility] = descriptor.accept(ExtractSymbolVisibility, Unit).rawValue
80+
it[extensionReceiverType] = extensionReceiverFqn?.toString()
81+
}
7782
}
7883
}
7984

@@ -90,6 +95,10 @@ class SymbolIndex {
9095
}
9196
}
9297

98+
private fun canStoreFqName(fqName: FqName) =
99+
fqName.toString().length <= MAX_FQNAME_LENGTH
100+
&& fqName.shortName().toString().length <= MAX_SHORT_NAME_LENGTH
101+
93102
fun query(prefix: String, receiverType: FqName? = null, limit: Int = 20): List<Symbol> = transaction(db) {
94103
// TODO: Extension completion currently only works if the receiver matches exactly,
95104
// ideally this should work with subtypes as well

0 commit comments

Comments
 (0)