Skip to content

Commit 8d7c2e1

Browse files
committed
QuickDoc: fix typelist representation
1 parent f87d8e6 commit 8d7c2e1

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/com/goide/GoDocumentationProvider.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@
3434
import com.intellij.psi.*;
3535
import com.intellij.psi.search.GlobalSearchScopesCore;
3636
import com.intellij.psi.util.PsiTreeUtil;
37-
import com.intellij.util.ArrayUtil;
3837
import com.intellij.util.Function;
3938
import com.intellij.util.containers.ContainerUtil;
4039
import com.intellij.xml.util.XmlStringUtil;
4140
import org.jetbrains.annotations.NotNull;
4241
import org.jetbrains.annotations.Nullable;
4342

44-
import java.util.Collection;
45-
import java.util.Collections;
46-
import java.util.Comparator;
47-
import java.util.List;
43+
import java.util.*;
4844

4945
public class GoDocumentationProvider extends AbstractDocumentationProvider {
5046
private static final GoCommentsConverter COMMENTS_CONVERTER = new GoCommentsConverter();
@@ -242,7 +238,7 @@ else if (type instanceof GoPointerType) {
242238
return replaceInnerTypes(type, ((GoPointerType)type).getType());
243239
}
244240
else if (type instanceof GoTypeList) {
245-
return replaceInnerTypes(type, ArrayUtil.toObjectArray(GoType.class, ((GoTypeList)type).getTypeList()));
241+
return "(" + replaceInnerTypes(type, ((GoTypeList)type).getTypeList()) + ")";
246242
}
247243

248244
GoTypeReferenceExpression typeRef = GoPsiImplUtil.getTypeReference(type);
@@ -259,13 +255,18 @@ else if (type instanceof GoTypeList) {
259255

260256
@NotNull
261257
private static String replaceInnerTypes(@NotNull GoType type, GoType... innerTypes) {
258+
return replaceInnerTypes(type, Arrays.asList(innerTypes));
259+
}
260+
261+
@NotNull
262+
private static String replaceInnerTypes(@NotNull GoType type, @NotNull List<GoType> innerTypes) {
262263
StringBuilder result = new StringBuilder();
263264
String typeText = type.getText();
264265
int initialOffset = type.getTextRange().getStartOffset();
265266
int lastStartOffset = type.getTextLength();
266267
ContainerUtil.sort(innerTypes, ELEMENT_BY_RANGE_COMPARATOR);
267-
for (int i = innerTypes.length - 1; i >= 0; i--) {
268-
GoType innerType = innerTypes[i];
268+
for (int i = innerTypes.size() - 1; i >= 0; i--) {
269+
GoType innerType = innerTypes.get(i);
269270
if (innerType != null) {
270271
TextRange range = innerType.getTextRange().shiftRight(-initialOffset);
271272
result.insert(0, XmlStringUtil.escapeString(typeText.substring(range.getEndOffset(), lastStartOffset)));

testData/doc/signature.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package a;
2+
func _() {Fo<caret>o()}
3+
// If n < 0, there is no limit on the number of replacements.
4+
func Foo(a map[int]*string, b (string), c string, int) (<-chan string, int) {return c}

testData/doc/signature.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<b>func Foo(a map[<a href="psi_element://builtin#int">int</a>]*<a href="psi_element://builtin#string">string</a>, b (<a href="psi_element://builtin#string">string</a>), c <a href="psi_element://builtin#string">string</a>, <a href="psi_element://builtin#int">int</a>) (&lt;-chan <a href="psi_element://builtin#string">string</a>, <a href="psi_element://builtin#int">int</a>)</b>
2+
<p>If n &lt; 0, there is no limit on the number of replacements.
3+
</p>
4+
5+
=====
6+
https://godoc.org/null#Foo

tests/com/goide/GoDocumentationProviderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected LightProjectDescriptor getProjectDescriptor() {
4646
public void testPackageOnImportAlias() { doTest(); }
4747
public void testTypeResultDefinition() { doTest(); }
4848
public void testMultilineTypeListDefinition() { doTest(); }
49+
public void testSignature() { doTest(); }
4950

5051
public void testMultiBlockDoc() { doConverterTest(); }
5152
public void testIndentedBlock() { doConverterTest(); }

0 commit comments

Comments
 (0)