@@ -26,6 +26,7 @@ def main():
26
26
if args .version :
27
27
print ("{0}" .format (__version__ ))
28
28
sys .exit (0 )
29
+
29
30
debug_server = (
30
31
args .debug_diagnostics
31
32
or args .debug_symbols
@@ -35,14 +36,14 @@ def main():
35
36
or args .debug_hover
36
37
or args .debug_implementation
37
38
or args .debug_references
38
- or ( args .debug_rename is not None )
39
+ or args .debug_rename
39
40
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
42
43
)
43
- #
44
+
44
45
settings = set_settings (args )
45
- #
46
+
46
47
if args .debug_parser :
47
48
debug_server_parser (args )
48
49
@@ -58,18 +59,26 @@ def main():
58
59
).run ()
59
60
60
61
61
- def parse_args ():
62
+ def parse_args () -> argparse . Namespace :
62
63
"""Parses the command line arguments to the Language Server
63
64
64
65
Returns
65
66
-------
66
- Namespace
67
+ argparse. Namespace
67
68
command line arguments
68
69
"""
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
+
71
77
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" ,
73
82
)
74
83
parser .add_argument (
75
84
"--config" , type = str , default = ".fortls" , help = "Configuration options file"
@@ -92,7 +101,6 @@ def parse_args():
92
101
)
93
102
parser .add_argument (
94
103
"--incremental_sync" ,
95
- "--incrmental_sync" ,
96
104
action = "store_true" ,
97
105
help = "Use incremental document synchronization (beta)" ,
98
106
)
@@ -178,87 +186,131 @@ def parse_args():
178
186
action = "store_true" ,
179
187
help = "Generate debug log in project root folder" ,
180
188
)
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
+ )
182
229
group .add_argument (
183
230
"--debug_parser" ,
184
231
action = "store_true" ,
185
- help = "Test source code parser on specified file" ,
232
+ help = hide_opt ( "Test source code parser on specified file" ) ,
186
233
)
187
234
group .add_argument (
188
235
"--debug_diagnostics" ,
189
236
action = "store_true" ,
190
- help = "Test diagnostic notifications for specified file" ,
237
+ help = hide_opt ( "Test diagnostic notifications for specified file" ) ,
191
238
)
192
239
group .add_argument (
193
240
"--debug_symbols" ,
194
241
action = "store_true" ,
195
- help = "Test symbol request for specified file" ,
242
+ help = hide_opt ( "Test symbol request for specified file" ) ,
196
243
)
197
244
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" ),
199
248
)
200
249
group .add_argument (
201
250
"--debug_completion" ,
202
251
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" ) ,
204
253
)
205
254
group .add_argument (
206
255
"--debug_signature" ,
207
256
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" ) ,
209
258
)
210
259
group .add_argument (
211
260
"--debug_definition" ,
212
261
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" ) ,
214
263
)
215
264
group .add_argument (
216
265
"--debug_hover" ,
217
266
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" ) ,
219
268
)
220
269
group .add_argument (
221
270
"--debug_implementation" ,
222
271
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" ) ,
224
273
)
225
274
group .add_argument (
226
275
"--debug_references" ,
227
276
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" ) ,
229
278
)
230
279
group .add_argument (
231
280
"--debug_rename" ,
232
281
type = str ,
233
- help = "Test rename request for specified file and position" ,
282
+ help = hide_opt ( "Test rename request for specified file and position" ) ,
234
283
)
235
284
group .add_argument (
236
285
"--debug_actions" ,
237
286
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" ) ,
239
288
)
240
289
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" ),
242
293
)
243
294
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" ),
245
298
)
246
299
group .add_argument (
247
300
"--debug_line" ,
248
301
type = int ,
249
- help = "Line position for language server tests (1-indexed)" ,
302
+ help = hide_opt ( "Line position for language server tests (1-indexed)" ) ,
250
303
)
251
304
group .add_argument (
252
305
"--debug_char" ,
253
306
type = int ,
254
- help = "Character position for language server tests (1-indexed)" ,
307
+ help = hide_opt ( "Character position for language server tests (1-indexed)" ) ,
255
308
)
256
309
group .add_argument (
257
310
"--debug_full_result" ,
258
311
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" ) ,
260
313
)
261
- return parser .parse_args ()
262
314
263
315
264
316
def set_settings (args ):
0 commit comments