Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复文件死锁问题 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.6.8

* Fix 修复文件死锁问题

## 0.6.7

* Feature 优化代码,移除废弃的方法调用,并且做了低版本兼容
Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ version = properties("pluginVersion")

repositories {
mavenCentral()
maven {
url = uri("https://www.jetbrains.com/intellij-repository/releases")
}
}

// Configure Gradle IntelliJ Plugin
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginVersion=0.6.7
pluginVersion=0.6.8
#intellijVersion=2022.2.2
#intellijVersion=2023.1
#intellijVersion=2024.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.intellij.json.JsonFileType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.application.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
Expand Down Expand Up @@ -36,30 +33,6 @@ public MethodMetaDataRepository(Project project) {
this.basePath = project.getBasePath();
}

// public ClassMetadata getFromClassname(String classname) {
// Path phpFilePath = PathManager.findBinFile(getDir() + File.separator + decodeFileName(classname) + "." + fileExtension);
// if (Optional.ofNullable(phpFilePath).isEmpty()) {
// return null;
// }
//
// Gson gson = new GsonBuilder()
// .serializeNulls()
// .registerTypeAdapter(AccessorMethod.class, AccessorMethodDeserializerFactory.create())
// .create();
// VirtualFile file = VfsUtil.findFile(phpFilePath, true);
// if (Optional.ofNullable(file).isEmpty()) {
// return null;
// }
//
//// file.refresh(false, false);
// try {
// String json = new String(file.getInputStream().readAllBytes());
// return gson.fromJson(json, ClassMetadata.class);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }

public ClassMetadata getFromClassname(String classname) {
Path phpFilePath = PathManager.findBinFile(getDir() + File.separator + decodeFileName(classname) + "." + fileExtension);
if (Optional.ofNullable(phpFilePath).isEmpty()) {
Expand All @@ -76,11 +49,18 @@ public ClassMetadata getFromClassname(String classname) {
return null;
}

// WriteAction.run(() -> file.refresh(false, false));

// ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(() -> file.refresh(false, false)));
ApplicationManager.getApplication().invokeLater(() -> WriteAction.run(() -> file.refresh(false, false)));

// ApplicationManager.getApplication().invokeLater(() -> {
// WriteAction.run(() -> file.refresh(false, false));
// }, ModalityState.defaultModalityState());

// 判断文件是否上锁,上锁则等到解锁后再读取
while (!file.isWritable()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

try {
String json = new String(file.getInputStream().readAllBytes());
Expand Down