@@ -71,7 +71,7 @@ public static boolean isBuiltInSymbol(PsiElement element) {
7171 * @return List of symbols which are assigned.
7272 */
7373 @ Nullable
74- public static List <Symbol > getAssignmentSymbols (PsiElement element ) {
74+ static List <Symbol > getAssignmentSymbols (PsiElement element ) {
7575 PsiElement firstChild = element .getFirstChild ();
7676 final List <Symbol > assignees = Lists .newArrayList ();
7777
@@ -525,6 +525,48 @@ public static List<Symbol> getLocalCompileLikeVariables(FunctionCall element) {
525525 return localVariables ;
526526 }
527527
528+
529+ @ Nullable
530+ public static SymbolResolveResult resolveLocalCompileLikeVariables (Symbol myStartElement , FunctionCall functionCall , ResolveState state ) {
531+
532+ final PsiElement lastParent = state .get (SymbolResolveHint .LAST_PARENT );
533+ final List <PsiElement > arguments = getArguments (functionCall );
534+ if (arguments .size () < 1 ) {
535+ return null ;
536+ }
537+
538+ final PsiElement firstArgument = arguments .get (0 );
539+ boolean inDef = firstArgument .equals (lastParent );
540+
541+
542+ final MScope scopingConstruct = functionCall .getScopingConstruct ();
543+ if (firstArgument instanceof Symbol ) {
544+ if (((Symbol ) firstArgument ).getFullSymbolName ().equals (myStartElement .getFullSymbolName ())) {
545+ return new SymbolResolveResult (firstArgument , scopingConstruct , true );
546+ }
547+ } else if (firstArgument instanceof de .halirutan .mathematica .lang .psi .api .lists .List ) {
548+ final PsiElement [] children = firstArgument .getChildren ();
549+ for (PsiElement child : children ) {
550+ if (child instanceof de .halirutan .mathematica .lang .psi .api .lists .List ) {
551+ child = child .getFirstChild ();
552+ }
553+ if (child instanceof Symbol ) {
554+ if (inDef ) {
555+ if (child .equals (myStartElement )) {
556+ return new SymbolResolveResult (child , scopingConstruct , true );
557+ }
558+ } else {
559+ if (((Symbol ) child ).getFullSymbolName ().equals (myStartElement .getFullSymbolName ())) {
560+ return new SymbolResolveResult (child , scopingConstruct , true );
561+ }
562+ }
563+ }
564+ }
565+ }
566+ return null ;
567+ }
568+
569+
528570 /**
529571 * This extracts the local defined argument for a <code>Limit[Sin[x]/x, x-> 0]</code> call. Note that the returned
530572 * list has always only one element since <code>Limit</code> always uses only one variable.
@@ -578,7 +620,7 @@ public static PsiElement getFirstListElement(@Nullable PsiElement list) {
578620 * @return List of arguments
579621 */
580622 @ NotNull
581- public static List <PsiElement > getArguments (@ Nullable PsiElement func ) {
623+ static List <PsiElement > getArguments (@ Nullable PsiElement func ) {
582624 List <PsiElement > allArguments = Lists .newLinkedList ();
583625 if (!(func instanceof FunctionCall )) {
584626 return allArguments ;
@@ -636,7 +678,7 @@ public static String getBeginContext(@NotNull PsiElement element) {
636678 * @return context string or null if it could not be extracted
637679 */
638680 @ Nullable
639- public static String getContext (@ NotNull PsiElement element , final boolean beginPackageOnly ) {
681+ private static String getContext (@ NotNull PsiElement element , final boolean beginPackageOnly ) {
640682 if (element instanceof FunctionCall ) {
641683 final FunctionCall functionCall = (FunctionCall ) element ;
642684 if (functionCall .matchesHead ("BeginPackage" ) || (!beginPackageOnly && functionCall .matchesHead ("Begin" ))) {
0 commit comments