Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2012-10-24 20:09:14 +04:00
5 changed files with 72 additions and 55 deletions
+3 -10
View File
@@ -156,7 +156,7 @@ class InterpreterInterface(BaseInterpreterInterface):
completer = Completer(self.namespace, None)
return completer.complete(act_tok)
except:
import traceback;
import traceback
traceback.print_exc()
return []
@@ -183,15 +183,8 @@ def process_exec_queue(interpreter):
raise
except:
type, value, tb = sys.exc_info()
try:
print_exception()
rpc.response_queue.put((seq, None))
except:
# Link didn't work, print same exception to __stderr__
traceback.print_exception(type, value, tb, file=sys.__stderr__)
exit()
else:
continue
traceback.print_exception(type, value, tb, file=sys.__stderr__)
exit()
try:
@@ -37,12 +37,12 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
/**
* XML-RPC client for sending messages to the server.
*/
private IPydevXmlRpcClient client;
private IPydevXmlRpcClient myClient;
/**
* This is the server responsible for giving input to a raw_input() requested.
*/
private WebServer webServer;
private WebServer myWebServer;
private static final Logger LOG = Logger.getInstance(PydevConsoleCommunication.class.getName());
@@ -78,16 +78,16 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
super(project);
//start the server that'll handle input requests
webServer = new IdeaAwareWebServer(clientPort, null, new IdeaAwareXmlRpcServer());
webServer.addHandler("$default", this);
this.webServer.start();
myWebServer = new IdeaAwareWebServer(clientPort, null, new IdeaAwareXmlRpcServer());
myWebServer.addHandler("$default", this);
this.myWebServer.start();
this.client = new PydevXmlRpcClient(process, port);
this.myClient = new PydevXmlRpcClient(process, port);
}
public boolean handshake() throws XmlRpcException {
if (client != null) {
Object ret = client.execute(HANDSHAKE, new Object[]{});
if (myClient != null) {
Object ret = myClient.execute(HANDSHAKE, new Object[]{});
if (ret instanceof String) {
String retVal = (String)ret;
return "PyCharm".equals(retVal);
@@ -99,25 +99,25 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
/**
* Stops the communication with the client (passes message for it to quit).
*/
public void close() {
if (this.client != null) {
public synchronized void close() {
if (this.myClient != null) {
new Task.Backgroundable(myProject, "Close console communication", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
PydevConsoleCommunication.this.client.execute(CLOSE, new Object[0]);
PydevConsoleCommunication.this.myClient.execute(CLOSE, new Object[0]);
}
catch (Exception e) {
//Ok, we can ignore this one on close.
}
PydevConsoleCommunication.this.client = null;
PydevConsoleCommunication.this.myClient = null;
}
}.queue();
}
if (this.webServer != null) {
this.webServer.shutdown();
this.webServer = null;
if (myWebServer != null) {
myWebServer.shutdown();
myWebServer = null;
}
}
@@ -236,7 +236,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
*/
protected Pair<String, Boolean> exec(final String command) throws XmlRpcException {
setExecuting(true);
Object execute = client.execute(EXEC_LINE, new Object[]{command});
Object execute = myClient.execute(EXEC_LINE, new Object[]{command});
Object object;
if (execute instanceof Vector) {
@@ -264,7 +264,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
if (waitingForInput) {
return Collections.emptyList();
}
final Object fromServer = client.execute(GET_COMPLETIONS, new Object[]{text, actTok});
final Object fromServer = myClient.execute(GET_COMPLETIONS, new Object[]{text, actTok});
return PydevXmlUtils.decodeCompletions(fromServer);
}
@@ -276,7 +276,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
if (waitingForInput) {
return "Unable to get description: waiting for input.";
}
return client.execute(GET_DESCRIPTION, new Object[]{text}).toString();
return myClient.execute(GET_DESCRIPTION, new Object[]{text}).toString();
}
/**
@@ -395,7 +395,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
@Override
public void interrupt() {
try {
client.execute("interrupt", new Object[]{});
myClient.execute("interrupt", new Object[]{});
}
catch (XmlRpcException e) {
LOG.error(e);
@@ -29,7 +29,6 @@ import com.intellij.openapi.progress.Task;
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.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
@@ -40,8 +39,8 @@ import com.intellij.psi.impl.source.tree.FileElement;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IJSwingUtilities;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.net.NetUtils;
import com.intellij.util.ui.UIUtil;
import com.jetbrains.django.run.Runner;
import com.jetbrains.plugins.remotesdk.RemoteInterpreterException;
import com.jetbrains.plugins.remotesdk.RemoteSdkData;
@@ -50,7 +49,6 @@ import com.jetbrains.python.PythonHelpersLocator;
import com.jetbrains.python.console.completion.PydevConsoleElement;
import com.jetbrains.python.console.parsing.PythonConsoleData;
import com.jetbrains.python.console.pydev.ConsoleCommunication;
import com.jetbrains.python.console.pydev.ConsoleCommunicationListener;
import com.jetbrains.python.debugger.PySourcePosition;
import com.jetbrains.python.remote.PythonRemoteInterpreterManager;
import com.jetbrains.python.run.PythonCommandLineState;
@@ -485,21 +483,8 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
}
private void closeCommunication() {
if (myPydevConsoleCommunication.isExecuting()) {
final Semaphore s = new Semaphore(); //TODO: test me
myPydevConsoleCommunication.addCommunicationListener(new ConsoleCommunicationListener() {
@Override
public void executionFinished() {
s.up();
}
@Override
public void inputRequested() {
}
});
if (!myProcessHandler.isProcessTerminated()) {
myPydevConsoleCommunication.close();
s.waitFor();
}
}
@@ -594,9 +579,29 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
@Override
public void actionPerformed(AnActionEvent e) {
myConsoleRunner.closeCommunication();
myConsoleRunner.run();
myConsoleRunner.rerun();
}
}
private void rerun() {
new Task.Backgroundable(getProject(), "Restarting console", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
UIUtil.invokeLaterIfNeeded(new Runnable() {
public void run() {
PydevConsoleRunner.this.closeCommunication();
}
});
myProcessHandler.waitFor();
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
PydevConsoleRunner.this.run();
}
});
}
}.queue();
}
}
@@ -11,6 +11,7 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
@@ -111,7 +112,7 @@ public class PythonTask {
bashParams.addParameter("-cl");
NotNullFunction<String, String> escaperFunction = StringUtil.escaper(false, "|>$\"'& ");
StringBuilder paramString = new StringBuilder(escaperFunction.fun(homePath) + " " +escaperFunction.fun(myRunnerScript));
StringBuilder paramString = new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myRunnerScript));
for (String p : myParameters) {
paramString.append(" ").append(p);
@@ -152,8 +153,9 @@ public class PythonTask {
protected List<String> setupPythonPath(final boolean addProjectRoot) {
final List<String> pythonPath = Lists.newArrayList(PythonCommandLineState.getAddedPaths(mySdk));
if (addProjectRoot)
if (addProjectRoot) {
pythonPath.addAll(PythonCommandLineState.collectPythonPath(myModule));
}
return pythonPath;
}
@@ -174,6 +176,19 @@ public class PythonTask {
}
}
})
.withStop(new Runnable() {
@Override
public void run() {
process.destroyProcess();
}
}, new Computable<Boolean>() {
@Override
public Boolean compute() {
return !process.isProcessTerminated();
}
}
)
.withAfterCompletion(myAfterCompletion)
.withHelpId(myHelpId)
.run();
@@ -79,7 +79,11 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
@Nullable
@Override
public State collectionInformation(@NotNull PsiFile file) {
final Sdk sdk = PythonSdkType.findLocalPython(ModuleUtilCore.findModuleForPsiElement(file));
Sdk sdk = PythonSdkType.findPythonSdk(ModuleUtilCore.findModuleForPsiElement(file));
if (PythonSdkType.isRemote(sdk)) {
sdk = PythonSdkType.findLocalPython(ModuleUtilCore.findModuleForPsiElement(file));
}
if (sdk == null) return null;
final String homePath = sdk.getHomePath();
if (homePath == null) return null;
@@ -90,7 +94,7 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
}
final LocalInspectionToolWrapper profileEntry = (LocalInspectionToolWrapper)profile.getInspectionTool(
PyPep8Inspection.INSPECTION_SHORT_NAME, file);
final List<String> ignoredErrors = ((PyPep8Inspection) profileEntry.getTool()).ignoredErrors;
final List<String> ignoredErrors = ((PyPep8Inspection)profileEntry.getTool()).ignoredErrors;
final int margin = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings().RIGHT_MARGIN;
return new State(homePath, file.getText(), profile.getErrorLevel(key, file), ignoredErrors, margin);
}
@@ -127,8 +131,8 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
public void apply(@NotNull PsiFile file, State annotationResult, @NotNull AnnotationHolder holder) {
if (annotationResult == null) return;
final String text = file.getText();
for (Problem problem: annotationResult.problems) {
int offset = StringUtil.lineColToOffset(text, problem.myLine-1, problem.myColumn-1);
for (Problem problem : annotationResult.problems) {
int offset = StringUtil.lineColToOffset(text, problem.myLine - 1, problem.myColumn - 1);
PsiElement problemElement = file.findElementAt(offset);
if (!(problemElement instanceof PsiWhiteSpace) && !(problem.myCode.startsWith("E3"))) {
final PsiElement elementAfter = file.findElementAt(offset + 1);