use up to date PSI to query intentions in "goto action"

This commit is contained in:
peter
2017-10-31 11:58:20 +01:00
parent 76bb61812e
commit 3fc043ee72
6 changed files with 14 additions and 19 deletions
@@ -72,6 +72,6 @@ class GotoActionTest extends LightCodeInsightFixtureTestCase {
void actionPerformed(AnActionEvent e) {
}
}
new GotoActionModel.ActionWrapper(action, "", mode, DataContext.EMPTY_CONTEXT, new GotoActionModel(project, null, null, null))
new GotoActionModel.ActionWrapper(action, "", mode, DataContext.EMPTY_CONTEXT, new GotoActionModel(project, null, null))
}
}
@@ -21,7 +21,6 @@ import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiDocumentManager;
@@ -61,8 +60,8 @@ public class ApplyIntentionAction extends AnAction {
@Nullable
public static ApplyIntentionAction[] getAvailableIntentions(final Editor editor, final PsiFile file) {
final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
ApplicationManager.getApplication().runReadAction(() -> ShowIntentionsPass.getActionsToShow(editor, file, info, -1));
ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
ShowIntentionsPass.getActionsToShow(editor, file, info, -1);
if (info.isEmpty()) return null;
final List<HighlightInfo.IntentionActionDescriptor> actions = new ArrayList<>();
@@ -48,7 +48,6 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.psi.PsiFile;
import com.intellij.ui.HeldDownKeyListener;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
@@ -70,10 +69,9 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
final Project project = e.getData(CommonDataKeys.PROJECT);
final Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
Editor editor = e.getData(CommonDataKeys.EDITOR);
PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.action");
GotoActionModel model = new GotoActionModel(project, component, editor, file);
GotoActionModel model = new GotoActionModel(project, component, editor);
GotoActionCallback<Object> callback = new GotoActionCallback<Object>() {
@Override
public void elementChosen(@NotNull ChooseByNamePopup popup, @NotNull Object element) {
@@ -192,7 +192,6 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA
private Editor myEditor;
private FileEditor myFileEditor;
private PsiFile myFile;
private HistoryItem myHistoryItem;
@Override
@@ -597,7 +596,6 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA
if (e != null) {
myEditor = e.getData(CommonDataKeys.EDITOR);
myFileEditor = e.getData(PlatformDataKeys.FILE_EDITOR);
myFile = e.getData(CommonDataKeys.PSI_FILE);
}
if (e == null && myFocusOwner != null) {
e = AnActionEvent.createFromAnAction(this, me, ActionPlaces.UNKNOWN, DataManager.getInstance().getDataContext(myFocusOwner));
@@ -1982,7 +1980,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA
}
private GotoActionItemProvider createActionProvider() {
GotoActionModel model = new GotoActionModel(project, myFocusComponent, myEditor, myFile) {
GotoActionModel model = new GotoActionModel(project, myFocusComponent, myEditor) {
@Override
protected MatchMode actionMatches(@NotNull String pattern, MinusculeMatcher matcher, @NotNull AnAction anAction) {
MatchMode mode = super.actionMatches(pattern, matcher, anAction);
@@ -25,6 +25,7 @@ import com.intellij.ide.ui.search.SearchableOptionsRegistrar;
import com.intellij.ide.ui.search.SearchableOptionsRegistrarImpl;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.impl.ActionManagerImpl;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NotNullLazyValue;
@@ -55,7 +56,7 @@ public class GotoActionItemProvider implements ChooseByNameItemProvider {
public GotoActionItemProvider(GotoActionModel model) {
myModel = model;
myIntentions = NotNullLazyValue.createValue(() -> myModel.getAvailableIntentions());
myIntentions = NotNullLazyValue.createValue(() -> ReadAction.compute(() -> myModel.getAvailableIntentions()));
}
@NotNull
@@ -38,7 +38,7 @@ import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.codeStyle.MinusculeMatcher;
import com.intellij.ui.*;
import com.intellij.ui.components.JBLabel;
@@ -74,7 +74,6 @@ public class GotoActionModel implements ChooseByNameModel, Comparator<Object>, D
@Nullable private final Project myProject;
private final Component myContextComponent;
@Nullable private final Editor myEditor;
@Nullable private final PsiFile myFile;
protected final ActionManager myActionManager = ActionManager.getInstance();
@@ -94,15 +93,14 @@ public class GotoActionModel implements ChooseByNameModel, Comparator<Object>, D
private final ModalityState myModality;
public GotoActionModel(@Nullable Project project, Component component, @Nullable Editor editor, @Nullable PsiFile file) {
this(project, component, editor, file, ModalityState.defaultModalityState());
public GotoActionModel(@Nullable Project project, Component component, @Nullable Editor editor) {
this(project, component, editor, ModalityState.defaultModalityState());
}
public GotoActionModel(@Nullable Project project, Component component, @Nullable Editor editor, @Nullable PsiFile file, @Nullable ModalityState modalityState) {
public GotoActionModel(@Nullable Project project, Component component, @Nullable Editor editor, @Nullable ModalityState modalityState) {
myProject = project;
myContextComponent = component;
myEditor = editor;
myFile = file;
myModality = modalityState;
ActionGroup mainMenu = (ActionGroup)myActionManager.getActionOrStub(IdeActions.GROUP_MAIN_MENU);
assert mainMenu != null;
@@ -112,8 +110,9 @@ public class GotoActionModel implements ChooseByNameModel, Comparator<Object>, D
@NotNull
Map<String, ApplyIntentionAction> getAvailableIntentions() {
Map<String, ApplyIntentionAction> map = new TreeMap<>();
if (myProject != null && myEditor != null && myFile != null) {
ApplyIntentionAction[] children = ApplyIntentionAction.getAvailableIntentions(myEditor, myFile);
if (myProject != null && !myProject.isDisposed() && myEditor != null && !myEditor.isDisposed()) {
ApplyIntentionAction[] children = ApplyIntentionAction.getAvailableIntentions(myEditor, PsiDocumentManager.getInstance(myProject).getPsiFile(
myEditor.getDocument()));
if (children != null) {
for (ApplyIntentionAction action : children) {
map.put(action.getName(), action);