Skip to content

Commit

Permalink
fix(read locks): fix read lock when setting file content.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMcIntosh committed Nov 21, 2024
1 parent 596daf7 commit d42d44a
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable {

private fun deleteFile(fileName: String) {
logger.warn("deleteFile: $fileName")
ApplicationManager.getApplication().runReadAction {
ApplicationManager.getApplication().invokeLater {
LocalFileSystem.getInstance().findFileByPath(fileName)?.delete(this.project)
}
}
Expand Down Expand Up @@ -363,15 +363,13 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable {

private fun setContent(fileName: String, content: String) {
logger.warn("setContent: item.fileNameEdit = $fileName")
val file = ApplicationManager.getApplication().runReadAction<VirtualFile?> {
LocalFileSystem.getInstance().refreshAndFindFileByPath(fileName)
}
if (file == null) {
logger.warn("setContent: item.fileNameEdit = $fileName is null")
return
}

ApplicationManager.getApplication().invokeLater {
val file = LocalFileSystem.getInstance().refreshAndFindFileByPath(fileName)
if (file == null) {
logger.warn("setContent: item.fileNameEdit = $fileName is null")
return@invokeLater
}

FileDocumentManager.getInstance().getDocument(file)?.setText(content)
}
}
Expand Down Expand Up @@ -403,16 +401,14 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable {
logger.warn("showPatch: item.fileNameEdit = $fileName")
this.handleAnimationStop(fileName)

val file = ApplicationManager.getApplication().runReadAction<VirtualFile?> {
LocalFileSystem.getInstance().refreshAndFindFileByPath(fileName)
}
if (file == null) {
logger.warn("showPatch: item.fileNameEdit = $fileName is null")
return
}

val fileDescriptor = OpenFileDescriptor(project, file)
ApplicationManager.getApplication().invokeLater {
val file = LocalFileSystem.getInstance().refreshAndFindFileByPath(fileName)
if (file == null) {
logger.warn("showPatch: item.fileNameEdit = $fileName is null")
return@invokeLater
}

val fileDescriptor = OpenFileDescriptor(project, file)
val editor = FileEditorManager.getInstance(project).openTextEditor(fileDescriptor, true)
editor?.selectionModel?.setSelection(0, editor.document.textLength)
if (editor != null) {
Expand Down

0 comments on commit d42d44a

Please sign in to comment.