use of org.jetbrains.plugins.ipnb.psi.IpnbPyFragment in project intellij-community by JetBrains.
the class IpnbPep8ProblemSuppressor method isProblemSuppressed.
@Override
public boolean isProblemSuppressed(@NotNull Pep8ExternalAnnotator.Problem problem, @NotNull PsiFile file, @Nullable PsiElement targetElement) {
if (file instanceof IpnbPyFragment) {
// Ignore warnings about missing new line at the end of file
if (problem.getCode().equals("W292")) {
return true;
}
// Ignore warnings about imports not at the top of file if there are magic commands before
if (problem.getCode().equals("E402") && targetElement != null) {
final PyImportStatementBase importStatement = PsiTreeUtil.getParentOfType(targetElement, PyImportStatementBase.class);
if (importStatement != null && importStatement.getParent() == file) {
boolean containsMagicCommandsBefore = false;
PsiElement prev = PyPsiUtils.getPrevNonCommentSibling(importStatement, true);
while (prev != null) {
if (prev instanceof PyEmptyExpression && prev.getText().startsWith("%")) {
containsMagicCommandsBefore = true;
} else if (!(isModuleLevelDocstring(prev, (PyFile) file) || prev instanceof PyImportStatementBase)) {
return false;
}
prev = PyPsiUtils.getPrevNonCommentSibling(prev, true);
}
return containsMagicCommandsBefore;
}
}
}
return false;
}
use of org.jetbrains.plugins.ipnb.psi.IpnbPyFragment in project intellij-community by JetBrains.
the class IpnbEditorUtil method createPythonCodeEditor.
public static Editor createPythonCodeEditor(@NotNull final Project project, @NotNull final IpnbCodeSourcePanel codeSourcePanel) {
final EditorFactory editorFactory = EditorFactory.getInstance();
assert editorFactory != null;
final String text = codeSourcePanel.getCell().getSourceAsString().trim();
final Module module = ProjectRootManagerEx.getInstanceEx(project).getFileIndex().getModuleForFile(codeSourcePanel.getIpnbCodePanel().getFileEditor().getVirtualFile());
final IpnbPyFragment fragment = new IpnbPyFragment(project, text, true, codeSourcePanel);
fragment.putUserData(ModuleUtilCore.KEY_MODULE, module);
final Document document = PsiDocumentManager.getInstance(project).getDocument(fragment);
assert document != null;
EditorEx editor = (EditorEx) editorFactory.createEditor(document, project, fragment.getVirtualFile(), false);
setupEditor(editor);
return editor;
}
Aggregations