Skip to content

Commit

Permalink
Merge branch 'main' into misc/add-security-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough committed Jan 3, 2024
2 parents 2b534e4 + ae401b2 commit 4a930c9
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .cloud_build/dart_services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ steps:
- PROJECT_ID=$PROJECT_ID
- --build-arg
- FLUTTER_CHANNEL=${_FLUTTER_CHANNEL}
- --build-arg
- BUILD_SHA=${SHORT_SHA}
- .
dir: pkgs/dart_services

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dart_pad.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: ${{ matrix.sdk }}
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
- uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8

- name: Install dart dependencies
run: dart pub get
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/no-response.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'dart-lang' }}
steps:
- uses: actions/stale@1160a2240286f5da8ec72b1c0816ce2481aabf84
- uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e
with:
days-before-stale: -1
days-before-close: 14
Expand Down
2 changes: 0 additions & 2 deletions pkgs/dart_pad/lib/playground.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ class Playground extends EditorUi implements GistContainer, GistController {
Layout.flutter),
Sample('85e77d36533b16647bf9b6eb8c03296d', 'Implicit animations',
Layout.flutter),
Sample('d57c6c898dabb8c6fb41018588b8cf73', 'Firebase Nanochat',
Layout.flutter),
Sample(
'493c8b3ef8931cbac3fbbe5c04b9c4cf', 'Google Fonts', Layout.flutter),
Sample('a133148221a8cbacbcef8bc77a6c82ec', 'Provider', Layout.flutter),
Expand Down
6 changes: 5 additions & 1 deletion pkgs/dart_services/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG PROJECT_ID
ARG FLUTTER_CHANNEL
ARG BUILD_SHA

FROM gcr.io/$PROJECT_ID/flutter:$FLUTTER_CHANNEL

WORKDIR /app
Expand All @@ -8,7 +10,9 @@ COPY . /app
RUN dart pub get
RUN dart compile exe bin/server.dart -o bin/server

RUN dart pub run grinder build-project-templates
RUN dart run grinder build-project-templates

ENV BUILD_SHA=$BUILD_SHA

EXPOSE 8080
CMD ["/app/bin/server"]
2 changes: 1 addition & 1 deletion pkgs/dart_services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To run tests:

`dart test`

### Re-renerating source
### Re-generating source

To rebuild the shelf router, run:

Expand Down
7 changes: 4 additions & 3 deletions pkgs/dart_services/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:args/args.dart';
import 'package:logging/logging.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf;
import 'package:shelf_gzip/shelf_gzip.dart';

import 'src/caching.dart';
import 'src/common_server.dart';
Expand Down Expand Up @@ -103,7 +104,6 @@ class EndpointsServer {

late final HttpServer server;

late final Pipeline pipeline;
late final Handler handler;

late final CommonServerApi commonServer;
Expand All @@ -127,10 +127,11 @@ class EndpointsServer {
GitHubOAuthHandler.setCache(cache);
GitHubOAuthHandler.addRoutes(commonServer.router);

pipeline = const Pipeline()
final pipeline = const Pipeline()
.addMiddleware(logRequestsToLogger(_logger))
.addMiddleware(createCustomCorsHeadersMiddleware())
.addMiddleware(exceptionResponse());
.addMiddleware(exceptionResponse())
.addMiddleware(gzipMiddleware);

handler = pipeline.addHandler(commonServer.router.call);
}
Expand Down
19 changes: 9 additions & 10 deletions pkgs/dart_services/lib/src/analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ class AnalysisServerWrapper {
}

Future<api.CompleteResponse> complete(String source, int offset) async {
const maxResults = 500;

final results = await _completeImpl(
{kMainDart: source},
kMainDart,
offset,
maxResults: maxResults,
);

final suggestions =
Expand All @@ -149,14 +152,6 @@ class AnalysisServerWrapper {
}

return false;
}).toList();

suggestions.sort((CompletionSuggestion x, CompletionSuggestion y) {
if (x.relevance == y.relevance) {
return x.completion.compareTo(y.completion);
} else {
return y.relevance.compareTo(x.relevance);
}
});

return api.CompleteResponse(
Expand Down Expand Up @@ -359,13 +354,17 @@ class AnalysisServerWrapper {
}

Future<Suggestions2Result> _completeImpl(
Map<String, String> sources, String sourceName, int offset) async {
Map<String, String> sources,
String sourceName,
int offset, {
required int maxResults,
}) async {
await _loadSources(_getOverlayMapWithPaths(sources));

return await analysisServer.completion.getSuggestions2(
_getPathFromName(sourceName),
offset,
500,
maxResults,
);
}

Expand Down
2 changes: 2 additions & 0 deletions pkgs/dart_services/lib/src/common_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:logging/logging.dart';
import 'package:shelf/shelf.dart';
Expand Down Expand Up @@ -241,6 +242,7 @@ class CommonServerApi {
dartVersion: sdk.dartVersion,
flutterVersion: sdk.flutterVersion,
engineVersion: sdk.engineVersion,
serverRevision: Platform.environment['BUILD_SHA'],
experiments: sdk.experiments,
packages: packages,
);
Expand Down
2 changes: 2 additions & 0 deletions pkgs/dart_services/lib/src/shared/model.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkgs/dart_services/lib/src/shared/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions pkgs/dart_services/pubspec.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkgs/dart_services/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
path: ^1.8.3
resp_client: ^1.2.0
shelf: ^1.4.1
shelf_gzip: ^4.1.0
shelf_router: ^1.1.4
yaml: ^3.1.2

Expand Down
7 changes: 4 additions & 3 deletions pkgs/dart_services/test/src/sample_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

const sampleCode = '''
void main() {
print("hello");
print('hello');
}
''';

const sampleCodeWeb = """
import 'dart:html';
void main() {
print("hello");
print('hello');
querySelector('#foo')?.text = 'bar';
}
""";
Expand Down Expand Up @@ -114,6 +114,7 @@ class _MyHomePageState extends State<MyHomePage> {
// From https://gist.github.com/RedBrogdon/e0a2e942e85fde2cd39b2741ff0c49e5
const sampleCodeFlutterSunflower = r'''
import 'dart:math' as math;
import 'package:flutter/material.dart';
const Color primaryColor = Colors.orange;
Expand Down Expand Up @@ -254,7 +255,7 @@ const sampleCodeFlutterDraggableCard = '''
import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';
main() {
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
Expand Down
2 changes: 2 additions & 0 deletions pkgs/dartpad_shared/lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,15 @@ class VersionResponse {
final String dartVersion;
final String flutterVersion;
final String engineVersion;
final String? serverRevision;
final List<String> experiments;
final List<PackageInfo> packages;

VersionResponse({
required this.dartVersion,
required this.flutterVersion,
required this.engineVersion,
this.serverRevision,
required this.experiments,
required this.packages,
});
Expand Down
2 changes: 2 additions & 0 deletions pkgs/dartpad_shared/lib/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a930c9

Please sign in to comment.