Skip to content

Commit 1134dbb

Browse files
committed
fix global type quick fix
1 parent 2f9b170 commit 1134dbb

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/com/goide/refactor/GoRefactoringUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.goide.psi.GoBlock;
2020
import com.goide.psi.GoStatement;
21+
import com.goide.psi.impl.GoPsiImplUtil;
2122
import com.intellij.codeInsight.PsiEquivalenceUtil;
2223
import com.intellij.psi.PsiElement;
2324
import com.intellij.psi.PsiRecursiveElementVisitor;
@@ -60,10 +61,11 @@ public static PsiElement findLocalAnchor(@NotNull List<PsiElement> occurrences)
6061

6162
@Nullable
6263
public static PsiElement findAnchor(@NotNull List<PsiElement> occurrences, @Nullable PsiElement context) {
63-
PsiElement statement = PsiTreeUtil.getNonStrictParentOfType(ContainerUtil.getFirstItem(occurrences), GoStatement.class);
64+
PsiElement first = ContainerUtil.getFirstItem(occurrences);
65+
PsiElement statement = PsiTreeUtil.getNonStrictParentOfType(first, GoStatement.class);
6466
while (statement != null && statement.getParent() != context) {
6567
statement = statement.getParent();
6668
}
67-
return statement;
69+
return statement == null ? GoPsiImplUtil.getTopLevelDeclaration(first) : statement;
6870
}
6971
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package foo
2+
3+
type A<caret>
4+
5+
type ServerFunc func(params A) (error)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package foo
2+
3+
type ServerFunc func(params A<caret>) (error)

tests/com/goide/quickfix/GoCreateTypeQuickFixTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ protected String getBasePath() {
3333
}
3434

3535
public void testSimple() { doTest(CREATE_TYPE_A); }
36+
public void testGlobal() { doTest(CREATE_TYPE_A); }
3637
public void testProhibited() { doTestNoFix(CREATE_TYPE_A); }
3738
}

0 commit comments

Comments
 (0)