Skip to content

Commit 89c0d4d

Browse files
amichneCopilot
andcommitted
Use content refresh for known targeted files
Route explicit targeted refreshes for known existing files through the content-refresh path that keeps macOS daemon state stable, while preserving structural rebuilds for new, deleted, or unknown paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 310043a commit 89c0d4d

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

backend-standalone/src/main/kotlin/io/github/amichne/kast/standalone/StandaloneAnalysisBackend.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ internal class StandaloneAnalysisBackend internal constructor(
554554
if (query.filePaths.isEmpty()) {
555555
session.refreshWorkspace(invalidateCaches = true)
556556
} else {
557-
session.refreshFiles(query.filePaths.toSet())
557+
session.refreshTargetedPaths(query.filePaths.toSet())
558558
}
559559
}
560560
}

backend-standalone/src/main/kotlin/io/github/amichne/kast/standalone/StandaloneAnalysisSession.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ internal class StandaloneAnalysisSession(
285285
return buildRefreshResult(normalizedPaths, fullRefresh = false)
286286
}
287287

288+
fun refreshTargetedPaths(paths: Set<String>): RefreshResult {
289+
val normalizedPaths = normalizeTrackedKotlinPaths(paths)
290+
if (normalizedPaths.all(::isKnownRegularKotlinFile)) {
291+
return refreshFileContents(paths)
292+
}
293+
return refreshFiles(paths)
294+
}
295+
288296
private data class CachedKtFileEntries(
289297
val ktFile: KtFile?,
290298
val targetedKtFile: KtFile?,
@@ -340,6 +348,16 @@ internal class StandaloneAnalysisSession(
340348
return virtualFile
341349
}
342350

351+
private fun isKnownRegularKotlinFile(normalizedPath: NormalizedPath): Boolean {
352+
if (!Files.isRegularFile(normalizedPath.toJavaPath())) {
353+
return false
354+
}
355+
if (ktFilesByPath.containsKey(normalizedPath) || targetedKtFilesByPath.containsKey(normalizedPath)) {
356+
return true
357+
}
358+
return sourceIdentifierIndex.get()?.knownPaths()?.contains(normalizedPath.value) == true
359+
}
360+
343361
/**
344362
* Rebuilds the K2 analysis session without a full workspace refresh.
345363
*

0 commit comments

Comments
 (0)