IJPL-248392 LSP: do not log errors related to client state when document sync manager is disposed

(cherry picked from commit a67ef53f818901a254931ad729826730a2780c28)

IJ-CR-210268

GitOrigin-RevId: 40a151e4ce0b1c89d3677d81559c0616cce72bd2
This commit is contained in:
Piotr Tomiak
2026-08-19 18:48:46 +00:00
committed by intellij-monorepo-bot
parent b86bb5d1aa
commit d4294bc008
2 changed files with 16 additions and 9 deletions
+1 -1
View File
@@ -293,7 +293,7 @@ class LspClientImpl internal constructor(
LspInlayApplier.getInstance(project).scheduleRefresh(file)
}
}
documentSyncManager.close()
documentSyncManager.dispose()
requestExecutor.shutdownNow()
serverNotificationsHandler.cancelAllProgress()
@@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean
internal class LspDocumentSyncManager(private val client: LspClientImpl) {
private val openedFiles: MutableSet<VirtualFile> = Collections.synchronizedSet(HashSet())
private val closed = AtomicBoolean(false)
private val disposed = AtomicBoolean(false)
val openedFileCount: Int get() = openedFiles.size
@@ -45,15 +45,20 @@ internal class LspDocumentSyncManager(private val client: LspClientImpl) {
fun forEachOpenedFile(action: (VirtualFile) -> Unit) = openedFiles.forEach(action)
fun close() {
fun dispose() {
openedFiles.clear()
closed.set(true)
disposed.set(true)
}
@RequiresWriteLock
fun open(file: VirtualFile) {
if (client.state != LspServerState.Running) {
client.logError("Server is not in the Running state. Ignoring open($file)")
// Error should not be logged if the sync manager is disposed of, as the server state
// and thus sync manager state might have changed just after entering `open` method
// and caller is not able to sync on the server state
if (!disposed.get()) {
client.logError("Server is not in the Running state. Ignoring open($file)")
}
return
}
@@ -76,11 +81,13 @@ internal class LspDocumentSyncManager(private val client: LspClientImpl) {
@RequiresWriteLock
fun close(file: VirtualFile) {
// Ignore any close requests once the document sync manager has been closed
if (closed.get()) return
if (!openedFiles.remove(file)) {
client.logError("close() cannot be called for files that haven't been opened. Ignoring: $file")
// Error should not be logged if the sync manager is disposed of, as the server state
// and thus sync manager state might have changed just after entering `open` method
// and caller is not able to sync on the server state
if (!disposed.get()) {
client.logError("close() cannot be called for files that haven't been opened. Ignoring: $file")
}
return
}