mirror of https://github.com/AMT-Cheif/drift.git
Make eager ast resolving behavior opt-in
This commit is contained in:
parent
e2b65e968a
commit
d43e227757
|
@ -63,6 +63,8 @@ At the moment, moor supports these options:
|
|||
However, it's still in development and may not work in all cases yet. Please report any issues you can find.
|
||||
__Warning:__ The new type inference algorithm is in development and does not obey to semantic versioning.
|
||||
Results and generated code might change in moor versions not declared as breaking.
|
||||
* `eagerly_load_dart_ast`: Moor's builder will load the resolved AST whenever it encounters a Dart file,
|
||||
instead of lazily when it reads a table. This is used to investigate rare builder crashes.
|
||||
|
||||
## Available extensions
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ targets:
|
|||
compact_query_methods: true
|
||||
write_from_json_string_constructor: true
|
||||
use_experimental_inference: true
|
||||
eagerly_load_dart_ast: true
|
||||
sqlite_modules:
|
||||
- json1
|
||||
- fts5
|
|
@ -63,6 +63,9 @@ class MoorOptions {
|
|||
@JsonKey(name: 'sqlite_modules', defaultValue: [])
|
||||
final List<SqlModule> modules;
|
||||
|
||||
@JsonKey(name: 'eagerly_load_dart_ast', defaultValue: false)
|
||||
final bool eagerlyLoadDartAst;
|
||||
|
||||
/// Whether the [module] has been enabled in this configuration.
|
||||
bool hasModule(SqlModule module) => modules.contains(module);
|
||||
|
||||
|
@ -75,6 +78,7 @@ class MoorOptions {
|
|||
this.useColumnNameAsJsonKeyWhenDefinedInMoorFile = false,
|
||||
this.generateConnectConstructor = false,
|
||||
this.useExperimentalInference = false,
|
||||
this.eagerlyLoadDartAst = false,
|
||||
this.modules = const []});
|
||||
|
||||
factory MoorOptions.fromJson(Map<String, dynamic> json) =>
|
||||
|
|
|
@ -17,7 +17,8 @@ MoorOptions _$MoorOptionsFromJson(Map<String, dynamic> json) {
|
|||
'use_column_name_as_json_key_when_defined_in_moor_file',
|
||||
'generate_connect_constructor',
|
||||
'use_experimental_inference',
|
||||
'sqlite_modules'
|
||||
'sqlite_modules',
|
||||
'eagerly_load_dart_ast',
|
||||
]);
|
||||
final val = MoorOptions(
|
||||
generateFromJsonStringConstructor: $checkedConvert(
|
||||
|
@ -46,6 +47,9 @@ MoorOptions _$MoorOptionsFromJson(Map<String, dynamic> json) {
|
|||
useExperimentalInference: $checkedConvert(
|
||||
json, 'use_experimental_inference', (v) => v as bool) ??
|
||||
false,
|
||||
eagerlyLoadDartAst:
|
||||
$checkedConvert(json, 'eagerly_load_dart_ast', (v) => v as bool) ??
|
||||
false,
|
||||
modules: $checkedConvert(
|
||||
json,
|
||||
'sqlite_modules',
|
||||
|
|
|
@ -5,10 +5,15 @@ import 'package:analyzer/dart/element/type.dart';
|
|||
import 'package:build/build.dart' hide log;
|
||||
import 'package:build/build.dart' as build show log;
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:moor_generator/src/analyzer/options.dart';
|
||||
import 'package:moor_generator/src/backends/backend.dart';
|
||||
import 'package:moor_generator/src/backends/build/serialized_types.dart';
|
||||
|
||||
class BuildBackend extends Backend {
|
||||
final MoorOptions options;
|
||||
|
||||
BuildBackend([this.options = const MoorOptions()]);
|
||||
|
||||
BuildBackendTask createTask(BuildStep step) {
|
||||
return BuildBackendTask(step, this);
|
||||
}
|
||||
|
@ -47,8 +52,11 @@ class BuildBackendTask extends BackendTask {
|
|||
try {
|
||||
final asset = _resolve(uri);
|
||||
final library = await step.resolver.libraryFor(asset);
|
||||
_cachedResults[asset] =
|
||||
await library.session.getResolvedLibraryByElement(library);
|
||||
|
||||
if (backend.options.eagerlyLoadDartAst) {
|
||||
_cachedResults[asset] =
|
||||
await library.session.getResolvedLibraryByElement(library);
|
||||
}
|
||||
|
||||
return library;
|
||||
} on NonLibraryAssetException catch (_) {
|
||||
|
@ -63,8 +71,12 @@ class BuildBackendTask extends BackendTask {
|
|||
// dart file was read...
|
||||
final assetId = await step.resolver.assetIdForElement(element);
|
||||
final result = _cachedResults[assetId];
|
||||
return result.getElementDeclaration(element) ??
|
||||
await super.loadElementDeclaration(element);
|
||||
|
||||
if (result != null) {
|
||||
return result.getElementDeclaration(element);
|
||||
} else {
|
||||
return super.loadElementDeclaration(element);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -19,7 +19,7 @@ mixin MoorBuilder on Builder {
|
|||
Task task;
|
||||
FoundFile input;
|
||||
try {
|
||||
final backend = BuildBackend();
|
||||
final backend = BuildBackend(options);
|
||||
final backendTask = backend.createTask(step);
|
||||
final session = MoorSession(backend, options: options);
|
||||
|
||||
|
|
Loading…
Reference in New Issue