Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve multi-line comment order #3412

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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: 1 addition & 1 deletion drift_dev/lib/src/analysis/resolver/drift/table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ extension on ColumnDefinition {
final tokens = <CommentToken>[];

while (lastBefore is CommentToken) {
tokens.add(lastBefore);
tokens.insert(0, lastBefore);
lastBefore = lastBefore.previous;
}

Expand Down
28 changes: 28 additions & 0 deletions drift_dev/test/analysis/resolver/drift/table_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,34 @@ CREATE TABLE IF NOT EXISTS currencies (
);
});

test('preserves the order of comments for columns', () async {
final state = await TestBackend.inTest({
'a|lib/a.drift': '''
CREATE TABLE todos (
-- This is the first comment.
-- This is the second comment.
title TEXT NOT NULL
);
''',
});

final file = await state.analyze('package:a/a.drift');
state.expectNoErrors();

final table = file.analyzedElements.single as DriftTable;
final column = table.columnBySqlName['title'];

expect(
column,
isA<DriftColumn>().having(
(c) => c.documentationComment,
'documentationComment',
'''/// This is the first comment.
/// This is the second comment.''',
),
);
});

test('can use custom types', () async {
final state = await TestBackend.inTest({
'a|lib/a.drift': '''
Expand Down
Loading