diff --git a/pkgs/dart_services/lib/src/common_server_api.dart b/pkgs/dart_services/lib/src/common_server_api.dart index 5bafac723..801023299 100644 --- a/pkgs/dart_services/lib/src/common_server_api.dart +++ b/pkgs/dart_services/lib/src/common_server_api.dart @@ -67,6 +67,7 @@ class CommonServerApi { column: issue.column, ); }).toList(), + packageImports: result.packageImports, ).toJson()); } else { return unhandledVersion(apiVersion); diff --git a/pkgs/dart_services/lib/src/shared/model.dart b/pkgs/dart_services/lib/src/shared/model.dart index 1496905b6..5385e2a02 100644 --- a/pkgs/dart_services/lib/src/shared/model.dart +++ b/pkgs/dart_services/lib/src/shared/model.dart @@ -25,8 +25,12 @@ class SourceRequest { @JsonSerializable() class AnalysisResponse { final List issues; + final List packageImports; - AnalysisResponse({this.issues = const []}); + AnalysisResponse({ + required this.issues, + required this.packageImports, + }); factory AnalysisResponse.fromJson(Map json) => _$AnalysisResponseFromJson(json); @@ -138,6 +142,11 @@ class FlutterBuildResponse { @JsonSerializable() class FixesResponse { + static final FixesResponse empty = FixesResponse( + fixes: [], + assists: [], + ); + final List fixes; final List assists; @@ -222,6 +231,12 @@ class DocumentResponse { @JsonSerializable() class CompleteResponse { + static final CompleteResponse empty = CompleteResponse( + replacementLength: 0, + replacementOffset: 0, + suggestions: [], + ); + final int replacementOffset; final int replacementLength; final List suggestions; diff --git a/pkgs/dart_services/lib/src/shared/model.g.dart b/pkgs/dart_services/lib/src/shared/model.g.dart index 19369bf36..6cd7b8289 100644 --- a/pkgs/dart_services/lib/src/shared/model.g.dart +++ b/pkgs/dart_services/lib/src/shared/model.g.dart @@ -20,15 +20,18 @@ Map _$SourceRequestToJson(SourceRequest instance) => AnalysisResponse _$AnalysisResponseFromJson(Map json) => AnalysisResponse( - issues: (json['issues'] as List?) - ?.map((e) => AnalysisIssue.fromJson(e as Map)) - .toList() ?? - const [], + issues: (json['issues'] as List) + .map((e) => AnalysisIssue.fromJson(e as Map)) + .toList(), + packageImports: (json['packageImports'] as List) + .map((e) => e as String) + .toList(), ); Map _$AnalysisResponseToJson(AnalysisResponse instance) => { 'issues': instance.issues, + 'packageImports': instance.packageImports, }; AnalysisIssue _$AnalysisIssueFromJson(Map json) => diff --git a/pkgs/dart_services/test/server_v3_test.dart b/pkgs/dart_services/test/server_v3_test.dart index ee20a8296..4f8f8b610 100644 --- a/pkgs/dart_services/test/server_v3_test.dart +++ b/pkgs/dart_services/test/server_v3_test.dart @@ -53,6 +53,7 @@ void main() { } ''')); expect(result.issues, isEmpty); + expect(result.packageImports, isEmpty); }); test('analyze flutter', () async { @@ -79,6 +80,8 @@ class MyApp extends StatelessWidget { expect(result, isNotNull); expect(result.issues, isEmpty); + expect(result.packageImports, isNotEmpty); + expect(result.packageImports, contains('flutter')); }); test('analyze errors', () async { diff --git a/pkgs/dartpad_shared/lib/model.dart b/pkgs/dartpad_shared/lib/model.dart index 1496905b6..5385e2a02 100644 --- a/pkgs/dartpad_shared/lib/model.dart +++ b/pkgs/dartpad_shared/lib/model.dart @@ -25,8 +25,12 @@ class SourceRequest { @JsonSerializable() class AnalysisResponse { final List issues; + final List packageImports; - AnalysisResponse({this.issues = const []}); + AnalysisResponse({ + required this.issues, + required this.packageImports, + }); factory AnalysisResponse.fromJson(Map json) => _$AnalysisResponseFromJson(json); @@ -138,6 +142,11 @@ class FlutterBuildResponse { @JsonSerializable() class FixesResponse { + static final FixesResponse empty = FixesResponse( + fixes: [], + assists: [], + ); + final List fixes; final List assists; @@ -222,6 +231,12 @@ class DocumentResponse { @JsonSerializable() class CompleteResponse { + static final CompleteResponse empty = CompleteResponse( + replacementLength: 0, + replacementOffset: 0, + suggestions: [], + ); + final int replacementOffset; final int replacementLength; final List suggestions; diff --git a/pkgs/dartpad_shared/lib/model.g.dart b/pkgs/dartpad_shared/lib/model.g.dart index 19369bf36..6cd7b8289 100644 --- a/pkgs/dartpad_shared/lib/model.g.dart +++ b/pkgs/dartpad_shared/lib/model.g.dart @@ -20,15 +20,18 @@ Map _$SourceRequestToJson(SourceRequest instance) => AnalysisResponse _$AnalysisResponseFromJson(Map json) => AnalysisResponse( - issues: (json['issues'] as List?) - ?.map((e) => AnalysisIssue.fromJson(e as Map)) - .toList() ?? - const [], + issues: (json['issues'] as List) + .map((e) => AnalysisIssue.fromJson(e as Map)) + .toList(), + packageImports: (json['packageImports'] as List) + .map((e) => e as String) + .toList(), ); Map _$AnalysisResponseToJson(AnalysisResponse instance) => { 'issues': instance.issues, + 'packageImports': instance.packageImports, }; AnalysisIssue _$AnalysisIssueFromJson(Map json) =>