@@ -26,6 +26,7 @@ def main():
2626 if args .version :
2727 print ("{0}" .format (__version__ ))
2828 sys .exit (0 )
29+
2930 debug_server = (
3031 args .debug_diagnostics
3132 or args .debug_symbols
@@ -35,14 +36,14 @@ def main():
3536 or args .debug_hover
3637 or args .debug_implementation
3738 or args .debug_references
38- or ( args .debug_rename is not None )
39+ or args .debug_rename
3940 or args .debug_actions
40- or ( args .debug_rootpath is not None )
41- or ( args .debug_workspace_symbols is not None )
41+ or args .debug_rootpath
42+ or args .debug_workspace_symbols
4243 )
43- #
44+
4445 settings = set_settings (args )
45- #
46+
4647 if args .debug_parser :
4748 debug_server_parser (args )
4849
@@ -58,18 +59,26 @@ def main():
5859 ).run ()
5960
6061
61- def parse_args ():
62+ def parse_args () -> argparse . Namespace :
6263 """Parses the command line arguments to the Language Server
6364
6465 Returns
6566 -------
66- Namespace
67+ argparse. Namespace
6768 command line arguments
6869 """
69- parser = argparse .ArgumentParser ()
70- parser .description = "fortls ({0})" .format (__version__ )
70+
71+ parser = argparse .ArgumentParser (
72+ description = f"fortls { __version__ } " ,
73+ prog = __name__ ,
74+ usage = "%(prog)s [options] [debug options]" ,
75+ )
76+
7177 parser .add_argument (
72- "--version" , action = "store_true" , help = "Print server version number and exit"
78+ "-v" ,
79+ "--version" ,
80+ action = "store_true" ,
81+ help = "Print server version number and exit" ,
7382 )
7483 parser .add_argument (
7584 "--config" , type = str , default = ".fortls" , help = "Configuration options file"
@@ -92,7 +101,6 @@ def parse_args():
92101 )
93102 parser .add_argument (
94103 "--incremental_sync" ,
95- "--incrmental_sync" ,
96104 action = "store_true" ,
97105 help = "Use incremental document synchronization (beta)" ,
98106 )
@@ -178,87 +186,131 @@ def parse_args():
178186 action = "store_true" ,
179187 help = "Generate debug log in project root folder" ,
180188 )
181- group = parser .add_argument_group ("DEBUG" , "Options for debugging language server" )
189+ parser .add_argument (
190+ "--debug_help" , action = "help" , help = "Display options for debugging fortls"
191+ )
192+
193+ # By default debug arguments are hidden
194+ parse_debug_args (parser )
195+
196+ return parser .parse_args ()
197+
198+
199+ def parse_debug_args (parser : argparse .ArgumentParser ) -> None :
200+ """Parse the debug arguments if any are present.
201+ if none are present the arguments are suppressed in the help menu
202+
203+ Parameters
204+ ----------
205+ parser : argparse.ArgumentParser
206+ an argument parser
207+
208+ Returns
209+ -------
210+ None
211+ Operates and updates the parser
212+ """
213+
214+ # Only show debug options if an argument starting with --debug_ was input.
215+ # if suppressed the option will be hidden from the help menu.
216+ HIDE_DEBUG = True
217+ if any ("--debug_" in arg for arg in sys .argv ):
218+ HIDE_DEBUG = False
219+
220+ def hide_opt (help : str ) -> str :
221+ if not HIDE_DEBUG :
222+ return help
223+ else :
224+ return argparse .SUPPRESS
225+
226+ group = parser .add_argument_group (
227+ hide_opt ("DEBUG" ), hide_opt ("Options for debugging language server" )
228+ )
182229 group .add_argument (
183230 "--debug_parser" ,
184231 action = "store_true" ,
185- help = "Test source code parser on specified file" ,
232+ help = hide_opt ( "Test source code parser on specified file" ) ,
186233 )
187234 group .add_argument (
188235 "--debug_diagnostics" ,
189236 action = "store_true" ,
190- help = "Test diagnostic notifications for specified file" ,
237+ help = hide_opt ( "Test diagnostic notifications for specified file" ) ,
191238 )
192239 group .add_argument (
193240 "--debug_symbols" ,
194241 action = "store_true" ,
195- help = "Test symbol request for specified file" ,
242+ help = hide_opt ( "Test symbol request for specified file" ) ,
196243 )
197244 group .add_argument (
198- "--debug_workspace_symbols" , type = str , help = "Test workspace/symbol request"
245+ "--debug_workspace_symbols" ,
246+ type = str ,
247+ help = hide_opt ("Test workspace/symbol request" ),
199248 )
200249 group .add_argument (
201250 "--debug_completion" ,
202251 action = "store_true" ,
203- help = "Test completion request for specified file and position" ,
252+ help = hide_opt ( "Test completion request for specified file and position" ) ,
204253 )
205254 group .add_argument (
206255 "--debug_signature" ,
207256 action = "store_true" ,
208- help = "Test signatureHelp request for specified file and position" ,
257+ help = hide_opt ( "Test signatureHelp request for specified file and position" ) ,
209258 )
210259 group .add_argument (
211260 "--debug_definition" ,
212261 action = "store_true" ,
213- help = "Test definition request for specified file and position" ,
262+ help = hide_opt ( "Test definition request for specified file and position" ) ,
214263 )
215264 group .add_argument (
216265 "--debug_hover" ,
217266 action = "store_true" ,
218- help = "Test hover request for specified file and position" ,
267+ help = hide_opt ( "Test hover request for specified file and position" ) ,
219268 )
220269 group .add_argument (
221270 "--debug_implementation" ,
222271 action = "store_true" ,
223- help = "Test implementation request for specified file and position" ,
272+ help = hide_opt ( "Test implementation request for specified file and position" ) ,
224273 )
225274 group .add_argument (
226275 "--debug_references" ,
227276 action = "store_true" ,
228- help = "Test references request for specified file and position" ,
277+ help = hide_opt ( "Test references request for specified file and position" ) ,
229278 )
230279 group .add_argument (
231280 "--debug_rename" ,
232281 type = str ,
233- help = "Test rename request for specified file and position" ,
282+ help = hide_opt ( "Test rename request for specified file and position" ) ,
234283 )
235284 group .add_argument (
236285 "--debug_actions" ,
237286 action = "store_true" ,
238- help = "Test codeAction request for specified file and position" ,
287+ help = hide_opt ( "Test codeAction request for specified file and position" ) ,
239288 )
240289 group .add_argument (
241- "--debug_filepath" , type = str , help = "File path for language server tests"
290+ "--debug_filepath" ,
291+ type = str ,
292+ help = hide_opt ("File path for language server tests" ),
242293 )
243294 group .add_argument (
244- "--debug_rootpath" , type = str , help = "Root path for language server tests"
295+ "--debug_rootpath" ,
296+ type = str ,
297+ help = hide_opt ("Root path for language server tests" ),
245298 )
246299 group .add_argument (
247300 "--debug_line" ,
248301 type = int ,
249- help = "Line position for language server tests (1-indexed)" ,
302+ help = hide_opt ( "Line position for language server tests (1-indexed)" ) ,
250303 )
251304 group .add_argument (
252305 "--debug_char" ,
253306 type = int ,
254- help = "Character position for language server tests (1-indexed)" ,
307+ help = hide_opt ( "Character position for language server tests (1-indexed)" ) ,
255308 )
256309 group .add_argument (
257310 "--debug_full_result" ,
258311 action = "store_true" ,
259- help = "Print full result object instead of condensed version" ,
312+ help = hide_opt ( "Print full result object instead of condensed version" ) ,
260313 )
261- return parser .parse_args ()
262314
263315
264316def set_settings (args ):
0 commit comments