Search in sources :

Example 1 with PydevConsoleReference

use of com.jetbrains.python.console.completion.PydevConsoleReference in project intellij-community by JetBrains.

the class PyReferenceExpressionImpl method getReference.

@NotNull
@Override
public PsiPolyVariantReference getReference(@NotNull PyResolveContext context) {
    // Handle import reference
    final PsiElement importParent = PsiTreeUtil.getParentOfType(this, PyImportElement.class, PyFromImportStatement.class);
    if (importParent != null) {
        return PyImportReference.forElement(this, importParent, context);
    }
    final PyExpression qualifier = getQualifier();
    // Return special reference
    final ConsoleCommunication communication = getContainingFile().getCopyableUserData(PydevConsoleRunner.CONSOLE_KEY);
    if (communication != null) {
        final String prefix = qualifier == null ? "" : qualifier.getText() + ".";
        return new PydevConsoleReference(this, communication, prefix, context.allowRemote());
    }
    if (qualifier != null) {
        return new PyQualifiedReference(this, context);
    }
    return new PyReferenceImpl(this, context);
}
Also used : PydevConsoleReference(com.jetbrains.python.console.completion.PydevConsoleReference) PyQualifiedReference(com.jetbrains.python.psi.impl.references.PyQualifiedReference) ConsoleCommunication(com.jetbrains.python.console.pydev.ConsoleCommunication) PyReferenceImpl(com.jetbrains.python.psi.impl.references.PyReferenceImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PydevConsoleReference

use of com.jetbrains.python.console.completion.PydevConsoleReference in project intellij-community by JetBrains.

the class PydevDocumentationProvider method createDoc.

@Nullable
public static String createDoc(final PsiElement element, final PsiElement originalElement) {
    final PyReferenceExpression expression = PsiTreeUtil.getNonStrictParentOfType(originalElement, PyReferenceExpression.class);
    // Indicates that we are inside console, not a lookup element!
    if (expression == null) {
        return null;
    }
    PydevConsoleReference consoleRef = PyUtil.as(expression.getReference(), PydevConsoleReference.class);
    if (consoleRef == null) {
        //shouldn't really happen!
        return null;
    }
    PyElement documentationElement = consoleRef.getDocumentationElement();
    if (documentationElement == null) {
        return null;
    }
    return new PyDocumentationBuilder(documentationElement, null).build();
}
Also used : PydevConsoleReference(com.jetbrains.python.console.completion.PydevConsoleReference) PyDocumentationBuilder(com.jetbrains.python.documentation.PyDocumentationBuilder) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression) PyElement(com.jetbrains.python.psi.PyElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PydevConsoleReference (com.jetbrains.python.console.completion.PydevConsoleReference)2 ConsoleCommunication (com.jetbrains.python.console.pydev.ConsoleCommunication)1 PyDocumentationBuilder (com.jetbrains.python.documentation.PyDocumentationBuilder)1 PyElement (com.jetbrains.python.psi.PyElement)1 PyReferenceExpression (com.jetbrains.python.psi.PyReferenceExpression)1 PyQualifiedReference (com.jetbrains.python.psi.impl.references.PyQualifiedReference)1 PyReferenceImpl (com.jetbrains.python.psi.impl.references.PyReferenceImpl)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1