@@ -9,56 +9,58 @@ use tower_lsp::lsp_types::{
99} ; 
1010use  tracing:: { debug,  info} ; 
1111
12- use  super :: super :: LspInteractor ; 
13- use  super :: super :: component_factory:: { ComponentFactory ,  Config } ; 
12+ use  super :: super :: component_factory:: { ComponentFactory ,  Components ,  Config } ; 
1413use  super :: super :: queries:: QueryExecutor ; 
1514use  super :: command_generator; 
1615use  super :: commands:: { 
1716    LspCommand ,  build_and_scan:: BuildAndScanCommand ,  scan_base_image:: ScanBaseImageCommand , 
1817} ; 
1918use  super :: { InMemoryDocumentDatabase ,  LSPClient ,  WithContext } ; 
19+ use  crate :: app:: LspInteractor ; 
2020
2121use  super :: supported_commands:: SupportedCommands ; 
2222
23- pub  struct  LSPServerInner < C >  { 
23+ pub  struct  LSPServerInner < C ,   F :   ComponentFactory >  { 
2424    interactor :  LspInteractor < C > , 
2525    query_executor :  QueryExecutor , 
26-     component_factory :  Option < ComponentFactory > , 
26+     component_factory :  F , 
27+     components :  Option < Components > , 
2728} 
2829
29- impl < C >  LSPServerInner < C >  { 
30-     pub  fn  new ( client :  C )  -> LSPServerInner < C >  { 
30+ impl < C ,   F :   ComponentFactory >  LSPServerInner < C ,   F >  { 
31+     pub  fn  new ( client :  C ,   component_factory :   F )  -> LSPServerInner < C ,   F >  { 
3132        let  document_database = InMemoryDocumentDatabase :: default ( ) ; 
3233
3334        LSPServerInner  { 
3435            interactor :  LspInteractor :: new ( client,  document_database. clone ( ) ) , 
3536            query_executor :  QueryExecutor :: new ( document_database. clone ( ) ) , 
36-             component_factory :  None ,  // to be initialized in the initialize method of the LSP 
37+             component_factory, 
38+             components :  None , 
3739        } 
3840    } 
3941} 
4042
41- impl < C >  LSPServerInner < C > 
43+ impl < C ,   F :   ComponentFactory >  LSPServerInner < C ,   F > 
4244where 
4345    C :  LSPClient  + Send  + Sync  + ' static , 
4446{ 
45-     fn  update_component_factory ( & mut  self ,  config :  & Value )  -> Result < ( ) >  { 
47+     fn  update_components ( & mut  self ,  config :  & Value )  -> Result < ( ) >  { 
4648        let  config = serde_json:: from_value :: < Config > ( config. clone ( ) ) . map_err ( |e| { 
4749            Error :: internal_error ( ) 
4850                . with_message ( format ! ( "unable to transform json into config: {e}" ) ) 
4951        } ) ?; 
5052
5153        debug ! ( "updating with configuration: {config:?}" ) ; 
5254
53-         let  factory  = ComponentFactory :: new ( config) ?; 
54-         self . component_factory . replace ( factory ) ; 
55+         let  components  = self . component_factory . create_components ( config) ?; 
56+         self . components . replace ( components ) ; 
5557
5658        debug ! ( "updated configuration" ) ; 
5759        Ok ( ( ) ) 
5860    } 
5961} 
6062
61- impl < C >  LSPServerInner < C > 
63+ impl < C ,   F :   ComponentFactory >  LSPServerInner < C ,   F > 
6264where 
6365    C :  LSPClient  + Send  + Sync  + ' static , 
6466{ 
8890            } ) ; 
8991        } ; 
9092
91-         self . update_component_factory ( & config) ?; 
93+         self . update_components ( & config) ?; 
9294
9395        Ok ( InitializeResult  { 
9496            capabilities :  ServerCapabilities  { 
@@ -117,7 +119,7 @@ where
117119    } 
118120
119121    pub  async  fn  did_change_configuration ( & mut  self ,  params :  DidChangeConfigurationParams )  { 
120-         let  _ = self . update_component_factory ( & params. settings ) ; 
122+         let  _ = self . update_components ( & params. settings ) ; 
121123    } 
122124
123125    pub  async  fn  did_open ( & self ,  params :  DidOpenTextDocumentParams )  { 
@@ -162,31 +164,38 @@ where
162164        Ok ( Some ( code_lenses) ) 
163165    } 
164166
167+     fn  components ( & self )  -> Result < & Components >  { 
168+         self . components 
169+             . as_ref ( ) 
170+             . ok_or_else ( || Error :: internal_error ( ) . with_message ( "LSP not initialized" ) ) 
171+     } 
172+ 
165173    async  fn  execute_base_image_scan ( 
166174        & self , 
167175        location :  tower_lsp:: lsp_types:: Location , 
168176        image :  String , 
169177    )  -> Result < ( ) >  { 
170-         let  factory = self 
171-             . component_factory 
172-             . as_ref ( ) 
173-             . ok_or_else ( || Error :: internal_error ( ) . with_message ( "LSP not initialized" ) ) ?; 
174-         let  image_scanner = factory. image_scanner ( ) ; 
175-         ScanBaseImageCommand :: new ( image_scanner,  & self . interactor ,  location,  image) 
176-             . execute ( ) 
177-             . await 
178+         let  components = self . components ( ) ?; 
179+         ScanBaseImageCommand :: new ( 
180+             components. scanner . as_ref ( ) , 
181+             & self . interactor , 
182+             location, 
183+             image, 
184+         ) 
185+         . execute ( ) 
186+         . await 
178187    } 
179188
180189    async  fn  execute_build_and_scan ( & self ,  location :  tower_lsp:: lsp_types:: Location )  -> Result < ( ) >  { 
181-         let  factory  = self 
182-              . component_factory 
183-             . as_ref ( ) 
184-             . ok_or_else ( ||  Error :: internal_error ( ) . with_message ( "LSP not initialized" ) ) ? ; 
185-         let  image_scanner = factory . image_scanner ( ) ; 
186-         let  image_builder = factory . image_builder ( ) ; 
187-         BuildAndScanCommand :: new ( image_builder ,  image_scanner ,   & self . interactor ,  location ) 
188-              . execute ( ) 
189-              . await 
190+         let  components  = self . components ( ) ? ; 
191+         BuildAndScanCommand :: new ( 
192+             components . builder . as_ref ( ) , 
193+             components . scanner . as_ref ( ) , 
194+              & self . interactor , 
195+             location , 
196+         ) 
197+         . execute ( ) 
198+         . await 
190199    } 
191200
192201    async  fn  handle_command_error ( & self ,  command_name :  & str ,  e :  Error )  -> Error  { 
0 commit comments