Skip to content
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
46 changes: 20 additions & 26 deletions pkgs/dart_services/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,21 @@ import 'src/sdk.dart';
final DartPadLogger _logger = DartPadLogger('services');

Future<void> main(List<String> args) async {
final parser =
ArgParser()
..addOption('port', valueHelp: 'port', help: 'The port to listen on.')
..addOption(
'redis-url',
valueHelp: 'url',
help: 'The redis server url.',
)
..addOption(
'storage-bucket',
valueHelp: 'name',
help:
'The name of the Cloud Storage bucket for compilation artifacts.',
defaultsTo: 'nnbd_artifacts',
)
..addFlag(
'help',
abbr: 'h',
negatable: false,
help: 'Show this usage information.',
);
final parser = ArgParser()
..addOption('port', valueHelp: 'port', help: 'The port to listen on.')
..addOption('redis-url', valueHelp: 'url', help: 'The redis server url.')
..addOption(
'storage-bucket',
valueHelp: 'name',
help: 'The name of the Cloud Storage bucket for compilation artifacts.',
defaultsTo: 'nnbd_artifacts',
)
..addFlag(
'help',
abbr: 'h',
negatable: false,
help: 'Show this usage information.',
);

final results = parser.parse(args);
if (results['help'] as bool) {
Expand Down Expand Up @@ -88,7 +82,8 @@ Starting dart-services:
port: $port
sdkPath: ${sdk.dartSdkPath}
redisServerUri: $redisServerUri
Cloud Run Environment variables: $cloudRunEnvVars'''.trim(),
Cloud Run Environment variables: $cloudRunEnvVars'''
.trim(),
);

final server = await EndpointsServer.serve(
Expand Down Expand Up @@ -135,10 +130,9 @@ class EndpointsServer {
// https://cloud.google.com/run/docs/reference/container-contract#env-vars
final serverVersion = Platform.environment['K_REVISION'];

final cache =
redisServerUri == null
? NoopCache()
: RedisCache(redisServerUri, sdk, serverVersion);
final cache = redisServerUri == null
? NoopCache()
: RedisCache(redisServerUri, sdk, serverVersion);

commonServer = CommonServerApi(
CommonServerImpl(sdk, cache, storageBucket: storageBucket),
Expand Down
151 changes: 69 additions & 82 deletions pkgs/dart_services/lib/src/analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,20 @@ class AnalysisServerWrapper {
return api.CompleteResponse(
replacementOffset: results.replacementOffset,
replacementLength: results.replacementLength,
suggestions:
suggestions.map((suggestion) {
return api.CompletionSuggestion(
kind: suggestion.kind,
relevance: suggestion.relevance,
completion: suggestion.completion,
deprecated: suggestion.isDeprecated,
selectionOffset: suggestion.selectionOffset,
displayText: suggestion.displayText,
parameterNames: suggestion.parameterNames,
returnType: suggestion.returnType,
elementKind: suggestion.element?.kind,
elementParameters: suggestion.element?.parameters,
);
}).toList(),
suggestions: suggestions.map((suggestion) {
return api.CompletionSuggestion(
kind: suggestion.kind,
relevance: suggestion.relevance,
completion: suggestion.completion,
deprecated: suggestion.isDeprecated,
selectionOffset: suggestion.selectionOffset,
displayText: suggestion.displayText,
parameterNames: suggestion.parameterNames,
returnType: suggestion.returnType,
elementKind: suggestion.element?.kind,
elementParameters: suggestion.element?.parameters,
);
}).toList(),
);
}

Expand All @@ -206,14 +205,12 @@ class AnalysisServerWrapper {
);

return api.FixesResponse(
fixes:
fixChanges.map((change) {
return change.toApiSourceChange();
}).toList(),
assists:
assistsChanges.map((change) {
return change.toApiSourceChange();
}).toList(),
fixes: fixChanges.map((change) {
return change.toApiSourceChange();
}).toList(),
assists: assistsChanges.map((change) {
return change.toApiSourceChange();
}).toList(),
);
}

Expand Down Expand Up @@ -289,40 +286,37 @@ class AnalysisServerWrapper {
);
}

final issues =
errors.map((error) {
final issue = api.AnalysisIssue(
kind: error.severity.toLowerCase(),
message: utils.normalizeImports(error.message),
code: error.code.toLowerCase(),
final issues = errors.map((error) {
final issue = api.AnalysisIssue(
kind: error.severity.toLowerCase(),
message: utils.normalizeImports(error.message),
code: error.code.toLowerCase(),
location: api.Location(
charStart: error.location.offset,
charLength: error.location.length,
line: error.location.startLine,
column: error.location.startColumn,
),
correction: error.correction == null
? null
: utils.normalizeImports(error.correction!),
url: error.url,
contextMessages: error.contextMessages?.map((m) {
return api.DiagnosticMessage(
message: utils.normalizeImports(m.message),
location: api.Location(
charStart: error.location.offset,
charLength: error.location.length,
line: error.location.startLine,
column: error.location.startColumn,
charStart: m.location.offset,
charLength: m.location.length,
line: m.location.startLine,
column: m.location.startColumn,
),
correction:
error.correction == null
? null
: utils.normalizeImports(error.correction!),
url: error.url,
contextMessages:
error.contextMessages?.map((m) {
return api.DiagnosticMessage(
message: utils.normalizeImports(m.message),
location: api.Location(
charStart: m.location.offset,
charLength: m.location.length,
line: m.location.startLine,
column: m.location.startColumn,
),
);
}).toList(),
hasFix: error.hasFix,
);
}).toList(),
hasFix: error.hasFix,
);

return issue;
}).toList();
return issue;
}).toList();

issues.sort((api.AnalysisIssue a, api.AnalysisIssue b) {
// Order issues by severity.
Expand Down Expand Up @@ -394,11 +388,10 @@ class AnalysisServerWrapper {
);
}
}
final reportedImports =
imports
.where((import) => import.packageImport || import.dartImport)
.map((import) => import.uri.stringValue!)
.toList();
final reportedImports = imports
.where((import) => import.packageImport || import.dartImport)
.map((import) => import.uri.stringValue!)
.toList();

return api.AnalysisResponse(
issues: [...importIssues, ...issues],
Expand Down Expand Up @@ -490,31 +483,25 @@ extension SourceChangeExtension on SourceChange {
api.SourceChange toApiSourceChange() {
return api.SourceChange(
message: message,
edits:
edits
.expand((fileEdit) => fileEdit.edits)
.map(
(edit) => api.SourceEdit(
offset: edit.offset,
length: edit.length,
replacement: edit.replacement,
),
)
.toList(),
linkedEditGroups:
linkedEditGroups.map((editGroup) {
return api.LinkedEditGroup(
offsets: editGroup.positions.map((pos) => pos.offset).toList(),
length: editGroup.length,
suggestions:
editGroup.suggestions.map((sug) {
return api.LinkedEditSuggestion(
value: sug.value,
kind: sug.kind,
);
}).toList(),
);
edits: edits
.expand((fileEdit) => fileEdit.edits)
.map(
(edit) => api.SourceEdit(
offset: edit.offset,
length: edit.length,
replacement: edit.replacement,
),
)
.toList(),
linkedEditGroups: linkedEditGroups.map((editGroup) {
return api.LinkedEditGroup(
offsets: editGroup.positions.map((pos) => pos.offset).toList(),
length: editGroup.length,
suggestions: editGroup.suggestions.map((sug) {
return api.LinkedEditSuggestion(value: sug.value, kind: sug.kind);
}).toList(),
);
}).toList(),
selectionOffset: selection?.offset,
);
}
Expand Down
7 changes: 3 additions & 4 deletions pkgs/dart_services/lib/src/common_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ class CommonServerApi {
Request request,
String apiVersion,
) async {
final code =
api.OpenInFirebaseStudioRequest.fromJson(
await request.readAsJson(),
).code;
final code = api.OpenInFirebaseStudioRequest.fromJson(
await request.readAsJson(),
).code;
final idxUrl = Uri.parse('https://studio.firebase.google.com/run.api');

final data = {
Expand Down
24 changes: 12 additions & 12 deletions pkgs/dart_services/lib/src/compiling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ class Compiler {
// All hot restart (or initial compile) requests should include the
// bootstrap library.
final bootstrapPath = path.join(temp.path, 'lib', kBootstrapDart);
final bootstrapContents =
usingFlutter ? kBootstrapFlutterCode : kBootstrapDartCode;
final bootstrapContents = usingFlutter
? kBootstrapFlutterCode
: kBootstrapDartCode;

File(bootstrapPath).writeAsStringSync(bootstrapContents);
compilePath = bootstrapPath;
Expand Down Expand Up @@ -234,8 +235,9 @@ class Compiler {

final results = DDCCompilationResults(
compiledJS: compiledJs,
deltaDill:
useNew ? base64Encode(newDeltaDill.readAsBytesSync()) : null,
deltaDill: useNew
? base64Encode(newDeltaDill.readAsBytesSync())
: null,
modulesBaseUrl:
'https://storage.googleapis.com/$_storageBucket'
'/${_sdk.dartVersion}/',
Expand Down Expand Up @@ -296,10 +298,9 @@ class CompilationResults {
bool get success => problems.isEmpty;

@override
String toString() =>
success
? 'CompilationResults: Success'
: 'Compilation errors: ${problems.join('\n')}';
String toString() => success
? 'CompilationResults: Success'
: 'Compilation errors: ${problems.join('\n')}';
}

/// The result of a DDC compile.
Expand All @@ -323,10 +324,9 @@ class DDCCompilationResults {
bool get success => problems.isEmpty;

@override
String toString() =>
success
? 'CompilationResults: Success'
: 'Compilation errors: ${problems.join('\n')}';
String toString() => success
? 'CompilationResults: Success'
: 'Compilation errors: ${problems.join('\n')}';
}

/// An issue associated with [CompilationResults].
Expand Down
5 changes: 3 additions & 2 deletions pkgs/dart_services/lib/src/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class DartPadRequestContext {

factory DartPadRequestContext.fromRequest(Request request) {
return DartPadRequestContext(
enableLogging:
DartPadRequestHeaders.fromJson(request.headers).enableLogging,
enableLogging: DartPadRequestHeaders.fromJson(
request.headers,
).enableLogging,
);
}
}
2 changes: 1 addition & 1 deletion pkgs/dart_services/lib/src/flutter_genui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:http/http.dart' as http;
import 'context.dart';
import 'logging.dart';

final _logger = DartPadLogger('genui');
final DartPadLogger _logger = DartPadLogger('genui');

class _GenuiEnv {
late final Uri? apiUrl;
Expand Down
Loading