Skip to content

Commit e088be7

Browse files
committed
Merge pull request #2035 from dlsniper/add-const-folding
Added const folding option (fixes #2015)
2 parents 8989a05 + 3fd5239 commit e088be7

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/com/goide/editor/GoFoldingBuilder.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ protected void buildLanguageFoldRegions(@NotNull final List<FoldingDescriptor> r
8282
}
8383
}
8484

85+
for (GoConstDeclaration constDeclaration : PsiTreeUtil.findChildrenOfType(file, GoConstDeclaration.class)) {
86+
TextRange range = processList(constDeclaration.getLparen(), constDeclaration.getRparen(), constDeclaration.getConstSpecList().size());
87+
if (range != null) {
88+
result.add(new FoldingDescriptor(constDeclaration, range));
89+
}
90+
}
91+
8592
for (GoTypeDeclaration typeDeclaration : PsiTreeUtil.findChildrenOfType(file, GoTypeDeclaration.class)) {
8693
TextRange range = processList(typeDeclaration.getLparen(), typeDeclaration.getRparen(), typeDeclaration.getTypeSpecList().size());
8794
if (range != null) {
@@ -172,7 +179,8 @@ private static void addCommentFolds(@NotNull PsiElement comment,
172179
}
173180

174181
if (end != null) {
175-
foldElements.add(new FoldingDescriptor(comment, new TextRange(comment.getTextRange().getStartOffset(), end.getTextRange().getEndOffset())));
182+
foldElements
183+
.add(new FoldingDescriptor(comment, new TextRange(comment.getTextRange().getStartOffset(), end.getTextRange().getEndOffset())));
176184
}
177185
}
178186

@@ -182,8 +190,13 @@ protected String getLanguagePlaceholderText(@NotNull ASTNode node, @NotNull Text
182190
PsiElement psi = node.getPsi();
183191
IElementType type = node.getElementType();
184192
if (psi instanceof GoBlock || psi instanceof GoStructType ||
185-
psi instanceof GoInterfaceType || psi instanceof GoLiteralValue) return "{...}";
186-
if (psi instanceof GoVarDeclaration || psi instanceof GoTypeDeclaration) return "(...)";
193+
psi instanceof GoInterfaceType || psi instanceof GoLiteralValue) {
194+
return "{...}";
195+
}
196+
if (psi instanceof GoVarDeclaration || psi instanceof GoConstDeclaration
197+
|| psi instanceof GoTypeDeclaration) {
198+
return "(...)";
199+
}
187200
if (psi instanceof GoImportDeclaration) return "...";
188201
if (GoParserDefinition.LINE_COMMENT == type) return "/.../";
189202
if (GoParserDefinition.MULTILINE_COMMENT == type) return "/*...*/";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package foo
2+
3+
const <fold text='(...)'>(
4+
demo = 1
5+
dem = "2"
6+
)</fold>

tests/com/goide/editor/GoFoldingBuilderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected String getBasePath() {
3737
public void testImportListWithNewLineAfterKeyword() { doTest(); }
3838
public void testImportListWithOnlyThreeSymbolsToFold() { doTest(); }
3939
public void testVarDeclaration() { doTest(); }
40+
public void testConstDeclaration() { doTest(); }
4041
public void testTypeDeclaration() { doTest(); }
4142
public void testCompositeLiteral() { doTest(); }
4243
}

0 commit comments

Comments
 (0)