@@ -7,7 +7,7 @@ use tower_lsp::jsonrpc::Result;
77use tower_lsp:: lsp_types:: * ;
88use tower_lsp:: { Client , LanguageServer , LspService , Server } ;
99mod utils;
10- use utils:: { convert_severity, get_root_path, slashify_path , normalized_slash_path } ;
10+ use utils:: { convert_severity, get_root_path, normalized_slash_path , slashify_path } ;
1111mod affected_files_store;
1212use affected_files_store:: AffectedFilesStore ;
1313
@@ -30,7 +30,7 @@ impl LanguageServer for Backend {
3030 self . client
3131 . log_message ( MessageType :: INFO , "Foundry server initializing!" )
3232 . await ;
33- if let Some ( root_path) = get_root_path ( params. clone ( ) ) {
33+ if let Some ( root_path) = get_root_path ( params. clone ( ) ) {
3434 self . client
3535 . log_message (
3636 MessageType :: INFO ,
@@ -73,7 +73,8 @@ impl LanguageServer for Backend {
7373 format ! ( "file opened!: {:}" , params. text_document. uri) ,
7474 )
7575 . await ;
76- let _ = self . compile ( normalized_slash_path ( params. text_document . uri . path ( ) ) )
76+ let _ = self
77+ . compile ( normalized_slash_path ( params. text_document . uri . path ( ) ) )
7778 . await ;
7879 }
7980
@@ -84,7 +85,8 @@ impl LanguageServer for Backend {
8485 format ! ( "file changed!: {:}" , params. text_document. uri) ,
8586 )
8687 . await ;
87- let _ = self . compile ( normalized_slash_path ( params. text_document . uri . path ( ) ) )
88+ let _ = self
89+ . compile ( normalized_slash_path ( params. text_document . uri . path ( ) ) )
8890 . await ;
8991 }
9092
@@ -158,7 +160,7 @@ impl Backend {
158160 . unwrap ( )
159161 . to_string ( ) ;
160162 self . load_workspace ( folder_path) . await ?
161- }
163+ }
162164 Ok ( ( ) )
163165 }
164166
@@ -207,10 +209,11 @@ impl Backend {
207209
208210 for error in output. get_errors ( ) {
209211 // Generate diagnostic from compilation error
210- let ( affected_file, diagnostic) = match self . extract_diagnostic ( & error, & project_path) . await {
211- Some ( diagnostic) => diagnostic,
212- None => continue ,
213- } ;
212+ let ( affected_file, diagnostic) =
213+ match self . extract_diagnostic ( error, & project_path) . await {
214+ Some ( diagnostic) => diagnostic,
215+ None => continue ,
216+ } ;
214217
215218 // Add diagnostic to the hashmap
216219 let url = match affected_file. to_str ( ) {
@@ -224,14 +227,20 @@ impl Backend {
224227 }
225228 }
226229
227- self . reset_not_affected_files ( project_path, filepath, & raised_diagnostics) . await ;
230+ self . reset_not_affected_files ( project_path, filepath, & raised_diagnostics)
231+ . await ;
228232 for ( uri, diags) in raised_diagnostics. iter ( ) {
229233 if let Ok ( url) = Url :: parse ( & format ! ( "file://{}" , & uri) ) {
230234 self . client
231- . publish_diagnostics ( url, diags. clone ( ) , None )
232- . await ;
235+ . publish_diagnostics ( url, diags. clone ( ) , None )
236+ . await ;
233237 } else {
234- self . client . log_message ( MessageType :: ERROR , format ! ( "error, cannot parse file uri : {}" , uri) ) . await ;
238+ self . client
239+ . log_message (
240+ MessageType :: ERROR ,
241+ format ! ( "error, cannot parse file uri : {}" , uri) ,
242+ )
243+ . await ;
235244 }
236245 }
237246 }
@@ -243,13 +252,19 @@ impl Backend {
243252 * @returns {Option<(PathBuf, Diagnostic)>} Diagnostic
244253 * @returns {None} If the diagnostic cannot be extracted
245254 */
246- async fn extract_diagnostic ( & self , compilation_error : & CompilationError , project_path : & str ) -> Option < ( PathBuf , Diagnostic ) > {
255+ async fn extract_diagnostic (
256+ & self ,
257+ compilation_error : & CompilationError ,
258+ project_path : & str ,
259+ ) -> Option < ( PathBuf , Diagnostic ) > {
247260 eprintln ! ( "Compilation error: {:?}" , compilation_error) ;
248- let ( source_content_filepath, range) =
249- match self . extract_diagnostic_range ( & project_path, compilation_error) . await {
250- Some ( ( source_content_filepath, range) ) => ( source_content_filepath, range) ,
251- None => return None ,
252- } ;
261+ let ( source_content_filepath, range) = match self
262+ . extract_diagnostic_range ( project_path, compilation_error)
263+ . await
264+ {
265+ Some ( ( source_content_filepath, range) ) => ( source_content_filepath, range) ,
266+ None => return None ,
267+ } ;
253268 let diagnostic = Diagnostic {
254269 range : Range {
255270 start : Position {
@@ -294,8 +309,11 @@ impl Backend {
294309 }
295310 None => {
296311 self . client
297- . log_message ( MessageType :: ERROR , format ! ( "error, cannot get filepath: {:?}" , error) )
298- . await ;
312+ . log_message (
313+ MessageType :: ERROR ,
314+ format ! ( "error, cannot get filepath: {:?}" , error) ,
315+ )
316+ . await ;
299317 return None ;
300318 }
301319 } ;
@@ -347,7 +365,9 @@ impl Backend {
347365 . affected_files
348366 . add_project_file ( project_path. clone ( ) , filepath. clone ( ) ) ;
349367 let raised_files = raised_diagnostics. keys ( ) . cloned ( ) . collect :: < Vec < String > > ( ) ;
350- let without_diagnostics = state. affected_files . fill_affected_files ( raised_files, & project_path) ;
368+ let without_diagnostics = state
369+ . affected_files
370+ . fill_affected_files ( raised_files, & project_path) ;
351371
352372 self . client
353373 . log_message (
@@ -358,15 +378,16 @@ impl Backend {
358378
359379 for file in without_diagnostics. iter ( ) {
360380 if let Ok ( url) = Url :: parse ( & format ! ( "file://{}" , & file) ) {
381+ self . client . publish_diagnostics ( url, vec ! [ ] , None ) . await ;
382+ } else {
361383 self . client
362- . publish_diagnostics ( url, vec ! [ ] , None )
384+ . log_message (
385+ MessageType :: ERROR ,
386+ format ! ( "error, cannot parse file uri : {}" , file) ,
387+ )
363388 . await ;
364- } else {
365- self . client . log_message ( MessageType :: ERROR , format ! ( "error, cannot parse file uri : {}" , file) ) . await ;
366389 }
367390 }
368-
369-
370391 }
371392}
372393
0 commit comments