-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Richer search results via LookupElement
- Loading branch information
1 parent
59410c7
commit 7128521
Showing
9 changed files
with
158 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.github.garyttierney.ghidralite.framework | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
interface LookupElement { | ||
val key: Any | ||
val label: String | ||
val parent: LookupElement? | ||
val icon: @Composable () -> Unit | ||
|
||
fun ancestors(): Sequence<LookupElement> = sequence { | ||
val p = parent | ||
if (p != null) { | ||
yield(p) | ||
yieldAll(p.ancestors()) | ||
} | ||
} | ||
|
||
fun fullyQualified() = label | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/framework/search/index/program/symbol/SymbolIndexLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.garyttierney.ghidralite.framework.search.index.program.symbol | ||
|
||
import ghidra.program.model.symbol.SymbolType | ||
import io.github.garyttierney.ghidralite.framework.db.SymbolDbTable | ||
import io.github.garyttierney.ghidralite.framework.db.SymbolLookupDetails | ||
import io.github.garyttierney.ghidralite.framework.db.SymbolRecord | ||
import io.github.garyttierney.ghidralite.framework.search.index.IndexBulkLoader | ||
import it.unimi.dsi.fastutil.longs.Long2ObjectArrayMap | ||
import it.unimi.dsi.fastutil.longs.Long2ObjectFunction | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.filterNot | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.stream.consumeAsFlow | ||
|
||
class SymbolIndexLoader(private val table: SymbolDbTable) : IndexBulkLoader<SymbolLookupDetails> { | ||
override suspend fun load(): Flow<SymbolLookupDetails> { | ||
val namespaceCache = Long2ObjectArrayMap<SymbolLookupDetails>() | ||
|
||
fun recordToLookup(record: SymbolRecord): SymbolLookupDetails { | ||
val cacheLoader = Long2ObjectFunction { key -> recordToLookup(table.get(key)) } | ||
|
||
return SymbolLookupDetails( | ||
record.key, | ||
record.type, | ||
record.name, | ||
if (record.parentId == 0L) null else namespaceCache.computeIfAbsent(record.parentId, cacheLoader) | ||
) | ||
} | ||
|
||
return table.all().consumeAsFlow() | ||
.filterNot { it.type == SymbolType.LABEL || it.type == SymbolType.NAMESPACE } | ||
.map(::recordToLookup) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters