@@ -24,6 +24,10 @@ public partial class Cargo : PackageManager
2424 [ GeneratedRegex ( @"(.+)v(\d+\.\d+\.\d+)\s*v(\d+\.\d+\.\d+)\s*(Yes|No)" ) ]
2525 private static partial Regex UpdateLineRegex ( ) ;
2626
27+ // Matches "ripgrep v15.1.0:" lines from `cargo install --list`
28+ [ GeneratedRegex ( @"^([\w-]+)\s+v(\d+\.\d+\.\d+):" ) ]
29+ private static partial Regex InstallListLineRegex ( ) ;
30+
2731 public Cargo ( )
2832 {
2933 string cargoCommand = OperatingSystem . IsWindows ( ) ? "cargo.exe" : "cargo" ;
@@ -186,6 +190,9 @@ protected override void _loadManagerVersion(out string version)
186190 Logger . Error ( "cargo version error: " + error ) ;
187191 }
188192
193+ public void InvalidateInstalledCache ( ) =>
194+ TaskRecycler < List < Match > > . RemoveFromCache ( GetInstalledCommandOutput ) ;
195+
189196 private IReadOnlyList < Package > GetPackages ( LoggableTaskType taskType )
190197 {
191198 List < Package > Packages = [ ] ;
@@ -217,13 +224,35 @@ private List<Match> GetInstalledCommandOutput()
217224 logger . AddToStdOut ( line ) ;
218225 var match = UpdateLineRegex ( ) . Match ( line ) ;
219226 if ( match . Success )
220- {
221227 output . Add ( match ) ;
222- }
223228 }
224229 logger . AddToStdErr ( p . StandardError . ReadToEnd ( ) ) ;
225230 p . WaitForExit ( ) ;
226231 logger . Close ( p . ExitCode ) ;
232+
233+ if ( output . Count > 0 )
234+ return output ;
235+
236+ // Fallback: cargo-update is not installed, use the built-in `cargo install --list`.
237+ // No latest-version info is available, so updates won't be detected, but the installed
238+ // packages list will be populated correctly.
239+ using Process fallback = GetProcess ( Status . ExecutablePath , "install --list" ) ;
240+ IProcessTaskLogger fallbackLogger = TaskLogger . CreateNew ( LoggableTaskType . OtherTask , fallback ) ;
241+ fallbackLogger . AddToStdOut ( "Falling back to `cargo install --list` (cargo-update not available)" ) ;
242+ fallback . Start ( ) ;
243+ while ( ( line = fallback . StandardOutput . ReadLine ( ) ) is not null )
244+ {
245+ fallbackLogger . AddToStdOut ( line ) ;
246+ var m = InstallListLineRegex ( ) . Match ( line ) ;
247+ if ( ! m . Success ) continue ;
248+ // Synthesise a match compatible with UpdateLineRegex (same installed and latest version → no update)
249+ var fake = UpdateLineRegex ( ) . Match ( $ "{ m . Groups [ 1 ] . Value } v{ m . Groups [ 2 ] . Value } v{ m . Groups [ 2 ] . Value } No") ;
250+ if ( fake . Success )
251+ output . Add ( fake ) ;
252+ }
253+ fallbackLogger . AddToStdErr ( fallback . StandardError . ReadToEnd ( ) ) ;
254+ fallback . WaitForExit ( ) ;
255+ fallbackLogger . Close ( fallback . ExitCode ) ;
227256 return output ;
228257 }
229258
0 commit comments