mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cross-cell resolve to function declaration
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package org.jetbrains.plugins.ipnb.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.impl.stubs.PyFunctionElementType;
|
||||
import com.jetbrains.python.psi.stubs.PyFunctionStub;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IpnbFunctionElementType extends PyFunctionElementType {
|
||||
public IpnbFunctionElementType() {
|
||||
super("IPNB_FUNCTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement createElement(@NotNull ASTNode node) {
|
||||
return new IpnbPyFunction(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PyFunction createPsi(@NotNull PyFunctionStub stub) {
|
||||
return new IpnbPyFunction(stub);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStubElementType getStubElementType() {
|
||||
return IpnbPyTokenTypes.IPNB_FUNCTION;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.jetbrains.plugins.ipnb.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.python.psi.impl.PyFunctionImpl;
|
||||
import com.jetbrains.python.psi.stubs.PyFunctionStub;
|
||||
import org.jetbrains.plugins.ipnb.editor.IpnbFileEditor;
|
||||
import org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel;
|
||||
import org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel;
|
||||
import org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodeSourcePanel;
|
||||
|
||||
public class IpnbPyFunction extends PyFunctionImpl {
|
||||
|
||||
public IpnbPyFunction(ASTNode astNode) {
|
||||
super(astNode);
|
||||
}
|
||||
|
||||
public IpnbPyFunction(PyFunctionStub stub) {
|
||||
super(stub);
|
||||
}
|
||||
|
||||
public IpnbPyFunction(PyFunctionStub stub, IStubElementType nodeType) {
|
||||
super(stub, nodeType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void navigate(boolean requestFocus) {
|
||||
final IpnbCodeSourcePanel sourcePanel = ((IpnbPyFragment)getContainingFile()).getCodeSourcePanel();
|
||||
final Editor editor = sourcePanel.getEditor();
|
||||
|
||||
final IpnbCodePanel codePanel = sourcePanel.getIpnbCodePanel();
|
||||
final IpnbFileEditor fileEditor = codePanel.getFileEditor();
|
||||
final IpnbFilePanel filePanel = fileEditor.getIpnbFilePanel();
|
||||
codePanel.setEditing(true);
|
||||
filePanel.setSelectedCell(codePanel);
|
||||
super.navigate(false);
|
||||
UIUtil.requestFocus(editor.getContentComponent());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.parsing.ExpressionParsing;
|
||||
import com.jetbrains.python.parsing.FunctionParsing;
|
||||
import com.jetbrains.python.parsing.ParsingContext;
|
||||
import com.jetbrains.python.parsing.StatementParsing;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
@@ -12,6 +13,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class IpnbPyParsingContext extends ParsingContext {
|
||||
private final StatementParsing myStatementParser;
|
||||
private final ExpressionParsing myExpressionParser;
|
||||
private final FunctionParsing myFunctionParser;
|
||||
|
||||
public IpnbPyParsingContext(final PsiBuilder builder,
|
||||
LanguageLevel languageLevel,
|
||||
@@ -19,6 +21,7 @@ public class IpnbPyParsingContext extends ParsingContext {
|
||||
super(builder, languageLevel, futureFlag);
|
||||
myStatementParser = new IpnbPyStatementParsing(this, futureFlag);
|
||||
myExpressionParser = new IpnbPyExpressionParsing(this);
|
||||
myFunctionParser = new IpnbPyFunctionParsing(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,6 +34,11 @@ public class IpnbPyParsingContext extends ParsingContext {
|
||||
return myStatementParser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionParsing getFunctionParser() {
|
||||
return myFunctionParser;
|
||||
}
|
||||
|
||||
private static class IpnbPyExpressionParsing extends ExpressionParsing {
|
||||
public IpnbPyExpressionParsing(ParsingContext context) {
|
||||
super(context);
|
||||
@@ -68,4 +76,14 @@ public class IpnbPyParsingContext extends ParsingContext {
|
||||
}
|
||||
|
||||
}
|
||||
private static class IpnbPyFunctionParsing extends FunctionParsing {
|
||||
|
||||
public IpnbPyFunctionParsing(ParsingContext context) {
|
||||
super(context);
|
||||
}
|
||||
protected IElementType getFunctionType() {
|
||||
return IpnbPyTokenTypes.IPNB_FUNCTION;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,11 @@ public class IpnbPyTokenSetContributor extends PythonDialectsTokenSetContributor
|
||||
public TokenSet getReferenceExpressionTokens() {
|
||||
return IPNB_REFERENCE_EXPRESSIONS;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TokenSet getFunctionDeclarationTokens() {
|
||||
return TokenSet.create(IpnbPyTokenTypes.IPNB_FUNCTION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package org.jetbrains.plugins.ipnb.psi;
|
||||
|
||||
import com.jetbrains.python.psi.PyElementType;
|
||||
import com.jetbrains.python.psi.impl.stubs.PyFunctionElementType;
|
||||
|
||||
public class IpnbPyTokenTypes {
|
||||
public static final PyElementType IPNB_REFERENCE = new PyElementType("IPNB_REFERENCE", IpnbPyReferenceExpression.class);
|
||||
public static final PyElementType IPNB_TARGET = new PyElementType("IPNB_TARGET", IpnbPyTargetExpression.class);
|
||||
public static final PyFunctionElementType IPNB_FUNCTION = new IpnbFunctionElementType();
|
||||
|
||||
private IpnbPyTokenTypes() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user