Don't run discovery prematurely

This commit is contained in:
Simon Binder 2023-12-11 23:51:51 +01:00
parent e53035bc8f
commit 829f45126c
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 25 additions and 10 deletions

View File

@ -174,25 +174,27 @@ class DriftAnalysisDriver {
}
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;
if (state is DiscoveredDriftFile) {
for (final import in state.imports) {
final file = await findLocalElements(import.importedUri);
var discovery = known.discovery as DiscoveredDriftFile?;
for (var i = 0; i < imports.length; i++) {
var (uri: importedUri, transitive: _) = imports[i];
final file = await findLocalElements(importedUri);
if (file.isValidImport != true) {
var crossesPackageBoundaries = false;
if (import.importedUri.scheme == 'package' &&
if (importedUri.scheme == 'package' &&
known.ownUri.scheme == 'package') {
final ownPackage = known.ownUri.pathSegments.first;
final importedPackage = import.importedUri.pathSegments.first;
final importedPackage = importedUri.pathSegments.first;
crossesPackageBoundaries = ownPackage != importedPackage;
}
final message = StringBuffer(
'The imported file, `${import.importedUri}`, does not exist or '
'The imported file, `$importedUri`, does not exist or '
"can't be imported.",
);
if (crossesPackageBoundaries) {
@ -206,8 +208,14 @@ class DriftAnalysisDriver {
);
}
known.errorsDuringDiscovery.add(
DriftAnalysisError.inDriftFile(import.ast, message.toString()));
if (discovery == null) {
await discoverIfNecessary(known);
discovery = known.discovery as DiscoveredDriftFile;
}
var importAst = discovery.imports[i];
known.errorsDuringDiscovery.add(DriftAnalysisError.inDriftFile(
importAst.ast, message.toString()));
}
}
}

View File

@ -37,6 +37,13 @@ class FileState {
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.
bool get containsDatabaseAccessor {
return analyzedElements.any((e) => e is BaseDriftAccessor);