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;
|
return element.source!.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get canReadDart;
|
||||||
|
|
||||||
/// Resolves a Dart library by its uri.
|
/// Resolves a Dart library by its uri.
|
||||||
///
|
///
|
||||||
/// This should also be able to resolve SDK libraries.
|
/// This should also be able to resolve SDK libraries.
|
||||||
|
|
|
@ -63,13 +63,15 @@ class DriftAnalysisDriver {
|
||||||
|
|
||||||
AnalysisResultCacheReader? cacheReader;
|
AnalysisResultCacheReader? cacheReader;
|
||||||
|
|
||||||
final KnownDriftTypes knownTypes;
|
final KnownDriftTypes? _knownTypes;
|
||||||
|
|
||||||
|
KnownDriftTypes get knownTypes => _knownTypes!;
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
DriftAnalysisDriver(
|
DriftAnalysisDriver(
|
||||||
this.backend,
|
this.backend,
|
||||||
this.options,
|
this.options,
|
||||||
this.knownTypes, {
|
this._knownTypes, {
|
||||||
bool isTesting = false,
|
bool isTesting = false,
|
||||||
}) : _isTesting = isTesting;
|
}) : _isTesting = isTesting;
|
||||||
|
|
||||||
|
|
|
@ -102,10 +102,14 @@ class KnownDriftTypes {
|
||||||
return type?.asInstanceOf(converter);
|
return type?.asInstanceOf(converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<KnownDriftTypes> resolve(DriftBackend backend) async {
|
static Future<KnownDriftTypes?> resolve(DriftBackend backend) async {
|
||||||
final library = await backend.readDart(uri);
|
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');
|
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());
|
return Future.value(resourceProvider.getFile(path).readAsStringSync());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canReadDart => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<LibraryElement> readDart(Uri uri) async {
|
Future<LibraryElement> readDart(Uri uri) async {
|
||||||
final result = await context.currentSession.getLibraryByUri(uri.toString());
|
final result = await context.currentSession.getLibraryByUri(uri.toString());
|
||||||
|
|
|
@ -38,6 +38,9 @@ class DriftBuildBackend extends DriftBackend {
|
||||||
return id.uri;
|
return id.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canReadDart => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<LibraryElement> readDart(Uri uri) async {
|
Future<LibraryElement> readDart(Uri uri) async {
|
||||||
if (uri.scheme == 'dart') {
|
if (uri.scheme == 'dart') {
|
||||||
|
|
|
@ -91,6 +91,9 @@ class _SingleFileNoAnalyzerBackend extends DriftBackend {
|
||||||
return Future.value(contents);
|
return Future.value(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canReadDart => false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<LibraryElement> readDart(Uri uri) async {
|
Future<LibraryElement> readDart(Uri uri) async {
|
||||||
_noAnalyzer();
|
_noAnalyzer();
|
||||||
|
|
|
@ -237,6 +237,9 @@ class TestBackend extends DriftBackend {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canReadDart => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<LibraryElement> readDart(Uri uri) async {
|
Future<LibraryElement> readDart(Uri uri) async {
|
||||||
await ensureHasDartAnalyzer();
|
await ensureHasDartAnalyzer();
|
||||||
|
|
Loading…
Reference in New Issue