mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'tab-completions' of https://github.com/fitermay/intellij-community
This commit is contained in:
@@ -19,6 +19,7 @@ import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.ExecutionHelper;
|
||||
import com.intellij.execution.Executor;
|
||||
@@ -40,11 +41,13 @@ import com.intellij.ide.errorTreeView.NewErrorTreeViewPanel;
|
||||
import com.intellij.internal.statistic.UsageTrigger;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler;
|
||||
@@ -61,10 +64,7 @@ import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.StreamUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
@@ -164,7 +164,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
@Nullable final String workingDir,
|
||||
Map<String, String> environmentVariables,
|
||||
@NotNull
|
||||
PyConsoleOptions.PyConsoleSettings settingsProvider,
|
||||
PyConsoleOptions.PyConsoleSettings settingsProvider,
|
||||
String... statementsToExecute) {
|
||||
super(project, consoleType.getTitle(), workingDir);
|
||||
mySdk = sdk;
|
||||
@@ -316,6 +316,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
|
||||
actions.add(backspaceHandlingAction);
|
||||
actions.add(interruptAction);
|
||||
actions.add(createTabCompletionAction());
|
||||
|
||||
actions.add(createSplitLineAction());
|
||||
|
||||
@@ -385,24 +386,25 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
myGeneralCommandLine = createCommandLine(mySdk, myEnvironmentVariables, getWorkingDir(), myPorts);
|
||||
myCommandLine = myGeneralCommandLine.getCommandLineString();
|
||||
|
||||
UIUtil.invokeLaterIfNeeded(() -> ProgressManager.getInstance().run(new Task.Backgroundable(getProject(), "Connecting to Console", false) {
|
||||
@Override
|
||||
public void run(@NotNull final ProgressIndicator indicator) {
|
||||
indicator.setText("Connecting to console...");
|
||||
try {
|
||||
initAndRun(myStatementsToExecute);
|
||||
UIUtil
|
||||
.invokeLaterIfNeeded(() -> ProgressManager.getInstance().run(new Task.Backgroundable(getProject(), "Connecting to Console", false) {
|
||||
@Override
|
||||
public void run(@NotNull final ProgressIndicator indicator) {
|
||||
indicator.setText("Connecting to console...");
|
||||
try {
|
||||
initAndRun(myStatementsToExecute);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
LOG.warn("Error running console", e);
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showErrorsInConsole(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
LOG.warn("Error running console", e);
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showErrorsInConsole(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
private void showErrorsInConsole(Exception e) {
|
||||
@@ -564,7 +566,8 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Using tunneled communication for Python console: port %d (=> %d) on IDE side, " +
|
||||
"port %d (=> %d) on pydevconsole.py side", myPorts[1], remotePorts.second, myPorts[0], remotePorts.first));
|
||||
"port %d (=> %d) on pydevconsole.py side", myPorts[1], remotePorts.second, myPorts[0],
|
||||
remotePorts.first));
|
||||
}
|
||||
|
||||
myPydevConsoleCommunication = new PydevRemoteConsoleCommunication(getProject(), myPorts[0], remoteProcess, myPorts[1]);
|
||||
@@ -575,7 +578,8 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
remotePorts.second, remotePorts.first));
|
||||
}
|
||||
|
||||
myPydevConsoleCommunication = new PydevRemoteConsoleCommunication(getProject(), remotePorts.first, remoteProcess, remotePorts.second);
|
||||
myPydevConsoleCommunication =
|
||||
new PydevRemoteConsoleCommunication(getProject(), remotePorts.first, remoteProcess, remotePorts.second);
|
||||
}
|
||||
|
||||
return remoteProcess;
|
||||
@@ -731,6 +735,47 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
return anAction;
|
||||
}
|
||||
|
||||
private AnAction createTabCompletionAction() {
|
||||
final AnAction runCompletions = new AnAction() {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
|
||||
Editor editor = getConsoleView().getConsoleEditor();
|
||||
if (LookupManager.getActiveLookup(editor) != null) {
|
||||
AnAction replace = ActionManager.getInstance().getAction("EditorChooseLookupItemReplace");
|
||||
ActionUtil.performActionDumbAware(replace, e);
|
||||
return;
|
||||
}
|
||||
AnAction completionAction = ActionManager.getInstance().getAction("CodeCompletion");
|
||||
if (completionAction == null) {
|
||||
return;
|
||||
}
|
||||
ActionUtil.performActionDumbAware(completionAction, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Editor editor = getConsoleView().getConsoleEditor();
|
||||
if (LookupManager.getActiveLookup(editor) != null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
}
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
Document document = editor.getDocument();
|
||||
int lineStart = document.getLineStartOffset(document.getLineNumber(offset));
|
||||
String textToCursor = document.getText(new TextRange(lineStart, offset));
|
||||
e.getPresentation().setEnabled(!CharMatcher.WHITESPACE.matchesAllOf(textToCursor));
|
||||
}
|
||||
};
|
||||
|
||||
runCompletions
|
||||
.registerCustomShortcutSet(KeyEvent.VK_TAB, 0, getConsoleView().getConsoleEditor().getComponent());
|
||||
runCompletions.getTemplatePresentation().setVisible(false);
|
||||
return runCompletions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private AnAction createBackspaceHandlingAction() {
|
||||
final AnAction upAction = new AnAction() {
|
||||
|
||||
Reference in New Issue
Block a user