Skip to content

Commit 799690a

Browse files
committed
Add SymbolIndex.query
1 parent 42829cb commit 799690a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.jetbrains.exposed.sql.insert
1414

1515
private object Symbols : Table() {
1616
val fqName = varchar("fqname", length = 255).autoIncrement().primaryKey()
17+
val shortName = varchar("shortname", length = 127)
1718
val kind = integer("kind")
1819
}
1920

@@ -36,8 +37,11 @@ class SymbolIndex {
3637
try {
3738
transaction(db) {
3839
for (descriptor in allDescriptors(module)) {
40+
val fqn = descriptor.fqNameSafe
41+
3942
Symbols.insert {
40-
it[fqName] = descriptor.fqNameSafe.toString()
43+
it[fqName] = fqn.toString()
44+
it[shortName] = fqn.shortName().toString()
4145
it[kind] = descriptor.accept(ExtractSymbolKind, Unit).rawValue
4246
}
4347
}
@@ -52,6 +56,13 @@ class SymbolIndex {
5256
}
5357
}
5458

59+
fun query(prefix: String, limit: Int = 20): List<Symbol> = transaction(db) {
60+
Symbols
61+
.selectAll()
62+
.limit(limit)
63+
.map { Symbol(FqName(it[Symbols.fqName]), Symbol.Kind.fromRaw(it[Symbols.kind])) }
64+
}
65+
5566
private fun allDescriptors(module: ModuleDescriptor): Collection<DeclarationDescriptor> = allPackages(module)
5667
.map(module::getPackage)
5768
.flatMap {

0 commit comments

Comments
 (0)