11using System . Text . Json ;
22using Apollo . Components . Console ;
33using Apollo . Components . Infrastructure . MessageBus ;
4+ using Apollo . Components . NuGet ;
45using Apollo . Components . Solutions ;
56using Apollo . Contracts . Analysis ;
7+ using Apollo . Contracts . Solutions ;
68using Apollo . Contracts . Workers ;
79using OmniSharp . Models . v1 . Completion ;
810using Solution = Apollo . Contracts . Solutions . Solution ;
@@ -16,6 +18,8 @@ public class CodeAnalysisState
1618 private readonly IMessageBus _messageBus ;
1719 private readonly SolutionsState _solutionsState ;
1820 private readonly UserAssemblyStore _userAssemblyStore ;
21+ private readonly NuGetState _nuGetState ;
22+ private readonly INuGetStorageService _nuGetStorageService ;
1923 private bool _disabled ;
2024
2125 public event Func < Task > ? OnCodeAnalysisStateChanged ;
@@ -65,13 +69,17 @@ public CodeAnalysisState(
6569 CodeAnalysisConsoleService console ,
6670 IMessageBus messageBus ,
6771 SolutionsState solutionsState ,
68- UserAssemblyStore userAssemblyStore )
72+ UserAssemblyStore userAssemblyStore ,
73+ NuGetState nuGetState ,
74+ INuGetStorageService nuGetStorageService )
6975 {
7076 _workerFactory = workerFactory ;
7177 _console = console ;
7278 _messageBus = messageBus ;
7379 _solutionsState = solutionsState ;
7480 _userAssemblyStore = userAssemblyStore ;
81+ _nuGetState = nuGetState ;
82+ _nuGetStorageService = nuGetStorageService ;
7583
7684 _userAssemblyStore . OnAssemblyUpdated += HandleUserAssemblyUpdated ;
7785 }
@@ -130,6 +138,8 @@ public async Task<List<Diagnostic>> GetDiagnosticsAsync(Solution solution, strin
130138 if ( Disabled || ! _workerReady || solution == null || _workerProxy == null )
131139 return [ ] ;
132140
141+ solution . NuGetReferences = await LoadNuGetReferencesAsync ( ) ;
142+
133143 var request = new DiagnosticRequestWrapper
134144 {
135145 Solution = solution ,
@@ -145,6 +155,35 @@ public async Task<List<Diagnostic>> GetDiagnosticsAsync(Solution solution, strin
145155
146156 return diagnostics ? . ToList ( ) ?? [ ] ;
147157 }
158+
159+ private async Task < List < NuGetReference > > LoadNuGetReferencesAsync ( )
160+ {
161+ var references = new List < NuGetReference > ( ) ;
162+
163+ foreach ( var package in _nuGetState . InstalledPackages )
164+ {
165+ foreach ( var assemblyName in package . AssemblyNames )
166+ {
167+ var assemblyData = await _nuGetStorageService . GetAssemblyDataAsync (
168+ package . Id ,
169+ package . Version ,
170+ assemblyName ) ;
171+
172+ if ( assemblyData != null )
173+ {
174+ references . Add ( new NuGetReference
175+ {
176+ PackageId = package . Id ,
177+ AssemblyName = assemblyName ,
178+ AssemblyData = assemblyData
179+ } ) ;
180+ _console . AddLog ( $ "Loaded NuGet assembly: { assemblyName } from { package . Id } ", ConsoleSeverity . Debug ) ;
181+ }
182+ }
183+ }
184+
185+ return references ;
186+ }
148187
149188 public async Task UpdateDocumentAsync ( string path , string fullContent )
150189 {
0 commit comments