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

[dartpad_ui] Minor clean up and simplifications #3059

Merged
merged 1 commit into from
Sep 24, 2024
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
4 changes: 2 additions & 2 deletions pkgs/dart_services/lib/src/compiling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ String _rewritePaths(String output) {
final lines = output.split('\n');

return lines.map((line) {
final token1 = 'lib/bootstrap.dart:';
const token1 = 'lib/bootstrap.dart:';
var index = line.indexOf(token1);
if (index != -1) {
return 'main.dart:${line.substring(index + token1.length)}';
}

final token2 = 'lib/main.dart:';
const token2 = 'lib/main.dart:';
index = line.indexOf(token2);
if (index != -1) {
return 'main.dart:${line.substring(index + token2.length)}';
Expand Down
1 change: 1 addition & 0 deletions pkgs/dartpad_shared/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ analyzer:

linter:
rules:
- avoid_dynamic_calls
- prefer_final_in_for_each
- prefer_final_locals
88 changes: 44 additions & 44 deletions pkgs/dartpad_shared/lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class SourceRequest {

SourceRequest({required this.source, this.offset});

factory SourceRequest.fromJson(Map<String, dynamic> json) =>
factory SourceRequest.fromJson(Map<String, Object?> json) =>
_$SourceRequestFromJson(json);

Map<String, dynamic> toJson() => _$SourceRequestToJson(this);
Map<String, Object?> toJson() => _$SourceRequestToJson(this);

@override
String toString() => 'SourceRequest[source=$source,offset=$offset]';
Expand All @@ -30,10 +30,10 @@ class AnalysisResponse {
required this.issues,
});

factory AnalysisResponse.fromJson(Map<String, dynamic> json) =>
factory AnalysisResponse.fromJson(Map<String, Object?> json) =>
_$AnalysisResponseFromJson(json);

Map<String, dynamic> toJson() => _$AnalysisResponseToJson(this);
Map<String, Object?> toJson() => _$AnalysisResponseToJson(this);
}

@JsonSerializable()
Expand All @@ -56,10 +56,10 @@ class AnalysisIssue {
this.contextMessages,
});

factory AnalysisIssue.fromJson(Map<String, dynamic> json) =>
factory AnalysisIssue.fromJson(Map<String, Object?> json) =>
_$AnalysisIssueFromJson(json);

Map<String, dynamic> toJson() => _$AnalysisIssueToJson(this);
Map<String, Object?> toJson() => _$AnalysisIssueToJson(this);

int get severity {
return switch (kind) {
Expand Down Expand Up @@ -88,10 +88,10 @@ class Location {
this.column = -1,
});

factory Location.fromJson(Map<String, dynamic> json) =>
factory Location.fromJson(Map<String, Object?> json) =>
_$LocationFromJson(json);

Map<String, dynamic> toJson() => _$LocationToJson(this);
Map<String, Object?> toJson() => _$LocationToJson(this);
}

@JsonSerializable()
Expand All @@ -104,10 +104,10 @@ class DiagnosticMessage {
required this.location,
});

factory DiagnosticMessage.fromJson(Map<String, dynamic> json) =>
factory DiagnosticMessage.fromJson(Map<String, Object?> json) =>
_$DiagnosticMessageFromJson(json);

Map<String, dynamic> toJson() => _$DiagnosticMessageToJson(this);
Map<String, Object?> toJson() => _$DiagnosticMessageToJson(this);
}

@JsonSerializable()
Expand All @@ -116,10 +116,10 @@ class CompileRequest {

CompileRequest({required this.source});

factory CompileRequest.fromJson(Map<String, dynamic> json) =>
factory CompileRequest.fromJson(Map<String, Object?> json) =>
_$CompileRequestFromJson(json);

Map<String, dynamic> toJson() => _$CompileRequestToJson(this);
Map<String, Object?> toJson() => _$CompileRequestToJson(this);
}

@JsonSerializable()
Expand All @@ -128,10 +128,10 @@ class CompileResponse {

CompileResponse({required this.result});

factory CompileResponse.fromJson(Map<String, dynamic> json) =>
factory CompileResponse.fromJson(Map<String, Object?> json) =>
_$CompileResponseFromJson(json);

Map<String, dynamic> toJson() => _$CompileResponseToJson(this);
Map<String, Object?> toJson() => _$CompileResponseToJson(this);
}

@JsonSerializable()
Expand All @@ -144,10 +144,10 @@ class CompileDDCResponse {
required this.modulesBaseUrl,
});

factory CompileDDCResponse.fromJson(Map<String, dynamic> json) =>
factory CompileDDCResponse.fromJson(Map<String, Object?> json) =>
_$CompileDDCResponseFromJson(json);

Map<String, dynamic> toJson() => _$CompileDDCResponseToJson(this);
Map<String, Object?> toJson() => _$CompileDDCResponseToJson(this);
}

@JsonSerializable()
Expand All @@ -160,10 +160,10 @@ class FormatResponse {
required this.offset,
});

factory FormatResponse.fromJson(Map<String, dynamic> json) =>
factory FormatResponse.fromJson(Map<String, Object?> json) =>
_$FormatResponseFromJson(json);

Map<String, dynamic> toJson() => _$FormatResponseToJson(this);
Map<String, Object?> toJson() => _$FormatResponseToJson(this);

@override
String toString() => 'FormatResponse[source=$source,offset=$offset]';
Expand All @@ -184,10 +184,10 @@ class FixesResponse {
required this.assists,
});

factory FixesResponse.fromJson(Map<String, dynamic> json) =>
factory FixesResponse.fromJson(Map<String, Object?> json) =>
_$FixesResponseFromJson(json);

Map<String, dynamic> toJson() => _$FixesResponseToJson(this);
Map<String, Object?> toJson() => _$FixesResponseToJson(this);
}

@JsonSerializable()
Expand All @@ -204,10 +204,10 @@ class SourceChange {
this.selectionOffset,
});

factory SourceChange.fromJson(Map<String, dynamic> json) =>
factory SourceChange.fromJson(Map<String, Object?> json) =>
_$SourceChangeFromJson(json);

Map<String, dynamic> toJson() => _$SourceChangeToJson(this);
Map<String, Object?> toJson() => _$SourceChangeToJson(this);

@override
String toString() => 'SourceChange [$message]';
Expand All @@ -225,10 +225,10 @@ class SourceEdit {
required this.replacement,
});

factory SourceEdit.fromJson(Map<String, dynamic> json) =>
factory SourceEdit.fromJson(Map<String, Object?> json) =>
_$SourceEditFromJson(json);

Map<String, dynamic> toJson() => _$SourceEditToJson(this);
Map<String, Object?> toJson() => _$SourceEditToJson(this);

@override
String toString() => 'SourceEdit [$offset,$length,$replacement]';
Expand All @@ -246,10 +246,10 @@ class LinkedEditGroup {
required this.suggestions,
});

factory LinkedEditGroup.fromJson(Map<String, dynamic> json) =>
factory LinkedEditGroup.fromJson(Map<String, Object?> json) =>
_$LinkedEditGroupFromJson(json);

Map<String, dynamic> toJson() => _$LinkedEditGroupToJson(this);
Map<String, Object?> toJson() => _$LinkedEditGroupToJson(this);
}

@JsonSerializable()
Expand All @@ -262,10 +262,10 @@ class LinkedEditSuggestion {
required this.kind,
});

factory LinkedEditSuggestion.fromJson(Map<String, dynamic> json) =>
factory LinkedEditSuggestion.fromJson(Map<String, Object?> json) =>
_$LinkedEditSuggestionFromJson(json);

Map<String, dynamic> toJson() => _$LinkedEditSuggestionToJson(this);
Map<String, Object?> toJson() => _$LinkedEditSuggestionToJson(this);
}

@JsonSerializable()
Expand All @@ -286,10 +286,10 @@ class DocumentResponse {
this.propagatedType,
});

factory DocumentResponse.fromJson(Map<String, dynamic> json) =>
factory DocumentResponse.fromJson(Map<String, Object?> json) =>
_$DocumentResponseFromJson(json);

Map<String, dynamic> toJson() => _$DocumentResponseToJson(this);
Map<String, Object?> toJson() => _$DocumentResponseToJson(this);
}

@JsonSerializable()
Expand All @@ -310,10 +310,10 @@ class CompleteResponse {
required this.suggestions,
});

factory CompleteResponse.fromJson(Map<String, dynamic> json) =>
factory CompleteResponse.fromJson(Map<String, Object?> json) =>
_$CompleteResponseFromJson(json);

Map<String, dynamic> toJson() => _$CompleteResponseToJson(this);
Map<String, Object?> toJson() => _$CompleteResponseToJson(this);
}

@JsonSerializable()
Expand Down Expand Up @@ -342,10 +342,10 @@ class CompletionSuggestion {
required this.elementParameters,
});

factory CompletionSuggestion.fromJson(Map<String, dynamic> json) =>
factory CompletionSuggestion.fromJson(Map<String, Object?> json) =>
_$CompletionSuggestionFromJson(json);

Map<String, dynamic> toJson() => _$CompletionSuggestionToJson(this);
Map<String, Object?> toJson() => _$CompletionSuggestionToJson(this);

@override
String toString() => '[$relevance] [$kind] $completion';
Expand All @@ -369,10 +369,10 @@ class VersionResponse {
required this.packages,
});

factory VersionResponse.fromJson(Map<String, dynamic> json) =>
factory VersionResponse.fromJson(Map<String, Object?> json) =>
_$VersionResponseFromJson(json);

