Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions third_party/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 501.0.0

### Added
- Additional support for folding of Record literals.

### Changed

Expand All @@ -14,6 +15,7 @@
- UI freeze during refactoring operations (e.g. Move File) when Analysis Server is slow (#122)



## 500.0.0

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ protected void buildLanguageFoldRegions(final @NotNull List<FoldingDescriptor> d
DartForStatement.class,
DartWhileStatement.class,
DartDoWhileStatement.class,
DartFormalParameterList.class);
DartFormalParameterList.class,
DartRecord.class);
foldComments(descriptors, psiElements, fileHeaderRange); // 4. Comments and comment sequences
foldClassBodies(descriptors, dartFile); // 5. Class bodies
foldFunctionBodies(descriptors, psiElements); // 6. Function bodies
Expand All @@ -88,6 +89,10 @@ protected void buildLanguageFoldRegions(final @NotNull List<FoldingDescriptor> d
DartTokenTypes.LBRACKET,
DartTokenTypes.RBRACKET,
DartListLiteralExpression.class);
foldLiterals(descriptors, psiElements, // 9.3. Records
DartTokenTypes.LPAREN,
DartTokenTypes.RPAREN,
DartRecord.class);
foldConstructorInvocationExpressions(descriptors, psiElements); // 10. Constructor invocations
foldAssertExpressions(descriptors, psiElements); // 11. Assert statements
foldIfStatements(descriptors, psiElements); // 12.1. If statements
Expand Down Expand Up @@ -138,6 +143,8 @@ protected void buildLanguageFoldRegions(final @NotNull List<FoldingDescriptor> d
if (psiElement instanceof DartAssertStatement) return DOT_DOT_DOT; // 11. Assert statements
if (psiElement instanceof DartBlock) return BRACE_DOTS; // 12. Block statements
if (psiElement instanceof DartFormalParameterList) return PAREN_DOTS; // 13. Parameter list
if (psiElement instanceof DartRecord)
return PAREN_DOTS; // 14. Records
Comment on lines +146 to +147
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency with the rest of the file:

Suggested change
if (psiElement instanceof DartRecord)
return PAREN_DOTS; // 14. Records
if (psiElement instanceof DartRecord) return PAREN_DOTS; // 14. Records

Or if it will have a line break it should probably have surrounding brackets


return DOT_DOT_DOT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package com.jetbrains.lang.dart.folding;

import com.intellij.codeInsight.folding.CodeFoldingSettings;
import com.intellij.lang.folding.FoldingDescriptor;
import com.intellij.openapi.editor.Editor;
import com.intellij.util.Consumer;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.jetbrains.lang.dart.DartCodeInsightFixtureTestCase;
Expand All @@ -11,7 +13,9 @@
/**
* Test the Dart code folding functionality.
* <p>
* This class tests the {@link com.jetbrains.lang.dart.folding.DartFoldingBuilder} class, which is responsible for providing code folding regions for Dart code.
* This class tests the
* {@link com.jetbrains.lang.dart.folding.DartFoldingBuilder} class, which is
* responsible for providing code folding regions for Dart code.
*/
public class DartFoldingTest extends DartCodeInsightFixtureTestCase {

Expand All @@ -24,7 +28,7 @@ private void doTestWithSpecificSettings(@NotNull final Consumer<CodeFoldingSetti
}

private void doTestWithSpecificSettings(@Nullable final Consumer<CodeFoldingSettings> commonSettingsConsumer,
@Nullable final Consumer<DartCodeFoldingSettings> dartCodeFoldingSettingsConsumer) {
@Nullable final Consumer<DartCodeFoldingSettings> dartCodeFoldingSettingsConsumer) {
CodeFoldingSettings commonSettings = null;
CodeFoldingSettings commonOriginalSettings = null;

Expand All @@ -51,8 +55,7 @@ private void doTestWithSpecificSettings(@Nullable final Consumer<CodeFoldingSett
}

doTest();
}
finally {
} finally {
if (commonSettingsConsumer != null) {
XmlSerializerUtil.copyBean(commonOriginalSettings, commonSettings);
}
Expand Down Expand Up @@ -163,5 +166,16 @@ public void testCustomRegions() {
doTest();
}

public void testDartFormalParameterList() { doTest(); }
public void testDartFormalParameterList() {
doTest();
}

public void testRecordFolding() {
doTest();
}

@org.junit.Ignore("Parser bug: Function treated as identifier after Record Type (int,) in field declaration, see https://github.com/flutter/dart-intellij-third-party/issues/150")
public void testRecordTypeMethodFolding() {
doTest();
}
}
34 changes: 34 additions & 0 deletions third_party/src/test/testData/folding/RecordFolding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var r = <fold text='(...)' expand='true'>(
1,
2,
)</fold>;

var r2 = <fold text='(...)' expand='true'>(
a: 1,
b: 2,
)</fold>;

var r3 = <fold text='(...)' expand='true'>(
1,
b: 2,
)</fold>;

var nested = <fold text='(...)' expand='true'>(
1,
<fold text='(...)' expand='true'>(
2,
3,
)</fold>,
)</fold>;

var mixed = <fold text='(...)' expand='true'>(
1,
a: 2,
3,
b: 4,
)</fold>;

var withComments = <fold text='(...)' expand='true'>(
1, // comment
2,
)</fold>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Foo <fold text='{...}' expand='true'>{
final (int,) Function(int)? _textStyles = null;

void bar() <fold text='{...}' expand='true'>{

}</fold>
}</fold>
Loading