Some plugin fixes

This commit is contained in:
Simon Binder 2022-01-24 17:25:24 +01:00
parent 6d89a7711b
commit 7d56497c18
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 25 additions and 10 deletions

View File

@ -43,7 +43,9 @@ class MoorDriver {
}
bool _ownsFile(String path) =>
path.endsWith('.moor') || path.endsWith('.dart');
path.endsWith('.moor') ||
path.endsWith('.drift') ||
path.endsWith('.dart');
FoundFile pathToFoundFile(String path) {
final uri = _resourceProvider.pathContext.toUri(path);
@ -99,21 +101,34 @@ class MoorDriver {
/// Waits for the file at [path] to be parsed. If the file is neither a Dart
/// or a moor file, returns `null`.
Future<FoundFile> waitFileParsed(String path) {
Future<FoundFile> waitFileParsed(String path) async {
if (!_ownsFile(path)) {
return Future.value(null);
return null;
}
final found = pathToFoundFile(path);
if (found.isParsed) {
return Future.value(found);
return found;
} else {
_runTask(path);
final result = Completer<FoundFile>();
return session
unawaited(session
.completedFiles()
.firstWhere((file) => file == found && file.isParsed);
.firstWhere((file) => file == found && file.isParsed)
.then((file) {
if (!result.isCompleted) {
result.complete(file);
}
}));
try {
await _runTask(path);
} on Exception {
result.complete(null);
}
return result.future;
}
}

View File

@ -5,4 +5,4 @@ include: package:pedantic/analysis_options.yaml
#analyzer:
# plugins:
# - moor
# - drift

View File

@ -5,8 +5,8 @@ environment:
sdk: '>=2.4.0 <3.0.0'
dependencies:
moor:
path: ../../moor
drift:
path: ../../drift
dev_dependencies:
pedantic: ^1.7.0