mirror of https://github.com/AMT-Cheif/drift.git
Don't run discovery prematurely
This commit is contained in:
parent
e53035bc8f
commit
829f45126c
|
@ -174,25 +174,27 @@ class DriftAnalysisDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _warnAboutUnresolvedImportsInDriftFile(FileState known) async {
|
Future<void> _warnAboutUnresolvedImportsInDriftFile(FileState known) async {
|
||||||
await discoverIfNecessary(known);
|
if (known.isDriftFile) {
|
||||||
|
final imports = known.imports?.toList();
|
||||||
|
if (imports == null) return;
|
||||||
|
|
||||||
final state = known.discovery;
|
var discovery = known.discovery as DiscoveredDriftFile?;
|
||||||
if (state is DiscoveredDriftFile) {
|
for (var i = 0; i < imports.length; i++) {
|
||||||
for (final import in state.imports) {
|
var (uri: importedUri, transitive: _) = imports[i];
|
||||||
final file = await findLocalElements(import.importedUri);
|
final file = await findLocalElements(importedUri);
|
||||||
|
|
||||||
if (file.isValidImport != true) {
|
if (file.isValidImport != true) {
|
||||||
var crossesPackageBoundaries = false;
|
var crossesPackageBoundaries = false;
|
||||||
|
|
||||||
if (import.importedUri.scheme == 'package' &&
|
if (importedUri.scheme == 'package' &&
|
||||||
known.ownUri.scheme == 'package') {
|
known.ownUri.scheme == 'package') {
|
||||||
final ownPackage = known.ownUri.pathSegments.first;
|
final ownPackage = known.ownUri.pathSegments.first;
|
||||||
final importedPackage = import.importedUri.pathSegments.first;
|
final importedPackage = importedUri.pathSegments.first;
|
||||||
crossesPackageBoundaries = ownPackage != importedPackage;
|
crossesPackageBoundaries = ownPackage != importedPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
final message = StringBuffer(
|
final message = StringBuffer(
|
||||||
'The imported file, `${import.importedUri}`, does not exist or '
|
'The imported file, `$importedUri`, does not exist or '
|
||||||
"can't be imported.",
|
"can't be imported.",
|
||||||
);
|
);
|
||||||
if (crossesPackageBoundaries) {
|
if (crossesPackageBoundaries) {
|
||||||
|
@ -206,8 +208,14 @@ class DriftAnalysisDriver {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
known.errorsDuringDiscovery.add(
|
if (discovery == null) {
|
||||||
DriftAnalysisError.inDriftFile(import.ast, message.toString()));
|
await discoverIfNecessary(known);
|
||||||
|
discovery = known.discovery as DiscoveredDriftFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
var importAst = discovery.imports[i];
|
||||||
|
known.errorsDuringDiscovery.add(DriftAnalysisError.inDriftFile(
|
||||||
|
importAst.ast, message.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,13 @@ class FileState {
|
||||||
|
|
||||||
String get extension => url.extension(ownUri.path);
|
String get extension => url.extension(ownUri.path);
|
||||||
|
|
||||||
|
bool get isDriftFile {
|
||||||
|
return switch (extension) {
|
||||||
|
'.drift' || '.moor' => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether this file contains a drift database or a drift accessor / DAO.
|
/// Whether this file contains a drift database or a drift accessor / DAO.
|
||||||
bool get containsDatabaseAccessor {
|
bool get containsDatabaseAccessor {
|
||||||
return analyzedElements.any((e) => e is BaseDriftAccessor);
|
return analyzedElements.any((e) => e is BaseDriftAccessor);
|
||||||
|
|
Loading…
Reference in New Issue