Skip to content

Commit 346ac7c

Browse files
committed
merge: lock-free request reads
2 parents 3eb0411 + f040a1e commit 346ac7c

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,23 @@ class LuaLanguageService(
374374
return result.affectedDocuments
375375
}
376376

377-
fun setWorkspaceMetadata(metadata: Map<String, String>): Unit = synchronized(stateLock) {
378-
workspaceGeneration += 1
379-
workspaceMetadata = metadata.toMap()
380-
// Configuration that invalidates global metadata falls back to a full rebuild.
381-
rebuildFull()
382-
Unit
377+
fun setWorkspaceMetadata(metadata: Map<String, String>): Unit {
378+
// Store + bump generation under lock, then run the heavy rebuild on the
379+
// background thread (scheduleBackgroundRebuild no-ops if one is already
380+
// running; its post-build moved-check re-runs with the NEW metadata).
381+
// A synchronous rebuild here blocked every completion/hover request for
382+
// the whole 13-18s dex+corpus build on device.
383+
val changed = synchronized(stateLock) {
384+
val moved = workspaceMetadata != metadata.toMap()
385+
if (moved) {
386+
workspaceGeneration += 1
387+
workspaceMetadata = metadata.toMap()
388+
}
389+
moved
390+
}
391+
if (changed) {
392+
scheduleBackgroundRebuild()
393+
}
383394
}
384395

385396
/**

0 commit comments

Comments
 (0)