use of org.python.pydev.core.IPythonNature in project Pydev by fabioz.
the class PySetNextTarget method setNextToLine.
@Override
public boolean setNextToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException {
// System.out.println("Run to line:"+target);
PyStackFrame stack = null;
if (target instanceof PyStackFrame) {
stack = (PyStackFrame) target;
target = stack.getThread();
}
if (!(part instanceof PyEdit)) {
return false;
}
PyEdit pyEdit = (PyEdit) part;
SimpleNode ast = pyEdit.getAST();
if (ast == null) {
IDocument doc = pyEdit.getDocument();
SourceModule sourceModule;
IPythonNature nature = null;
try {
nature = pyEdit.getPythonNature();
} catch (MisconfigurationException e) {
// Let's try to find a suitable nature
File editorFile = pyEdit.getEditorFile();
if (editorFile == null || !editorFile.exists()) {
Log.log(e);
return false;
}
nature = InterpreterManagersAPI.getInfoForFile(editorFile).o1;
}
if (nature == null) {
Log.log("Unable to determine nature!");
return false;
}
try {
sourceModule = AbstractModule.createModuleFromDoc("", pyEdit.getEditorFile(), doc, nature, true);
} catch (MisconfigurationException e) {
Log.log(e);
return false;
}
ast = sourceModule.getAst();
}
if (ast == null) {
Log.log("Cannot determine context to run to.");
return false;
}
if (target instanceof PyThread && selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
PyThread pyThread = (PyThread) target;
if (!pyThread.isPydevThread()) {
int sourceLine = stack.getLineNumber();
int targetLine = textSelection.getStartLine();
if (!NodeUtils.isValidContextForSetNext(ast, sourceLine, targetLine)) {
return false;
}
String functionName = NodeUtils.getContextName(targetLine, ast);
if (functionName == null) {
// global context
functionName = "";
} else {
functionName = FullRepIterable.getLastPart(functionName).trim();
}
pyThread.setNextStatement(targetLine + 1, functionName);
return true;
}
}
return true;
}
use of org.python.pydev.core.IPythonNature in project Pydev by fabioz.
the class PyBreakpoint method getPythonNature.
/**
* @return The nature to be used for this breakpoint or null if it cannot be determined.
*/
private IPythonNature getPythonNature() {
IMarker marker = getMarker();
IPythonNature nature = PythonNature.getPythonNature(marker.getResource());
if (nature == null) {
try {
String externalPath = (String) marker.getAttribute(PyBreakpoint.PY_BREAK_EXTERNAL_PATH_ID);
if (externalPath != null) {
Tuple<IPythonNature, String> infoForFile = InterpreterManagersAPI.getInfoForFile(new File(externalPath));
if (infoForFile != null) {
nature = infoForFile.o1;
}
}
} catch (CoreException e) {
throw new RuntimeException(e);
}
}
return nature;
}
use of org.python.pydev.core.IPythonNature in project Pydev by fabioz.
the class PyGlobalsBrowser method getFromSystemManager.
/**
* @param selectedText the text that should be selected in the beginning (may be null)
*/
private void getFromSystemManager(String selectedText) {
// is null
File editorFile = getPyEdit().getEditorFile();
Tuple<IPythonNature, String> infoForFile;
if (editorFile != null) {
infoForFile = InterpreterManagersAPI.getInfoForFile(editorFile);
} else {
infoForFile = null;
}
if (infoForFile != null) {
IPythonNature systemPythonNature = infoForFile.o1;
if (systemPythonNature == null) {
getFromWorkspace(selectedText);
return;
}
IInterpreterManager manager = infoForFile.o1.getRelatedInterpreterManager();
getFromManagerAndRelatedNatures(selectedText, manager);
} else {
getFromWorkspace(selectedText);
}
}
use of org.python.pydev.core.IPythonNature in project Pydev by fabioz.
the class PyGlobalsBrowser method run.
@Override
public void run(IAction action) {
IPythonNature pythonNature;
try {
pythonNature = getPyEdit().getPythonNature();
} catch (MisconfigurationException e1) {
handle(e1);
return;
}
PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(this.getPyEdit());
String selectedText;
try {
selectedText = ps.getSelectedText();
} catch (BadLocationException e1) {
selectedText = null;
}
if (selectedText == null || selectedText.length() == 0) {
try {
selectedText = ps.getCurrToken().o1;
} catch (BadLocationException e) {
// ignore
}
}
if (pythonNature != null) {
IInterpreterManager manager = pythonNature.getRelatedInterpreterManager();
getFromManagerAndRelatedNatures(selectedText, manager);
} else {
getFromSystemManager(selectedText);
}
}
use of org.python.pydev.core.IPythonNature in project Pydev by fabioz.
the class PyGlobalsBrowser method getFromManagerAndRelatedNatures.
/**
* Gets it using all the natures that match a given interpreter manager.
* @throws MisconfigurationException
*/
private static void getFromManagerAndRelatedNatures(String selectedText, IInterpreterManager useManager) {
AbstractAdditionalTokensInfo additionalSystemInfo;
try {
additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(useManager, useManager.getDefaultInterpreterInfo(true).getExecutableOrJar());
} catch (MisconfigurationException e) {
MessageDialog.openError(EditorUtils.getShell(), "Error", "Additional info is not available (default interpreter not configured).");
handle(e);
return;
}
List<AbstractAdditionalTokensInfo> additionalInfo = new ArrayList<AbstractAdditionalTokensInfo>();
additionalInfo.add(additionalSystemInfo);
List<IPythonNature> natures = PythonNature.getPythonNaturesRelatedTo(useManager.getInterpreterType());
for (IPythonNature nature : natures) {
AbstractAdditionalDependencyInfo info;
try {
info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
if (info != null) {
additionalInfo.add(info);
}
} catch (MisconfigurationException e) {
// just go on to the next nature if one is not properly configured.
handle(e);
}
}
doSelect(natures, additionalInfo, selectedText);
}
Aggregations