mirror of https://github.com/AMT-Cheif/drift.git
fix no backend error
This commit is contained in:
parent
9a1dc2b0e3
commit
7c6e36e4f4
|
@ -19,6 +19,8 @@ abstract class DriftBackend {
|
|||
return element.source!.uri;
|
||||
}
|
||||
|
||||
bool get canReadDart;
|
||||
|
||||
/// Resolves a Dart library by its uri.
|
||||
///
|
||||
/// This should also be able to resolve SDK libraries.
|
||||
|
|
|
@ -63,13 +63,15 @@ class DriftAnalysisDriver {
|
|||
|
||||
AnalysisResultCacheReader? cacheReader;
|
||||
|
||||
final KnownDriftTypes knownTypes;
|
||||
final KnownDriftTypes? _knownTypes;
|
||||
|
||||
KnownDriftTypes get knownTypes => _knownTypes!;
|
||||
|
||||
@visibleForTesting
|
||||
DriftAnalysisDriver(
|
||||
this.backend,
|
||||
this.options,
|
||||
this.knownTypes, {
|
||||
this._knownTypes, {
|
||||
bool isTesting = false,
|
||||
}) : _isTesting = isTesting;
|
||||
|
||||
|
|
|
@ -102,10 +102,14 @@ class KnownDriftTypes {
|
|||
return type?.asInstanceOf(converter);
|
||||
}
|
||||
|
||||
static Future<KnownDriftTypes> resolve(DriftBackend backend) async {
|
||||
final library = await backend.readDart(uri);
|
||||
static Future<KnownDriftTypes?> resolve(DriftBackend backend) async {
|
||||
if (backend.canReadDart) {
|
||||
final library = await backend.readDart(uri);
|
||||
|
||||
return KnownDriftTypes._fromLibrary(library);
|
||||
return KnownDriftTypes._fromLibrary(library);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static final Uri uri = Uri.parse('package:drift/src/drift_dev_helper.dart');
|
||||
|
|
|
@ -96,6 +96,9 @@ class AnalysisContextBackend extends DriftBackend {
|
|||
return Future.value(resourceProvider.getFile(path).readAsStringSync());
|
||||
}
|
||||
|
||||
@override
|
||||
bool get canReadDart => true;
|
||||
|
||||
@override
|
||||
Future<LibraryElement> readDart(Uri uri) async {
|
||||
final result = await context.currentSession.getLibraryByUri(uri.toString());
|
||||
|
|
|
@ -38,6 +38,9 @@ class DriftBuildBackend extends DriftBackend {
|
|||
return id.uri;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get canReadDart => true;
|
||||
|
||||
@override
|
||||
Future<LibraryElement> readDart(Uri uri) async {
|
||||
if (uri.scheme == 'dart') {
|
||||
|
|
|
@ -91,6 +91,9 @@ class _SingleFileNoAnalyzerBackend extends DriftBackend {
|
|||
return Future.value(contents);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get canReadDart => false;
|
||||
|
||||
@override
|
||||
Future<LibraryElement> readDart(Uri uri) async {
|
||||
_noAnalyzer();
|
||||
|
|
|
@ -237,6 +237,9 @@ class TestBackend extends DriftBackend {
|
|||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get canReadDart => true;
|
||||
|
||||
@override
|
||||
Future<LibraryElement> readDart(Uri uri) async {
|
||||
await ensureHasDartAnalyzer();
|
||||
|
|
Loading…
Reference in New Issue