koxudaxi / ruff-pycharm-plugin

PyCharm plugin for ruff. This plugin provides reformat code using ruff.
MIT License
204 stars 10 forks source link

Read Access error when unshelving changes #344

Closed johnthagen closed 8 months ago

johnthagen commented 9 months ago

Describe the bug

When unshelving changes using the PyCharm shelf feature, if the changes modify a Python file, I sometimes get an unhandled exception in the Ruff plugin:

com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: Read access is allowed from inside read-action (see Application.runReadAction()); see https://jb.gg/ij-platform-threading for details
Current thread: Thread[ApplicationImpl pooled thread 162,4,main] 887693740 (EventQueue.isDispatchThread()=false)
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,main] 169213168
    at com.intellij.util.concurrency.ThreadingAssertions.createThreadAccessException(ThreadingAssertions.java:149)
    at com.intellij.util.concurrency.ThreadingAssertions.softAssertReadAccess(ThreadingAssertions.java:107)
    at com.intellij.openapi.application.impl.ApplicationImpl.assertReadAccessAllowed(ApplicationImpl.java:1012)
    at com.intellij.openapi.fileEditor.impl.FileDocumentManagerBase.getDocument(FileDocumentManagerBase.java:47)
    at com.intellij.openapi.fileEditor.FileDocumentManager.getDocument(FileDocumentManager.java:61)
    at com.intellij.psi.AbstractFileViewProvider.getDocument(AbstractFileViewProvider.java:170)
    at com.intellij.psi.AbstractFileViewProvider$VirtualFileContent.getText(AbstractFileViewProvider.java:446)
    at com.intellij.psi.AbstractFileViewProvider.getContents(AbstractFileViewProvider.java:151)
    at com.intellij.psi.impl.source.PsiFileImpl.getText(PsiFileImpl.java:307)
    at com.koxudaxi.ruff.SourceFile$text$2.invoke(Ruff.kt:269)
    at com.koxudaxi.ruff.SourceFile$text$2.invoke(Ruff.kt:269)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at com.koxudaxi.ruff.SourceFile.getText(Ruff.kt:269)
    at com.koxudaxi.ruff.SourceFile.getAsStdin(Ruff.kt:274)
    at com.koxudaxi.ruff.RuffKt.generateCommandArgs(Ruff.kt:297)
    at com.koxudaxi.ruff.RuffKt.runRuff(Ruff.kt:282)
    at com.koxudaxi.ruff.RuffApplyService.apply$lambda$2(RuffApplyService.kt:48)
    at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:249)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:840)

Expected behavior

No unhandled exceptions when using Ruff PyCharm plugin.

Environments:

koxudaxi commented 8 months ago

Thank you for creating the issue. I didn't test the plugin for the unshelving changes feature. I will fix it.

koxudaxi commented 8 months ago

@johnthagen I have released fixed version 0.0.29 Thank you very much!!

johnthagen commented 8 months ago

Thanks @koxudaxi!