mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -7,6 +7,7 @@ from pydevd_constants import * #@UnusedWildImport
|
||||
from types import * #@UnusedWildImport
|
||||
from code import compile_command
|
||||
from code import InteractiveInterpreter
|
||||
from console import pydevconsole
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
@@ -464,6 +465,9 @@ def consoleExec(thread_id, frame_id, expression):
|
||||
updated_globals.update(frame.f_globals)
|
||||
updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals
|
||||
|
||||
if pydevconsole.IPYTHON:
|
||||
return pydevconsole.exec_expression(expression, updated_globals, frame.f_locals)
|
||||
|
||||
interpreter = ConsoleWriter()
|
||||
|
||||
try:
|
||||
@@ -477,7 +481,8 @@ def consoleExec(thread_id, frame_id, expression):
|
||||
# Case 2
|
||||
return True
|
||||
|
||||
# Case 3
|
||||
#Case 3
|
||||
|
||||
try:
|
||||
Exec(code, updated_globals, frame.f_locals)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class PyConsoleProcessHandler extends PythonProcessHandler {
|
||||
protected void textAvailable(final String text, final Key attributes) {
|
||||
final String string = PyConsoleUtil.processPrompts(getConsole(), StringUtil.convertLineSeparators(text));
|
||||
|
||||
myConsoleView.printText(string, attributes);
|
||||
myConsoleView.print(string, attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@ import com.jetbrains.python.highlighting.PyHighlighter;
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
class ConsoleSourceHighlighter {
|
||||
class PyConsoleSourceHighlighter {
|
||||
private final Lexer myLexer;
|
||||
|
||||
private final EditorColorsScheme myScheme;
|
||||
@@ -21,7 +21,7 @@ class ConsoleSourceHighlighter {
|
||||
private int myLexerState;
|
||||
private PythonConsoleView myPythonConsoleView;
|
||||
|
||||
ConsoleSourceHighlighter(PythonConsoleView pythonConsoleView, EditorColorsScheme scheme, PyHighlighter pyHighlighter) {
|
||||
PyConsoleSourceHighlighter(PythonConsoleView pythonConsoleView, EditorColorsScheme scheme, PyHighlighter pyHighlighter) {
|
||||
myPythonConsoleView = pythonConsoleView;
|
||||
myScheme = scheme;
|
||||
myPyHighlighter = pyHighlighter;
|
||||
@@ -32,7 +32,7 @@ class ConsoleSourceHighlighter {
|
||||
myLexer.start(text, 0, text.length(), getLexerState());
|
||||
while (hasNext()) {
|
||||
Pair<String, ConsoleViewContentType> pair = next();
|
||||
myPythonConsoleView.print(pair.first, pair.second);
|
||||
myPythonConsoleView.printText(pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.jetbrains.python.console;
|
||||
|
||||
import com.intellij.execution.console.LanguageConsoleImpl;
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -10,12 +14,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author traff
|
||||
*/
|
||||
public class PyConsoleUtil {
|
||||
public static final String ORDINARY_PROMPT = ">>> ";
|
||||
public static final String INPUT_PROMPT = ">? ";
|
||||
public static final String INDENT_PROMPT = "... ";
|
||||
static final String HELP_PROMPT = "help> ";
|
||||
public static final String EXECUTING_PROMPT = "";
|
||||
|
||||
public static final String ORDINARY_PROMPT = ">>> ";
|
||||
public static final String INPUT_PROMPT = ">? ";
|
||||
public static final String INDENT_PROMPT = "... ";
|
||||
static final String HELP_PROMPT = "help> ";
|
||||
public static final String EXECUTING_PROMPT = "";
|
||||
|
||||
private static final String IPYTHON_PAGING_PROMPT = "---Return to continue, q to quit---";
|
||||
|
||||
static final String[] PROMPTS = new String[]{
|
||||
@@ -26,6 +30,7 @@ public class PyConsoleUtil {
|
||||
};
|
||||
public static final String DOUBLE_QUOTE_MULTILINE = "\"\"\"";
|
||||
public static final String SINGLE_QUOTE_MULTILINE = "'''";
|
||||
static final Key<Boolean> IPYTHON = Key.create("ipython");
|
||||
|
||||
private PyConsoleUtil() {
|
||||
}
|
||||
@@ -89,16 +94,27 @@ public class PyConsoleUtil {
|
||||
return isMultilineStarts(line, DOUBLE_QUOTE_MULTILINE);
|
||||
}
|
||||
|
||||
public static boolean detectIPythonImported(@NotNull String text, final ConsoleViewContentType outputType) {
|
||||
return text.contains("PyDev console: using IPython 0.1") && outputType == ConsoleViewContentType.ERROR_OUTPUT;
|
||||
}
|
||||
|
||||
public static boolean detectSourcePrinting(@NotNull String text) {
|
||||
return text.contains("Source:");
|
||||
}
|
||||
|
||||
public static boolean detectIPythonStart(@NotNull String text) {
|
||||
return text.contains("<--<ipython_output_starts>-->");
|
||||
return text.contains("IPython-->");
|
||||
}
|
||||
|
||||
public static boolean detectIPythonEnd(@NotNull String text) {
|
||||
return text.contains("<--<ipython_output_ends>-->");
|
||||
return text.contains("<--IPython");
|
||||
}
|
||||
|
||||
public static boolean isIPythonDetected(VirtualFile file) {
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
Boolean detected = file.getUserData(IPYTHON);
|
||||
return detected != null && detected.booleanValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,9 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
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.net.NetUtils;
|
||||
@@ -42,6 +44,7 @@ import com.jetbrains.python.PythonHelpersLocator;
|
||||
import com.jetbrains.python.console.completion.PydevConsoleElement;
|
||||
import com.jetbrains.python.console.pydev.ConsoleCommunication;
|
||||
import com.jetbrains.python.console.pydev.PydevConsoleCommunication;
|
||||
import com.jetbrains.python.psi.resolve.ResolveImportUtil;
|
||||
import com.jetbrains.python.run.PythonCommandLineState;
|
||||
import com.jetbrains.python.run.PythonTracebackFilter;
|
||||
import com.jetbrains.python.sdk.PythonSdkFlavor;
|
||||
@@ -241,7 +244,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
myProcessHandler.addProcessListener(new ProcessAdapter() {
|
||||
@Override
|
||||
public void onTextAvailable(ProcessEvent event, Key outputType) {
|
||||
consoleView.printText(event.getText(), outputType);
|
||||
consoleView.print(event.getText(), outputType);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -258,7 +261,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
});
|
||||
}
|
||||
else {
|
||||
getConsoleView().printText("Couldn't connect to console process.", ProcessOutputTypes.STDERR);
|
||||
getConsoleView().print("Couldn't connect to console process.", ProcessOutputTypes.STDERR);
|
||||
myProcessHandler.destroyProcess();
|
||||
finishConsole();
|
||||
}
|
||||
@@ -269,7 +272,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
if (myPydevConsoleCommunication.isExecuting()) {
|
||||
getConsoleView().printText("^C", ProcessOutputTypes.SYSTEM);
|
||||
getConsoleView().print("^C", ProcessOutputTypes.SYSTEM);
|
||||
}
|
||||
myPydevConsoleCommunication.interrupt();
|
||||
}
|
||||
@@ -417,18 +420,24 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
return file.getName().contains("Python Console");
|
||||
}
|
||||
|
||||
public static boolean isInPydevConsole(final FileElement element) {
|
||||
public static boolean isIPythonConsole(final FileElement element) {
|
||||
//noinspection ConstantConditions
|
||||
if (element.getPsi() == null || element.getPsi().getContainingFile() == null) {
|
||||
return false;
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
if ("Python Console".equals(element.getPsi().getContainingFile().getName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
VirtualFile file = getConsoleFile(element.getPsi().getContainingFile());
|
||||
|
||||
return PyConsoleUtil.isIPythonDetected(file);
|
||||
}
|
||||
|
||||
private static VirtualFile getConsoleFile(PsiFile psiFile) {
|
||||
VirtualFile file = psiFile.getViewProvider().getVirtualFile();
|
||||
if (file instanceof LightVirtualFile) {
|
||||
file = ((LightVirtualFile)file).getOriginalFile();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ConsoleCommunication getConsoleCommunication(final PsiElement element) {
|
||||
|
||||
@@ -33,11 +33,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author traff
|
||||
*/
|
||||
public class PythonConsoleView extends LanguageConsoleViewImpl implements PyCodeExecutor {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(PythonConsoleView.class);
|
||||
|
||||
private Project myProject;
|
||||
private PydevConsoleExecuteActionHandler myExecuteActionHandler;
|
||||
private ConsoleSourceHighlighter mySourceHighlighter;
|
||||
private PyConsoleSourceHighlighter mySourceHighlighter;
|
||||
private boolean myIsIPythonOutput = false;
|
||||
private PyHighlighter myPyHighlighter;
|
||||
private EditorColorsScheme myScheme;
|
||||
@@ -50,7 +51,8 @@ public class PythonConsoleView extends LanguageConsoleViewImpl implements PyCode
|
||||
setUpdateFoldingsEnabled(false);
|
||||
myProject = project;
|
||||
//noinspection ConstantConditions
|
||||
myPyHighlighter = new PyHighlighter(sdk != null && sdk.getVersionString() != null ? LanguageLevel.fromPythonVersion(sdk.getVersionString()) : LanguageLevel.getDefault());
|
||||
myPyHighlighter = new PyHighlighter(
|
||||
sdk != null && sdk.getVersionString() != null ? LanguageLevel.fromPythonVersion(sdk.getVersionString()) : LanguageLevel.getDefault());
|
||||
myScheme = getPythonLanguageConsole().getConsoleEditor().getColorsScheme();
|
||||
}
|
||||
|
||||
@@ -70,6 +72,10 @@ public class PythonConsoleView extends LanguageConsoleViewImpl implements PyCode
|
||||
return ((PythonLanguageConsole)myConsole);
|
||||
}
|
||||
|
||||
public LanguageConsoleImpl getLanguageConsole() {
|
||||
return myConsole;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeCode(final @NotNull String code) {
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(null, "Executing code in console...", false) {
|
||||
@@ -108,11 +114,20 @@ public class PythonConsoleView extends LanguageConsoleViewImpl implements PyCode
|
||||
}
|
||||
|
||||
public void executeStatement(@NotNull String statement, @NotNull final Key attributes) {
|
||||
printText(statement, attributes);
|
||||
print(statement, outputTypeForAttributes(attributes));
|
||||
myExecuteActionHandler.processLine(statement, true);
|
||||
}
|
||||
|
||||
public void printText(String text, final Key attributes) {
|
||||
public void print(String text, @NotNull final Key attributes) {
|
||||
print(text, outputTypeForAttributes(attributes));
|
||||
}
|
||||
|
||||
public void printText(String text, final ConsoleViewContentType outputType) {
|
||||
super.print(text, outputType);
|
||||
}
|
||||
|
||||
public void print(String text, final ConsoleViewContentType outputType) {
|
||||
detectIPython(text, outputType);
|
||||
if (PyConsoleUtil.detectIPythonEnd(text)) {
|
||||
myIsIPythonOutput = false;
|
||||
mySourceHighlighter = null;
|
||||
@@ -121,17 +136,17 @@ public class PythonConsoleView extends LanguageConsoleViewImpl implements PyCode
|
||||
myIsIPythonOutput = true;
|
||||
}
|
||||
else {
|
||||
if (mySourceHighlighter == null || attributes == ProcessOutputTypes.STDERR) {
|
||||
if (mySourceHighlighter == null || outputType == ConsoleViewContentType.ERROR_OUTPUT) {
|
||||
if (myHyperlink) {
|
||||
printHyperlink(text, attributes);
|
||||
printHyperlink(text, outputType);
|
||||
}
|
||||
else {
|
||||
//Print text normally with converted attributes
|
||||
print(text, outputTypeForAttributes(attributes));
|
||||
super.print(text, outputType);
|
||||
}
|
||||
myHyperlink = detectHyperlink(text, attributes);
|
||||
myHyperlink = detectHyperlink(text);
|
||||
if (mySourceHighlighter == null && myIsIPythonOutput && PyConsoleUtil.detectSourcePrinting(text)) {
|
||||
mySourceHighlighter = new ConsoleSourceHighlighter(this, myScheme, myPyHighlighter);
|
||||
mySourceHighlighter = new PyConsoleSourceHighlighter(this, myScheme, myPyHighlighter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -145,11 +160,24 @@ public class PythonConsoleView extends LanguageConsoleViewImpl implements PyCode
|
||||
}
|
||||
}
|
||||
|
||||
private boolean detectHyperlink(@NotNull String text, @NotNull Key attributes) {
|
||||
public void detectIPython(String text, final ConsoleViewContentType outputType) {
|
||||
if (PyConsoleUtil.detectIPythonImported(text, outputType)) {
|
||||
setIPythonDetected();
|
||||
}
|
||||
}
|
||||
|
||||
private void setIPythonDetected() {
|
||||
VirtualFile file = getConsole().getFile().getVirtualFile();
|
||||
if (file != null) {
|
||||
file.putUserData(PyConsoleUtil.IPYTHON, Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean detectHyperlink(@NotNull String text) {
|
||||
return myIsIPythonOutput && text.startsWith("File:");
|
||||
}
|
||||
|
||||
private void printHyperlink(@NotNull String text, @NotNull Key attributes) {
|
||||
private void printHyperlink(@NotNull String text, @NotNull ConsoleViewContentType contentType) {
|
||||
if (!StringUtil.isEmpty(text)) {
|
||||
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(text.trim());
|
||||
|
||||
@@ -159,7 +187,7 @@ public class PythonConsoleView extends LanguageConsoleViewImpl implements PyCode
|
||||
printHyperlink(text, hyperlink);
|
||||
}
|
||||
else {
|
||||
print(text, outputTypeForAttributes(attributes));
|
||||
super.print(text, contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PythonDebugLanguageConsoleView extends JPanel implements ConsoleVie
|
||||
|
||||
add(myTextConsole.getComponent(), TEXT_CONSOLE_PANEL);
|
||||
add(myPydevConsoleView.getComponent(), PYDEV_CONSOLE_PANEL);
|
||||
|
||||
|
||||
showDebugConsole(PyConsoleOptionsProvider.getInstance(project).isShowDebugConsoleByDefault());
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class PythonDebugLanguageConsoleView extends JPanel implements ConsoleVie
|
||||
}
|
||||
|
||||
private static PythonConsoleView createConsoleView(Project project, Sdk sdk) {
|
||||
return new PythonConsoleView(project, "", sdk);
|
||||
return new PythonConsoleView(project, "Python Console", sdk);
|
||||
}
|
||||
|
||||
private void doShowConsole(String type) {
|
||||
@@ -95,8 +95,9 @@ public class PythonDebugLanguageConsoleView extends JPanel implements ConsoleVie
|
||||
}
|
||||
|
||||
public ConsoleViewImpl getTextConsole() {
|
||||
if (myTextConsole instanceof ConsoleViewImpl)
|
||||
if (myTextConsole instanceof ConsoleViewImpl) {
|
||||
return (ConsoleViewImpl)myTextConsole;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -206,8 +207,9 @@ public class PythonDebugLanguageConsoleView extends JPanel implements ConsoleVie
|
||||
@Override
|
||||
public void addChangeListener(ChangeListener listener, Disposable parent) {
|
||||
myPydevConsoleView.addChangeListener(listener, parent);
|
||||
if (myTextConsole instanceof ObservableConsoleView)
|
||||
if (myTextConsole instanceof ObservableConsoleView) {
|
||||
((ObservableConsoleView)myTextConsole).addChangeListener(listener, parent);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ShowDebugConsoleAction extends ToggleAction implements DumbAware {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.jetbrains.python.console.parsing;
|
||||
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.console.PyConsoleUtil;
|
||||
import com.jetbrains.python.parsing.ExpressionParsing;
|
||||
import com.jetbrains.python.parsing.ParsingContext;
|
||||
import com.jetbrains.python.parsing.ParsingScope;
|
||||
@@ -17,7 +21,10 @@ public class PyConsoleParsingContext extends ParsingContext {
|
||||
private final StatementParsing stmtParser;
|
||||
private final ExpressionParsing expressionParser;
|
||||
|
||||
public PyConsoleParsingContext(final PsiBuilder builder, LanguageLevel languageLevel, StatementParsing.FUTURE futureFlag) {
|
||||
public PyConsoleParsingContext(final PsiBuilder builder,
|
||||
LanguageLevel languageLevel,
|
||||
StatementParsing.FUTURE futureFlag,
|
||||
PsiElement psi) {
|
||||
super(builder, languageLevel, futureFlag);
|
||||
stmtParser = new ConsoleStatementParsing(this, futureFlag);
|
||||
expressionParser = new ConsoleExpressionParsing(this);
|
||||
@@ -34,6 +41,7 @@ public class PyConsoleParsingContext extends ParsingContext {
|
||||
}
|
||||
|
||||
private static class ConsoleStatementParsing extends StatementParsing {
|
||||
|
||||
protected ConsoleStatementParsing(ParsingContext context, @Nullable FUTURE futureFlag) {
|
||||
super(context, futureFlag);
|
||||
}
|
||||
@@ -69,7 +77,6 @@ public class PyConsoleParsingContext extends ParsingContext {
|
||||
}
|
||||
|
||||
private static class ConsoleExpressionParsing extends ExpressionParsing {
|
||||
|
||||
public ConsoleExpressionParsing(ParsingContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PyFileElementType extends IStubFileElementType<PyFileStub> {
|
||||
public ASTNode parseContents(ASTNode chameleon) {
|
||||
final FileElement node = (FileElement)chameleon;
|
||||
final LanguageLevel languageLevel = getLanguageLevel(node.getPsi());
|
||||
if (PydevConsoleRunner.isInPydevConsole(node)) {
|
||||
if (PydevConsoleRunner.isIPythonConsole(node)) {
|
||||
return parseConsoleCode(node, languageLevel);
|
||||
}
|
||||
final PsiElement psi = node.getPsi();
|
||||
@@ -85,7 +85,7 @@ public class PyFileElementType extends IStubFileElementType<PyFileStub> {
|
||||
final PyParser parser = new PyParser() {
|
||||
@Override
|
||||
protected ParsingContext createParsingContext(PsiBuilder builder, LanguageLevel languageLevel, StatementParsing.FUTURE futureFlag) {
|
||||
return new PyConsoleParsingContext(builder, languageLevel, futureFlag);
|
||||
return new PyConsoleParsingContext(builder, languageLevel, futureFlag, psi);
|
||||
}
|
||||
};
|
||||
return parser.parse(this, builder).getFirstChildNode();
|
||||
|
||||
Reference in New Issue
Block a user