Describe the bug
java.lang.RuntimeException: Document is locked by write PSI operations. Use PsiDocumentManager.doPostponedOperationsAndUnblockDocument() to commit PSI changes to the document.
Unprocessed elements: Py:IMPORT_ELEMENT(190,198), WHITE_SPACE(189,190), WHITE_SPACE(0,1), Py:COMMA(198,199), WHITE_SPACE(199,200)
at com.intellij.psi.impl.source.PostprocessReformattingAspectImpl.assertDocumentChangeIsAllowed(PostprocessReformattingAspectImpl.java:333)
at com.intellij.psi.impl.PsiDocumentManagerImpl.beforeDocumentChangeOnUnlockedDocument(PsiDocumentManagerImpl.java:124)
at com.intellij.psi.impl.PsiDocumentManagerBase.beforeDocumentChange(PsiDocumentManagerBase.java:918)
at jdk.internal.reflect.GeneratedMethodAccessor134.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at com.intellij.util.EventDispatcher.dispatchVoidMethod(EventDispatcher.java:119)
at com.intellij.util.EventDispatcher.lambda$createMulticaster$1(EventDispatcher.java:84)
at jdk.proxy2/jdk.proxy2.$Proxy68.beforeDocumentChange(Unknown Source)
at com.intellij.openapi.editor.impl.DocumentImpl.lambda$beforeChangedUpdate$0(DocumentImpl.java:876)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeNonCancelableSection$3(CoreProgressManager.java:269)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$computeInNonCancelableSection$4(CoreProgressManager.java:277)
at com.intellij.openapi.progress.Cancellation.computeInNonCancelableSection(Cancellation.java:57)
at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:277)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:268)
at com.intellij.openapi.editor.impl.DocumentImpl.beforeChangedUpdate(DocumentImpl.java:873)
at com.intellij.openapi.editor.impl.DocumentImpl.updateText(DocumentImpl.java:812)
at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:658)
at com.intellij.openapi.editor.impl.DocumentImpl.lambda$setText$3(DocumentImpl.java:1080)
at com.intellij.openapi.editor.impl.DocumentImpl.setText(DocumentImpl.java:1082)
at com.koxudaxi.ruff.RuffApplyService$write$1$1.invoke$lambda$0(RuffApplyService.kt:32)
at com.intellij.openapi.command.impl.CoreCommandProcessor.runUndoTransparentAction(CoreCommandProcessor.java:382)
at com.koxudaxi.ruff.RuffApplyService$write$1$1.invoke(RuffApplyService.kt:30)
at com.koxudaxi.ruff.RuffApplyService$write$1$1.invoke(RuffApplyService.kt:29)
at com.intellij.openapi.application.ActionsKt.runWriteAction$lambda$0(actions.kt:16)
at com.intellij.openapi.application.impl.RwLockHolder.runWriteAction(RwLockHolder.kt:354)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:888)
at com.intellij.openapi.application.ActionsKt.runWriteAction(actions.kt:16)
at com.koxudaxi.ruff.RuffApplyService$write$1.invoke(RuffApplyService.kt:29)
at com.koxudaxi.ruff.RuffApplyService$write$1.invoke(RuffApplyService.kt:28)
at com.intellij.openapi.application.ActionsKt.runInEdt(actions.kt:56)
at com.intellij.openapi.application.ActionsKt.runInEdt$default(actions.kt:53)
at com.koxudaxi.ruff.RuffApplyService.write(RuffApplyService.kt:28)
at com.koxudaxi.ruff.RuffApplyService.apply(RuffApplyService.kt:48)
at com.koxudaxi.ruff.RuffFileDocumentManagerListener.beforeDocumentSaving(RuffFileDocumentManagerListener.kt:20)
at com.intellij.util.messages.impl.MessageBusImplKt.invokeMethod(MessageBusImpl.kt:700)
at com.intellij.util.messages.impl.MessageBusImplKt.invokeListener(MessageBusImpl.kt:660)
at com.intellij.util.messages.impl.MessageBusImplKt.executeOrAddToQueue(MessageBusImpl.kt:492)
at com.intellij.util.messages.impl.ToDirectChildrenMessagePublisher.publish$intellij_platform_core(CompositeMessageBus.kt:310)
at com.intellij.util.messages.impl.MessagePublisher.invoke(MessageBusImpl.kt:449)
at jdk.proxy2/jdk.proxy2.$Proxy26.beforeDocumentSaving(Unknown Source)
at jdk.internal.reflect.GeneratedMethodAccessor266.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.multiCast(FileDocumentManagerImpl.java:174)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.lambda$new$0(FileDocumentManagerImpl.java:130)
at jdk.proxy2/jdk.proxy2.$Proxy26.beforeDocumentSaving(Unknown Source)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.lambda$doSaveDocumentInWriteAction$3(FileDocumentManagerImpl.java:423)
at com.intellij.pom.core.impl.PomModelImpl.guardPsiModificationsIn(PomModelImpl.java:321)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.doSaveDocumentInWriteAction(FileDocumentManagerImpl.java:422)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.lambda$doSaveDocument$2(FileDocumentManagerImpl.java:375)
at com.intellij.openapi.application.WriteAction.lambda$run$1(WriteAction.java:85)
at com.intellij.openapi.application.impl.RwLockHolder.runWriteAction(RwLockHolder.kt:364)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:893)
at com.intellij.openapi.application.WriteAction.run(WriteAction.java:84)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.doSaveDocument(FileDocumentManagerImpl.java:375)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveDocument(FileDocumentManagerImpl.java:324)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveDocument(FileDocumentManagerImpl.java:313)
at com.intellij.formatting.service.AsyncDocumentFormattingService$FormattingRequestImpl.<init>(AsyncDocumentFormattingService.java:180)
at com.intellij.formatting.service.AsyncDocumentFormattingService.formatDocument(AsyncDocumentFormattingService.java:75)
at com.intellij.formatting.service.AbstractDocumentFormattingService.formatElement(AbstractDocumentFormattingService.java:47)
at com.intellij.formatting.service.AbstractDocumentFormattingService.formatElement(AbstractDocumentFormattingService.java:31)
at com.intellij.formatting.service.FormattingServiceUtil.formatElement(FormattingServiceUtil.java:67)
at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformat(CodeStyleManagerImpl.java:83)
at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformat(CodeStyleManagerImpl.java:67)
at com.jetbrains.python.codeInsight.imports.AddImportHelper.addNameToFromImportStatement(AddImportHelper.java:780)
at com.jetbrains.python.codeInsight.imports.ImportFromExistingAction.addToExistingImport(ImportFromExistingAction.java:183)
at com.jetbrains.python.codeInsight.imports.ImportFromExistingAction.doIt(ImportFromExistingAction.java:116)
at com.jetbrains.python.codeInsight.imports.ImportFromExistingAction.lambda$doWriteAction$1(ImportFromExistingAction.java:199)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$1(WriteCommandAction.java:144)
at com.intellij.openapi.application.impl.RwLockHolder.runWriteAction(RwLockHolder.kt:344)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:883)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$2(WriteCommandAction.java:142)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:225)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:187)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.doRunWriteCommandAction(WriteCommandAction.java:151)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:118)
at com.jetbrains.python.codeInsight.imports.ImportFromExistingAction.doWriteAction(ImportFromExistingAction.java:199)
at com.jetbrains.python.codeInsight.imports.ImportFromExistingAction.lambda$selectSourceAndDo$0(ImportFromExistingAction.java:110)
at org.jetbrains.concurrency.AsyncPromise.onSuccess$lambda$3(AsyncPromise.kt:87)
at org.jetbrains.concurrency.AsyncPromise$whenComplete$1.invoke(AsyncPromise.kt:114)
at org.jetbrains.concurrency.AsyncPromise$whenComplete$1.invoke(AsyncPromise.kt:112)
at org.jetbrains.concurrency.AsyncPromise.whenComplete$lambda$6(AsyncPromise.kt:112)
at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:934)
at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:911)
at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147)
at org.jetbrains.concurrency.AsyncPromise.setResult(AsyncPromise.kt:188)
at com.jetbrains.python.codeInsight.imports.PyImportChooser.lambda$selectImport$0(PyImportChooser.java:40)
at com.intellij.ui.popup.PopupListAdapter.lambda$setItemChosenCallback$0(PopupListAdapter.java:57)
at com.intellij.openapi.ui.popup.PopupChooserBuilder.lambda$setItemChosenCallback$0(PopupChooserBuilder.java:206)
at com.intellij.ui.popup.AbstractPopup.lambda$dispose$18(AbstractPopup.java:1766)
at com.intellij.openapi.wm.impl.FocusManagerImpl.lambda$doWhenFocusSettlesDown$4(FocusManagerImpl.java:174)
at com.intellij.util.ui.EdtInvocationManager.invokeLaterIfNeeded(EdtInvocationManager.java:33)
at com.intellij.ide.IdeEventQueue.ifFocusEventsInTheQueue(IdeEventQueue.kt:226)
at com.intellij.ide.IdeEventQueue.executeWhenAllFocusEventsLeftTheQueue(IdeEventQueue.kt:192)
at com.intellij.openapi.wm.impl.FocusManagerImpl.doWhenFocusSettlesDown(FocusManagerImpl.java:170)
at com.intellij.openapi.wm.impl.FocusManagerImpl.doWhenFocusSettlesDown(FocusManagerImpl.java:164)
at com.intellij.ui.popup.AbstractPopup.dispose(AbstractPopup.java:1764)
at com.intellij.openapi.util.ObjectTree.runWithTrace(ObjectTree.java:130)
at com.intellij.openapi.util.ObjectTree.executeAll(ObjectTree.java:162)
at com.intellij.openapi.util.Disposer.dispose(Disposer.java:205)
at com.intellij.ui.popup.AbstractPopup.cancel(AbstractPopup.java:941)
at com.intellij.ui.popup.AbstractPopup.closeOk(AbstractPopup.java:875)
at com.intellij.openapi.ui.popup.PopupChooserBuilder.closePopup(PopupChooserBuilder.java:500)
at com.intellij.openapi.ui.popup.PopupChooserBuilder$2.actionPerformed(PopupChooserBuilder.java:489)
at java.desktop/javax.swing.JComponent$ActionStandin.actionPerformed(JComponent.java:3486)
at java.desktop/javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1810)
at java.desktop/javax.swing.JComponent.processKeyBinding(JComponent.java:2943)
at java.desktop/javax.swing.JComponent.processKeyBindings(JComponent.java:3005)
at java.desktop/javax.swing.JComponent.processKeyEvent(JComponent.java:2905)
at java.desktop/java.awt.Component.processEvent(Component.java:6434)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855)
at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:886)
at java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1166)
at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1023)
at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:849)
at com.intellij.ide.IdeKeyboardFocusManager.access$dispatchEvent$s1569605750(IdeKeyboardFocusManager.kt:22)
at com.intellij.ide.IdeKeyboardFocusManager$dispatchEvent$1.invoke(IdeKeyboardFocusManager.kt:39)
at com.intellij.ide.IdeKeyboardFocusManager$dispatchEvent$1.invoke(IdeKeyboardFocusManager.kt:39)
at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1021)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1021)
at com.intellij.ide.IdeKeyboardFocusManager.dispatchEvent(IdeKeyboardFocusManager.kt:39)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4904)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2809)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:794)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:733)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:766)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:764)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:763)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:698)
at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.kt:625)
at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$11(IdeEventQueue.kt:585)
at com.intellij.openapi.application.impl.RwLockHolder.runWithEnabledImplicitRead(RwLockHolder.kt:138)
at com.intellij.openapi.application.impl.RwLockHolder.runWithImplicitRead(RwLockHolder.kt:129)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:585)
at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:77)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:362)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:361)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:843)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:361)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:356)
at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1021)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:114)
at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1021)
at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$7(IdeEventQueue.kt:356)
at com.intellij.openapi.application.impl.RwLockHolder.runIntendedWriteActionOnCurrentThread(RwLockHolder.kt:209)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:830)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:398)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
To Reproduce
Steps to reproduce the behavior:
black
.ruff
both when the file is saved and when it's re-formatted.Environments (please complete the following information):
Linux stsav012-pendrive 6.5.13-7-MANJARO #1 SMP PREEMPT_DYNAMIC Wed Dec 20 07:15:58 UTC 2023 x86_64 GNU/Linux
Additional context
I can't reproduce the fail reliably yet. I just hope the traceback is enough to deal with the issue.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too