Skip to content

Commit 37f2393

Browse files
committed
[completion] wrong pointer type detection for short variable declaration, fix #2222
1 parent ace42f9 commit 37f2393

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/com/goide/GoDocumentationProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.intellij.psi.stubs.StubIndex;
4040
import com.intellij.psi.util.PsiTreeUtil;
4141
import com.intellij.util.Function;
42+
import com.intellij.util.ObjectUtils;
4243
import com.intellij.util.containers.ContainerUtil;
4344
import com.intellij.xml.util.XmlStringUtil;
4445
import org.jetbrains.annotations.NotNull;
@@ -222,7 +223,10 @@ else if (type instanceof GoArrayOrSliceType) {
222223
return replaceInnerTypes(type, contextImportPath, ((GoArrayOrSliceType)type).getType());
223224
}
224225
else if (type instanceof GoPointerType) {
225-
return replaceInnerTypes(type, contextImportPath, ((GoPointerType)type).getType());
226+
GoType inner = ((GoPointerType)type).getType();
227+
return inner instanceof GoSpecType
228+
? getTypePresentation(inner, contextImportPath)
229+
: replaceInnerTypes(type, contextImportPath, inner);
226230
}
227231
else if (type instanceof GoTypeList) {
228232
return "(" + replaceInnerTypes(type, contextImportPath, ((GoTypeList)type).getTypeList()) + ")";
@@ -273,7 +277,7 @@ private static String replaceInnerTypes(@NotNull GoType type, @Nullable String c
273277
private static String replaceInnerTypes(@NotNull GoType type, @Nullable String contextImportPath, @NotNull List<GoType> innerTypes) {
274278
StringBuilder result = new StringBuilder();
275279
String typeText = type.getText();
276-
int initialOffset = type.getTextRange().getStartOffset();
280+
int initialOffset = ObjectUtils.notNull(type.getTextRange(), TextRange.EMPTY_RANGE).getStartOffset();
277281
int lastStartOffset = type.getTextLength();
278282
ContainerUtil.sort(innerTypes, ELEMENT_BY_RANGE_COMPARATOR);
279283
for (int i = innerTypes.size() - 1; i >= 0; i--) {

src/com/goide/psi/impl/GoPsiImplUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ public static GoType getGoTypeInner(@NotNull final GoExpression o, @Nullable Res
329329
if (o instanceof GoUnaryExpr) {
330330
GoExpression e = ((GoUnaryExpr)o).getExpression();
331331
GoType type = e == null ? null : findBaseType(e.getGoType(context));
332+
if (type != null && ((GoUnaryExpr)o).getBitAnd() != null) return new LightPointerType(type);
332333
if (type instanceof GoChannelType && ((GoUnaryExpr)o).getSendChannel() != null) return ((GoChannelType)type).getType();
333334
if (type instanceof GoPointerType && ((GoUnaryExpr)o).getMul() != null) return ((GoPointerType)type).getType();
334335
return type;
@@ -640,6 +641,9 @@ else if (type instanceof GoSpecType) {
640641
@NotNull
641642
public static String getText(@Nullable GoType o) {
642643
if (o == null) return "";
644+
if (o instanceof GoPointerType && ((GoPointerType)o).getType() instanceof GoSpecType) {
645+
return "*" + getText(((GoPointerType)o).getType());
646+
}
643647
if (o instanceof GoSpecType) {
644648
String fqn = getFqn(getTypeSpecSafe(o));
645649
if (fqn != null) {

0 commit comments

Comments
 (0)