Skip to content

Commit

Permalink
Land #627: Don't highlight resolved callable if in a different file
Browse files Browse the repository at this point in the history
  • Loading branch information
KronicDeth committed Feb 24, 2017
2 parents 3d8d970 + 5eda5fe commit 610853a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion intellij-elixir.iml
Expand Up @@ -14,7 +14,7 @@
<excludeFolder url="file://$MODULE_DIR$/dependencies" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="jdk" jdkName="IntelliJ IDEA Community Edition IC-141.3056.4" jdkType="IDEA JDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
Expand Down
15 changes: 14 additions & 1 deletion src/org/elixir_lang/annonator/Callable.java
Expand Up @@ -6,8 +6,10 @@
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.util.containers.ContainerUtil;
import org.elixir_lang.ElixirSyntaxHighlighter;
Expand Down Expand Up @@ -166,7 +168,9 @@ private void highlight(@NotNull Call referrer,
highlight(referrer, rangeInReferrer, annotationHolder, referrerTextAttributesKey);
}

if (resolvedTextAttributesKey != null) {
/* Annotations can only be applied to the single, active file, which belongs to the referrer. The resolved
may be outside the file if it is a cross-file function or macro usage */
if (resolvedTextAttributesKey != null && sameFile(referrer, resolved)) {
highlight(resolved, annotationHolder, resolvedTextAttributesKey);
}
}
Expand Down Expand Up @@ -209,4 +213,13 @@ private void highlight(@NotNull final TextRange textRange,
EditorColorsManager.getInstance().getGlobalScheme().getAttributes(textAttributesKey)
);
}

private boolean sameFile(@NotNull PsiElement referrer, @NotNull PsiElement resolved) {
@NotNull PsiFile referrerPsiFile = referrer.getContainingFile();
VirtualFile referrerVirtualFile = referrerPsiFile.getVirtualFile();
@NotNull PsiFile resolvedPsiFile = resolved.getContainingFile();
VirtualFile resolvedVirtualFile = resolvedPsiFile.getVirtualFile();

return Comparing.equal(referrerVirtualFile, resolvedVirtualFile);
}
}

0 comments on commit 610853a

Please sign in to comment.