Implement isolated Build and Refresh with immutable leased snapshots
This commit is contained in:
+27
-1
@@ -90,6 +90,26 @@ public final class IntellijDocuments implements HostServices.Documents, AutoClos
|
||||
});
|
||||
}
|
||||
|
||||
public CompletionStage<List<DocumentSnapshot>> unsaved() {
|
||||
return edt(
|
||||
() -> {
|
||||
var result = new ArrayList<DocumentSnapshot>();
|
||||
var manager = FileDocumentManager.getInstance();
|
||||
for (var document : manager.getUnsavedDocuments()) {
|
||||
var file = manager.getFile(document);
|
||||
if (file == null || !file.isInLocalFileSystem()) continue;
|
||||
var handle =
|
||||
(Handle) open(Path.of(file.getPath()).toUri()).toCompletableFuture().join();
|
||||
try {
|
||||
result.add(snapshot(handle.s));
|
||||
} finally {
|
||||
handle.release();
|
||||
}
|
||||
}
|
||||
return List.copyOf(result);
|
||||
});
|
||||
}
|
||||
|
||||
private DocumentSnapshot snapshot(State s) {
|
||||
return new DocumentSnapshot(
|
||||
Path.of(s.file.getPath()).toUri(),
|
||||
@@ -171,7 +191,13 @@ public final class IntellijDocuments implements HostServices.Documents, AutoClos
|
||||
if (!s.document.isWritable() || !s.file.isWritable())
|
||||
throw new IllegalStateException("Read-only document");
|
||||
Path file = Path.of(s.file.getPath());
|
||||
if (!Files.readString(file).equals(s.disk))
|
||||
String onDisk = Files.readString(file);
|
||||
if (!FileDocumentManager.getInstance().isDocumentUnsaved(s.document)
|
||||
&& onDisk.equals(s.document.getText())) {
|
||||
s.disk = onDisk;
|
||||
return IntellijDocuments.this.snapshot(s);
|
||||
}
|
||||
if (!onDisk.equals(s.disk))
|
||||
throw new ConcurrentModificationException("External change; draft retained");
|
||||
FileDocumentManager.getInstance().saveDocument(s.document);
|
||||
if (FileDocumentManager.getInstance().isDocumentUnsaved(s.document))
|
||||
|
||||
Reference in New Issue
Block a user