@@ -415,54 +415,11 @@ def debug_parser(args):
415
415
The arguments parsed from the `ArgumentParser`
416
416
"""
417
417
418
- def locate_config (root : str ) -> str | None :
419
- default_conf_files = [args .config , ".fortlsrc" , ".fortls.json5" , ".fortls" ]
420
- present_conf_files = [
421
- os .path .isfile (os .path .join (root , f )) for f in default_conf_files
422
- ]
423
- if not any (present_conf_files ):
424
- return None
425
-
426
- # Load the first config file found
427
- for f , present in zip (default_conf_files , present_conf_files ):
428
- if not present :
429
- continue
430
- config_path = os .path .join (root , f )
431
- return config_path
432
-
433
- def read_config (root : str | None ):
434
- pp_suffixes = None
435
- pp_defs = {}
436
- include_dirs = set ()
437
- if root is None :
438
- return pp_suffixes , pp_defs , include_dirs
439
-
440
- # Check for config files
441
- config_path = locate_config (root )
442
- print (f" Config file = { config_path } " )
443
- if config_path is None or not os .path .isfile (config_path ):
444
- return pp_suffixes , pp_defs , include_dirs
445
-
446
- try :
447
- with open (config_path , encoding = "utf-8" ) as fhandle :
448
- config_dict = json5 .load (fhandle )
449
- pp_suffixes = config_dict .get ("pp_suffixes" , None )
450
- pp_defs = config_dict .get ("pp_defs" , {})
451
- for path in config_dict .get ("include_dirs" , set ()):
452
- include_dirs .update (only_dirs (resolve_globs (path , root )))
453
-
454
- if isinstance (pp_defs , list ):
455
- pp_defs = {key : "" for key in pp_defs }
456
- except ValueError as e :
457
- print (f"Error { e } while parsing '{ config_path } ' settings file" )
458
-
459
- return pp_suffixes , pp_defs , include_dirs
460
-
461
418
print ("\n Testing parser" )
462
419
separator ()
463
420
464
421
ensure_file_accessible (args .debug_filepath )
465
- pp_suffixes , pp_defs , include_dirs = read_config (args .debug_rootpath )
422
+ pp_suffixes , pp_defs , include_dirs = read_config (args .debug_rootpath , args . config )
466
423
467
424
print (f' File = "{ args .debug_filepath } "' )
468
425
file_obj = FortranFile (args .debug_filepath , pp_suffixes )
@@ -500,6 +457,51 @@ def check_request_params(args, loc_needed=True):
500
457
print (f" Char = { args .debug_char } \n " )
501
458
502
459
460
+ def locate_config (root : str , input_config : str ) -> str | None :
461
+ default_conf_files = [input_config , ".fortlsrc" , ".fortls.json5" , ".fortls" ]
462
+ present_conf_files = [
463
+ os .path .isfile (os .path .join (root , f )) for f in default_conf_files
464
+ ]
465
+ if not any (present_conf_files ):
466
+ return None
467
+
468
+ # Load the first config file found
469
+ for f , present in zip (default_conf_files , present_conf_files ):
470
+ if not present :
471
+ continue
472
+ config_path = os .path .join (root , f )
473
+ return config_path
474
+
475
+
476
+ def read_config (root : str | None , input_config : str ):
477
+ pp_suffixes = None
478
+ pp_defs = {}
479
+ include_dirs = set ()
480
+ if root is None :
481
+ return pp_suffixes , pp_defs , include_dirs
482
+
483
+ # Check for config files
484
+ config_path = locate_config (root , input_config )
485
+ print (f" Config file = { config_path } " )
486
+ if config_path is None or not os .path .isfile (config_path ):
487
+ return pp_suffixes , pp_defs , include_dirs
488
+
489
+ try :
490
+ with open (config_path , encoding = "utf-8" ) as fhandle :
491
+ config_dict = json5 .load (fhandle )
492
+ pp_suffixes = config_dict .get ("pp_suffixes" , None )
493
+ pp_defs = config_dict .get ("pp_defs" , {})
494
+ for path in config_dict .get ("include_dirs" , set ()):
495
+ include_dirs .update (only_dirs (resolve_globs (path , root )))
496
+
497
+ if isinstance (pp_defs , list ):
498
+ pp_defs = {key : "" for key in pp_defs }
499
+ except ValueError as e :
500
+ print (f"Error { e } while parsing '{ config_path } ' settings file" )
501
+
502
+ return pp_suffixes , pp_defs , include_dirs
503
+
504
+
503
505
def debug_generic (args , test_label , lsp_request , format_results , loc_needed = True ):
504
506
print (f'\n Testing "{ test_label } " request:' )
505
507
check_request_params (args , loc_needed )
0 commit comments