Skip to content

Commit 1cd8336

Browse files
committed
feat(sample): live indexing progress in bottom bar + dex surface warmup
- LspServerService exposes buildProgress StateFlow fed by the in-process server's onBuildProgress listener (host hook on LuaLanguageServer) — the app UI shows 'PARSING n/12' live, no client round-trip - After the cold rebuild completes, run one completion query to warm the Java member surfaces (dex/framework hydration) so the user's FIRST completion popup is fast instead of paying the 3s surface-build cost
1 parent 9329695 commit 1cd8336

4 files changed

Lines changed: 45 additions & 6 deletions

File tree

‎android/sample/src/main/java/io/github/dingyi222666/luaparser/sample/LspServerService.kt‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,21 @@ class LspServerService : Service() {
145145
* [LuaLanguageServerLauncher] connection over the socket streams and blocks
146146
* until the lsp4j reading loop finishes (peer disconnect, error or cancel).
147147
*/
148+
/** Live workspace-build status for the app UI ("PARSING 5/12", ...). */
149+
val buildProgress = kotlinx.coroutines.flow.MutableStateFlow("indexing: starting")
150+
148151
private suspend fun serve(client: LocalSocket) {
149152
try {
153+
// Fresh LuaLanguageServer per connection (mandatory, see
154+
// LuaLspServerHost's concurrency contract) + no-op exit hook.
155+
val server = LuaLanguageServer()
156+
server.setOnBuildProgressListener { done, total, phase ->
157+
buildProgress.value = "$phase $done/$total"
158+
}
150159
val connection = LuaLanguageServerLauncher.launch(
151160
client.inputStream,
152-
client.outputStream
153-
// Defaults are correct here: a FRESH LuaLanguageServer per
154-
// connection (mandatory, see LuaLspServerHost's concurrency
155-
// contract) and a no-op exit hook (an embedded server must
156-
// never kill the host app process on LSP `exit`).
161+
client.outputStream,
162+
server = server
157163
)
158164
// Blocks until the peer closes the stream or we get cancelled.
159165
connection.listening.get()

‎android/sample/src/main/java/io/github/dingyi222666/luaparser/sample/MainActivity.kt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ class MainActivity : AppCompatActivity(), FileBrowserFragment.Listener {
168168
subscribeDirtyTracking()
169169
diagnosticsBar.setOnClickListener { jumpToFirstProblem() }
170170

171+
// Live indexing status in the bottom bar: the service hosts the LSP
172+
// in-process, so progress arrives without any client round-trip.
173+
lifecycleScope.launch {
174+
LspServerService.buildProgress.collect { status ->
175+
diagSummary.text = status
176+
}
177+
}
178+
171179
lifecycleScope.launch {
172180
val t0 = System.currentTimeMillis()
173181
fun mark(phase: String) {

‎src/jvmMain/kotlin/io/github/dingyi222666/luaparser/lsp/LuaLanguageServer.kt‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,19 @@ class LuaLanguageServer(
369369

370370
override fun getWorkspaceService(): WorkspaceService = workspace
371371

372+
/**
373+
* Host hook (in-process embedding): receives throttled workspace build
374+
* progress (phase + completed/total) so the app UI can show indexing status
375+
* directly — no client round-trip needed.
376+
*/
377+
fun setOnBuildProgressListener(listener: ((Int, Int, String) -> Unit)?) {
378+
languageService.onBuildProgress = listener?.let { cb ->
379+
{ progress: io.github.dingyi222666.luaparser.semantic.workspace.AnalysisProgress ->
380+
cb(progress.completedFiles, progress.totalFiles, progress.phase.name)
381+
}
382+
}
383+
}
384+
372385
/** Test/embedding hook: wait for the background workspace build to settle. */
373386
internal fun flushBackgroundRebuild(timeoutMs: Long = 60_000): Boolean =
374387
languageService.awaitWorkspaceReady(timeoutMs)
@@ -380,7 +393,12 @@ class LuaLanguageServer(
380393
}
381394
}
382395
// Forward background-build progress as standard $/progress work-done
383-
// notifications (create/report/end) so editors show indexing status.
396+
// notifications for capability-advertising clients. When the client
397+
// doesn't support them (sora), leave any host-set listener in place —
398+
// an in-process host gets progress directly.
399+
if (languageService.onBuildProgress != null) {
400+
return
401+
}
384402
languageService.onBuildProgress = { progress ->
385403
val proxy = client
386404
// sora's client proxy throws UnsupportedOperationException on

‎src/jvmMain/kotlin/io/github/dingyi222666/luaparser/lsp/LuaLanguageService.kt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ class LuaLanguageService(
323323
workspaceGeneration != generationAtStart
324324
}
325325
if (!moved) {
326+
// Warm the Java member surfaces (dex/framework classes) so the
327+
// FIRST user completion isn't the one paying the build cost.
328+
runCatching {
329+
queries.completions(
330+
VirtualPath.of("warmup/main.lua"), Position(1, 1)
331+
)
332+
}
326333
return
327334
}
328335
attempts += 1

0 commit comments

Comments
 (0)