load static method
Loads a SourceFile from the given file if its extension
matches one of the allowed extensions.
Implementation
static SourceFile? load(File file, List<String> extensions) {
// Skip files that don't match any of the given extensions.
if (extensions.isNotEmpty) {
if (!extensions.any((e) => file.path.endsWith(e))) {
return null;
}
}
// Waits until the given file is no longer locked by another process.
while (true) {
if (!isFileLocked(file)) break;
sleep(lockCheckDelay);
}
// Read file content and create a SourceFile instance.
final content = file.readAsStringSync();
return SourceFile(path: file.path, text: content);
}