Skip to content

Commit b3153e2

Browse files
committed
Highlight exit points of a function when cursor is on func
1 parent b3ac9ae commit b3153e2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/com/goide/highlighting/GoHighlightExitPointsHandlerFactory.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ protected void selectTargets(List<PsiElement> targets, @NotNull Consumer<List<Ps
6363

6464
@Override
6565
public void computeUsages(List<PsiElement> targets) {
66+
if (myTarget instanceof LeafPsiElement && ((LeafPsiElement)myTarget).getElementType() == GoTypes.FUNC) {
67+
addOccurrence(myTarget);
68+
}
6669
new GoRecursiveVisitor() {
6770
@Override
6871
public void visitFunctionLit(@NotNull GoFunctionLit literal) {
@@ -85,12 +88,22 @@ public void visitCallExpr(@NotNull GoCallExpr o) {
8588
public static MyHandler createForElement(@NotNull Editor editor, PsiFile file, PsiElement element) {
8689
GoTypeOwner function = PsiTreeUtil.getParentOfType(element, GoFunctionLit.class, GoFunctionOrMethodDeclaration.class);
8790
if (function == null) return null;
88-
if (element instanceof LeafPsiElement && ((LeafPsiElement)element).getElementType() == GoTypes.RETURN || isPanicCall(element)) {
91+
if (shouldCreateMyHandler(element)) {
8992
return new MyHandler(editor, file, element, function);
9093
}
9194
return null;
9295
}
9396

97+
private static boolean shouldCreateMyHandler(PsiElement element) {
98+
if (element instanceof LeafPsiElement) {
99+
LeafPsiElement leaf = (LeafPsiElement)element;
100+
return leaf.getElementType() == GoTypes.RETURN || leaf.getElementType() == GoTypes.FUNC || isPanicCall(leaf);
101+
}
102+
else {
103+
return false;
104+
}
105+
}
106+
94107
private static boolean isPanicCall(@NotNull PsiElement e) {
95108
PsiElement parent = e.getParent();
96109
if (parent instanceof GoReferenceExpression) {

0 commit comments

Comments
 (0)