Map<String, dynamic> toJson() => _$VersionResponseToJson(this);
Map<String, Object?> toJson() => _$VersionResponseToJson(this);
}

@JsonSerializable()
Expand All @@ -383,10 +383,10 @@ class GeminiResponse {
required this.response,
});

factory GeminiResponse.fromJson(Map<String, dynamic> json) =>
factory GeminiResponse.fromJson(Map<String, Object?> json) =>
_$GeminiResponseFromJson(json);

Map<String, dynamic> toJson() => _$GeminiResponseToJson(this);
Map<String, Object?> toJson() => _$GeminiResponseToJson(this);

@override
String toString() => 'GeminiResponse[response=$response]';
Expand All @@ -400,10 +400,10 @@ class OpenInIdxRequest {
required this.code,
});

factory OpenInIdxRequest.fromJson(Map<String, dynamic> json) =>
factory OpenInIdxRequest.fromJson(Map<String, Object?> json) =>
_$OpenInIdxRequestFromJson(json);

Map<String, dynamic> toJson() => _$OpenInIdxRequestToJson(this);
Map<String, Object?> toJson() => _$OpenInIdxRequestToJson(this);

@override
String toString() => 'OpenInIdxRequest [${code.substring(0, 10)} (...)';
Expand All @@ -417,10 +417,10 @@ class OpenInIdxResponse {
required this.idxUrl,
});

factory OpenInIdxResponse.fromJson(Map<String, dynamic> json) =>
factory OpenInIdxResponse.fromJson(Map<String, Object?> json) =>
_$OpenInIdxResponseFromJson(json);

Map<String, dynamic> toJson() => _$OpenInIdxResponseToJson(this);
Map<String, Object?> toJson() => _$OpenInIdxResponseToJson(this);

@override
String toString() => 'OpenInIdxResponse [$idxUrl]';
Expand All @@ -438,8 +438,8 @@ class PackageInfo {
required this.supported,
});

factory PackageInfo.fromJson(Map<String, dynamic> json) =>
factory PackageInfo.fromJson(Map<String, Object?> json) =>
_$PackageInfoFromJson(json);

Map<String, dynamic> toJson() => _$PackageInfoToJson(this);
Map<String, Object?> toJson() => _$PackageInfoToJson(this);
}
10 changes: 5 additions & 5 deletions pkgs/dartpad_shared/lib/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ServicesClient {

Future<T> _requestGet<T>(
String action,
T Function(Map<String, dynamic> json) responseFactory,
T Function(Map<String, Object?> json) responseFactory,
) async {
final response = await client.get(Uri.parse('${rootUrl}api/v3/$action'));

Expand All @@ -62,7 +62,7 @@ class ServicesClient {
} else {
try {
return responseFactory(
json.decode(response.body) as Map<String, dynamic>);
json.decode(response.body) as Map<String, Object?>);
} on FormatException catch (e) {
throw ApiRequestError('$action: $e', response.body);
}
Expand All @@ -71,8 +71,8 @@ class ServicesClient {

Future<T> _requestPost<T>(
String action,
Map<String, dynamic> request,
T Function(Map<String, dynamic> json) responseFactory,
Map<String, Object?> request,
T Function(Map<String, Object?> json) responseFactory,
) async {
final response = await client.post(
Uri.parse('${rootUrl}api/v3/$action'),
Expand All @@ -84,7 +84,7 @@ class ServicesClient {
} else {
try {
return responseFactory(
json.decode(response.body) as Map<String, dynamic>);
json.decode(response.body) as Map<String, Object?>);
} on FormatException catch (e) {
throw ApiRequestError('$action: $e', response.body);
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dartpad_shared/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Shared code between the DartPad frontend and backend.
publish_to: none

environment:
sdk: ^3.4.0
sdk: ^3.5.0

dependencies:
http: ^1.2.1
Expand Down
1 change: 1 addition & 0 deletions pkgs/dartpad_ui/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ analyzer:
linter:
rules:
- directives_ordering
- invalid_runtime_check_with_js_interop_types
- prefer_final_in_for_each
- prefer_final_locals
- prefer_relative_imports
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dartpad_ui/lib/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ web.Element _codeMirrorFactory(int viewId) {

codeMirrorInstance = CodeMirror(
div,
<String, dynamic>{
<String, Object?>{
'lineNumbers': true,
'lineWrapping': true,
'mode': 'dart',
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dartpad_ui/lib/embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void handleEmbedMessage(AppServices services, {bool runOnInject = false}) {
);

parent.postMessage(
({'sender': web.window.name, 'type': 'ready'}).jsify(),
{'sender': web.window.name, 'type': 'ready'}.jsify(),
'*'.toJS,
);
}
Expand Down
Loading