Skip to content

Commit

Permalink
fix global type quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Sep 7, 2015
1 parent 2f9b170 commit 1134dbb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/com/goide/refactor/GoRefactoringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.goide.psi.GoBlock;
import com.goide.psi.GoStatement;
import com.goide.psi.impl.GoPsiImplUtil;
import com.intellij.codeInsight.PsiEquivalenceUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiRecursiveElementVisitor;
Expand Down Expand Up @@ -60,10 +61,11 @@ public static PsiElement findLocalAnchor(@NotNull List<PsiElement> occurrences)

@Nullable
public static PsiElement findAnchor(@NotNull List<PsiElement> occurrences, @Nullable PsiElement context) {
PsiElement statement = PsiTreeUtil.getNonStrictParentOfType(ContainerUtil.getFirstItem(occurrences), GoStatement.class);
PsiElement first = ContainerUtil.getFirstItem(occurrences);
PsiElement statement = PsiTreeUtil.getNonStrictParentOfType(first, GoStatement.class);
while (statement != null && statement.getParent() != context) {
statement = statement.getParent();
}
return statement;
return statement == null ? GoPsiImplUtil.getTopLevelDeclaration(first) : statement;
}
}
5 changes: 5 additions & 0 deletions testData/quickfixes/create-type/global-after.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package foo

type A<caret>

type ServerFunc func(params A) (error)
3 changes: 3 additions & 0 deletions testData/quickfixes/create-type/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package foo

type ServerFunc func(params A<caret>) (error)
1 change: 1 addition & 0 deletions tests/com/goide/quickfix/GoCreateTypeQuickFixTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ protected String getBasePath() {
}

public void testSimple() { doTest(CREATE_TYPE_A); }
public void testGlobal() { doTest(CREATE_TYPE_A); }
public void testProhibited() { doTestNoFix(CREATE_TYPE_A); }
}

2 comments on commit 1134dbb

@ignatov
Copy link
Contributor Author

@ignatov ignatov commented on 1134dbb Sep 7, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zolotov Please review

@zolotov
Copy link
Contributor

@zolotov zolotov commented on 1134dbb Sep 7, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

Please sign in to comment.