@@ -1096,8 +1096,15 @@ class TaskBackend {
10961096 /// If [version] or newer exists with finished analysis, it will be preferred, otherwise
10971097 /// older versions may be considered too.
10981098 ///
1099+ /// When [preferDocsCompleted] is set, a successfully completed but potentially older
1100+ /// version is preferred over a completed version without documentation.
1101+ ///
10991102 /// Returns `null` if no such version exists.
1100- Future <String ?> closestFinishedVersion (String package, String version) async {
1103+ Future <String ?> closestFinishedVersion (
1104+ String package,
1105+ String version, {
1106+ bool preferDocsCompleted = false ,
1107+ }) async {
11011108 final cachedValue =
11021109 await cache.closestFinishedVersion (package, version).get (() async {
11031110 final semanticVersion = Version .parse (version);
@@ -1108,7 +1115,19 @@ class TaskBackend {
11081115 if (state == null || state.hasNeverFinished) {
11091116 continue ;
11101117 }
1111- final candidates = state.versions? .entries
1118+ List <Version >? candidates;
1119+ if (preferDocsCompleted) {
1120+ final finishedDocCandidates = state.versions? .entries
1121+ .where ((e) => e.value.docs)
1122+ .map ((e) => Version .parse (e.key))
1123+ .toList ();
1124+ if (finishedDocCandidates != null &&
1125+ finishedDocCandidates.isNotEmpty) {
1126+ candidates = finishedDocCandidates;
1127+ }
1128+ }
1129+
1130+ candidates ?? = state.versions? .entries
11121131 .where ((e) => e.value.finished)
11131132 .map ((e) => Version .parse (e.key))
11141133 .toList ();
0 commit comments