allow to invoke code completion in whatever project the editor has

including the default one
This commit is contained in:
peter
2018-01-30 17:34:18 +01:00
parent fe1c485a64
commit e70a559ebb
2 changed files with 7 additions and 20 deletions
@@ -42,10 +42,10 @@ public abstract class BaseCodeCompletionAction extends DumbAwareAction implement
}
protected void invokeCompletion(AnActionEvent e, CompletionType type, int time) {
Project project = e.getData(CommonDataKeys.PROJECT);
Editor editor = e.getData(CommonDataKeys.EDITOR);
assert project != null;
assert editor != null;
Project project = editor.getProject();
assert project != null;
InputEvent inputEvent = e.getInputEvent();
createHandler(type, true, false, true).invokeCompletion(project, editor, time, inputEvent != null && inputEvent.getModifiers() != 0, false);
}
@@ -60,13 +60,12 @@ public abstract class BaseCodeCompletionAction extends DumbAwareAction implement
public void update(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
e.getPresentation().setEnabled(false);
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) return;
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
if (editor == null) return;
final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
Project project = editor.getProject();
PsiFile psiFile = project == null ? null : PsiUtilBase.getPsiFileInEditor(editor, project);
if (psiFile == null) return;
if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing()) return;
@@ -15,12 +15,10 @@
*/
package com.intellij.codeInsight.hint;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
public class EscapeHandler extends EditorActionHandler {
@@ -32,9 +30,7 @@ public class EscapeHandler extends EditorActionHandler {
@Override
public void doExecute(@NotNull Editor editor, Caret caret, DataContext dataContext) {
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project != null &&
HintManagerImpl.getInstanceImpl().hideHints(HintManager.HIDE_BY_ESCAPE | HintManager.HIDE_BY_ANY_KEY, true, false)) {
if (HintManagerImpl.getInstanceImpl().hideHints(HintManager.HIDE_BY_ESCAPE | HintManager.HIDE_BY_ANY_KEY, true, false)) {
return;
}
myOriginalHandler.execute(editor, caret, dataContext);
@@ -42,15 +38,7 @@ public class EscapeHandler extends EditorActionHandler {
@Override
public boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) {
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project != null) {
HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
if (hintManager.isEscapeHandlerEnabled()) {
return true;
}
}
return myOriginalHandler.isEnabled(editor, caret, dataContext);
HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
return hintManager.isEscapeHandlerEnabled() || myOriginalHandler.isEnabled(editor, caret, dataContext);
}
}