Skip to content

Commit

Permalink
feat(celest): Add analyzer plugin (#182)
Browse files Browse the repository at this point in the history
Initial implementation adds support for `Go to Definition` with cloud functions from Flutter app -> backend.
  • Loading branch information
dnys1 authored Sep 29, 2024
1 parent 4b7f420 commit d75c809
Show file tree
Hide file tree
Showing 26 changed files with 596 additions and 430 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ pubspec.lock
target/

# These are backup files generated by rustfmt
**/*.rs.bk
**/*.rs.bk

## VS Code extension logs ##
.vscode/logs/
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dart.dapLogFile": ".vscode/logs/dap.log",
"dart.dartTestLogFile": ".vscode/logs/dart_test/${name}.log",
"dart.toolingDaemonLogFile": ".vscode/logs/dtd.log",
"dart.devToolsLogFile": ".vscode/logs/devtools.log",
"dart.analyzerLogFile": ".vscode/logs/analyzer.log",
"dart.vmServiceLogFile": ".vscode/logs/vm_service/${name}.log",
"dart.extensionLogFile": ".vscode/logs/dartcode_ext.log",
"dart.analyzerInstrumentationLogFile": ".vscode/logs/analyzer/instrumentation.log"
}
4 changes: 4 additions & 0 deletions packages/celest/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include: package:flutter_lints/flutter.yaml

analyzer:
plugins:
- celest
17 changes: 9 additions & 8 deletions packages/celest/example/celest/client/lib/example_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ library; // ignore_for_file: no_leading_underscores_for_library_prefixes

import 'dart:io' as _$io;

import 'package:celest_core/_internal.dart';
import 'package:celest_core/src/util/globals.dart';
import 'package:celest_core/_internal.dart' as _$celest;
import 'package:celest_core/src/util/globals.dart' as _$celest;
import 'package:http/http.dart' as _$http;

import 'src/functions.dart';
Expand All @@ -23,22 +23,23 @@ enum CelestEnvironment {
local;

Uri get baseUri => switch (this) {
local => kIsWeb || !_$io.Platform.isAndroid
? Uri.parse('http://localhost:52780')
: Uri.parse('http://10.0.2.2:52780'),
local => _$celest.kIsWeb || !_$io.Platform.isAndroid
? Uri.parse('http://localhost:52792')
: Uri.parse('http://10.0.2.2:52792'),
};
}

class Celest with CelestBase {
class Celest with _$celest.CelestBase {
var _initialized = false;

late CelestEnvironment _currentEnvironment;

late final NativeStorage nativeStorage = NativeStorage(scope: 'celest');
late final _$celest.NativeStorage nativeStorage =
_$celest.NativeStorage(scope: 'celest');

@override
late _$http.Client httpClient =
CelestHttpClient(secureStorage: nativeStorage.secure);
_$celest.CelestHttpClient(secureStorage: nativeStorage.secure);

late Uri _baseUri;

Expand Down
70 changes: 15 additions & 55 deletions packages/celest/example/celest/client/lib/src/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ library; // ignore_for_file: no_leading_underscores_for_library_prefixes

import 'dart:convert' as _$convert;

import 'package:celest/celest.dart';
import 'package:celest_backend/exceptions/bad_name_exception.dart'
as _$bad_name_exception;
import 'package:celest_backend/models/person.dart' as _$person;
import 'package:celest_core/celest_core.dart';
import 'package:celest_core/src/exception/cloud_exception.dart';
import 'package:celest_core/src/exception/serialization_exception.dart';
import 'package:celest/celest.dart' as _$celest;
import 'package:celest_backend/exceptions/bad_name_exception.dart';
import 'package:celest_backend/models/person.dart';
import 'package:celest_core/celest_core.dart' as _$celest;

import '../example_client.dart';

Expand All @@ -28,54 +25,13 @@ class CelestFunctionsGreeting {
final $error = ($body['error'] as Map<String, Object?>);
final $code = ($error['code'] as String);
final $message = ($error['message'] as String?);
final $details = ($error['details'] as JsonMap?);
final $details = ($error['details'] as _$celest.JsonMap?);
switch ($code) {
case r'celest.core.CloudException':
throw Serializers.instance.deserialize<CloudException>($details);
case r'celest.core.CancelledException':
throw Serializers.instance.deserialize<CancelledException>($details);
case r'celest.core.UnknownError':
throw Serializers.instance.deserialize<UnknownError>($details);
case r'celest.core.BadRequestException':
throw Serializers.instance.deserialize<BadRequestException>($details);
case r'celest.core.UnauthorizedException':
throw Serializers.instance.deserialize<UnauthorizedException>($details);
case r'celest.core.NotFoundException':
throw Serializers.instance.deserialize<NotFoundException>($details);
case r'celest.core.AlreadyExistsException':
throw Serializers.instance
.deserialize<AlreadyExistsException>($details);
case r'celest.core.PermissionDeniedException':
throw Serializers.instance
.deserialize<PermissionDeniedException>($details);
case r'celest.core.ResourceExhaustedException':
throw Serializers.instance
.deserialize<ResourceExhaustedException>($details);
case r'celest.core.FailedPreconditionException':
throw Serializers.instance
.deserialize<FailedPreconditionException>($details);
case r'celest.core.AbortedException':
throw Serializers.instance.deserialize<AbortedException>($details);
case r'celest.core.OutOfRangeException':
throw Serializers.instance.deserialize<OutOfRangeException>($details);
case r'celest.core.UnimplementedError':
throw Serializers.instance.deserialize<UnimplementedError>($details);
case r'celest.core.InternalServerError':
throw Serializers.instance.deserialize<InternalServerError>($details);
case r'celest.core.UnavailableError':
throw Serializers.instance.deserialize<UnavailableError>($details);
case r'celest.core.DataLossError':
throw Serializers.instance.deserialize<DataLossError>($details);
case r'celest.core.DeadlineExceededError':
throw Serializers.instance.deserialize<DeadlineExceededError>($details);
case r'celest.core.SerializationException':
throw Serializers.instance
.deserialize<SerializationException>($details);
case r'example.BadNameException':
throw Serializers.instance
.deserialize<_$bad_name_exception.BadNameException>($details);
case r'example.v1.BadNameException':
throw _$celest.Serializers.instance
.deserialize<BadNameException>($details);
default:
throw CloudException.http(
throw _$celest.CloudException.http(
statusCode: $statusCode,
code: $code,
message: $message,
Expand All @@ -85,12 +41,16 @@ class CelestFunctionsGreeting {
}

/// Says hello to a [person].
Future<String> sayHello({required _$person.Person person}) async {
@_$celest.CloudFunction(
api: 'greeting',
function: 'sayHello',
)
Future<String> sayHello({required Person person}) async {
final $response = await celest.httpClient.post(
celest.baseUri.resolve('/greeting/say-hello'),
headers: {'Content-Type': 'application/json; charset=utf-8'},
body: _$convert.jsonEncode(
{r'person': Serializers.instance.serialize<_$person.Person>(person)}),
{r'person': _$celest.Serializers.instance.serialize<Person>(person)}),
);
final $body =
(_$convert.jsonDecode($response.body) as Map<String, Object?>);
Expand Down
Loading

0 comments on commit d75c809

Please sign in to comment.