mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[mod-commands] ModCommandExecutorImpl.ActionContextPointer: do not rely on PsiFile validity
It can be invalidated easily. Get the fresh one from VirtualFile Fixes IDEA-365492 File is invalid, when invoking some ModCommand based intention from property tests GitOrigin-RevId: 24a7d42f4d774f19ce8e118b22aeaa7d9d7dc2bc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b0c1412cba
commit
71f54717d0
+7
-4
@@ -76,6 +76,7 @@ import java.awt.datatransfer.StringSelection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static java.util.Objects.requireNonNullElse;
|
||||
@@ -540,7 +541,7 @@ public class ModCommandExecutorImpl extends ModCommandBatchExecutorImpl {
|
||||
|
||||
private static class ActionContextPointer {
|
||||
private final @NotNull Project myProject;
|
||||
private final @NotNull PsiFile myFile;
|
||||
private final @NotNull VirtualFile myFile;
|
||||
private final @Nullable SmartPsiElementPointer<PsiElement> myElementPointer;
|
||||
private final @NotNull RangeMarker myOffsetMarker;
|
||||
private final @NotNull RangeMarker mySelectionMarker;
|
||||
@@ -548,9 +549,9 @@ public class ModCommandExecutorImpl extends ModCommandBatchExecutorImpl {
|
||||
|
||||
ActionContextPointer(@NotNull ActionContext context) {
|
||||
myProject = context.project();
|
||||
myFile = context.file();
|
||||
myFile = Objects.requireNonNull(context.file().getVirtualFile());
|
||||
myElementPointer = context.element() != null ? SmartPointerManager.createPointer(context.element()) : null;
|
||||
Document document = myFile.getFileDocument();
|
||||
Document document = context.file().getFileDocument();
|
||||
myOffsetMarker = document.createRangeMarker(context.offset(), context.offset());
|
||||
mySelectionMarker = document.createRangeMarker(context.selection());
|
||||
}
|
||||
@@ -565,7 +566,9 @@ public class ModCommandExecutorImpl extends ModCommandBatchExecutorImpl {
|
||||
|
||||
@Nullable ActionContext restore() {
|
||||
if (!isValid()) return null;
|
||||
return new ActionContext(myProject, myFile, myOffsetMarker.getStartOffset(),
|
||||
PsiFile file = PsiManager.getInstance(myProject).findFile(myFile);
|
||||
if (file == null) return null;
|
||||
return new ActionContext(myProject, file, myOffsetMarker.getStartOffset(),
|
||||
mySelectionMarker.getTextRange(), myElementPointer != null ? myElementPointer.getElement() : null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user