Ability to debug python scratch files. Scratch enabled in PyCharm (PY-3151).

This commit is contained in:
Dmitry Trofimov
2015-03-09 20:39:44 +01:00
parent d455e419fb
commit 27290f9102
2 changed files with 15 additions and 5 deletions
@@ -90,10 +90,7 @@ public class PyCharmInitialConfigurator {
});
}
if (!propertiesComponent.getBoolean("PyCharm.NoScratch", false)) {
propertiesComponent.setValue("PyCharm.NoScratch", "true");
Registry.get("ide.scratch.enabled").setValue(false); //disable scratch till it is ready
}
Registry.get("ide.scratch.enabled").setValue(true);
}
private static void showInitialConfigurationDialog() {
@@ -15,6 +15,9 @@
*/
package com.jetbrains.python.debugger;
import com.intellij.ide.scratch.RootType;
import com.intellij.ide.scratch.ScratchFileService;
import com.intellij.ide.scratch.ScratchFileType;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
@@ -45,7 +48,7 @@ public class PyLineBreakpointType extends XLineBreakpointTypeBase {
final Ref<Boolean> stoppable = Ref.create(false);
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
if (file.getFileType() == PythonFileType.INSTANCE) {
if (file.getFileType() == PythonFileType.INSTANCE || isPythonScratch(project, file)) {
XDebuggerUtil.getInstance().iterateLine(project, document, line, new Processor<PsiElement>() {
@Override
public boolean process(PsiElement psiElement) {
@@ -67,6 +70,16 @@ public class PyLineBreakpointType extends XLineBreakpointTypeBase {
return stoppable.get();
}
private static boolean isPythonScratch(Project project, VirtualFile file) {
if (file.getFileType() == ScratchFileType.INSTANCE) {
RootType type = ScratchFileService.getInstance().getRootType(file);
return type != null && type.substituteLanguage(project, file) == PythonFileType.INSTANCE.getLanguage();
}
else {
return false;
}
}
private static boolean notStoppableElementType(IElementType elementType) {
return elementType == PyTokenTypes.TRIPLE_QUOTED_STRING ||
elementType == PyTokenTypes.SINGLE_QUOTED_STRING ||