@@ -21,7 +21,6 @@ with Ada.Characters.Latin_1;
21
21
with Ada.Text_IO ;
22
22
with Ada.Exceptions ; use Ada.Exceptions;
23
23
with Ada.Strings.Unbounded ;
24
- with GNAT.Command_Line ; use GNAT.Command_Line;
25
24
with GNAT.Traceback.Symbolic ; use GNAT.Traceback.Symbolic;
26
25
with GNAT.OS_Lib ;
27
26
with GNAT.Strings ;
@@ -31,8 +30,10 @@ with System.Soft_Links;
31
30
with System.Secondary_Stack ;
32
31
33
32
with VSS.Application ;
33
+ with VSS.Command_Line ;
34
34
with VSS.Standard_Paths ;
35
35
with VSS.Strings.Conversions ;
36
+ with VSS.Text_Streams.Standadrs ;
36
37
37
38
with GNATCOLL.JSON ;
38
39
with GNATCOLL.Memory ; use GNATCOLL.Memory;
@@ -82,6 +83,9 @@ procedure LSP.Ada_Driver is
82
83
-- Quit the process when an uncaught exception reaches this. Used for
83
84
-- fuzzing.
84
85
86
+ procedure Print_Help (Option : VSS.Command_Line.Named_Option'Class);
87
+ -- Put option description to stdout
88
+
85
89
Server_Trace : constant Trace_Handle := Create (" ALS.MAIN" , From_Config);
86
90
-- Main trace for the LSP.
87
91
@@ -130,6 +134,31 @@ procedure LSP.Ada_Driver is
130
134
GNAT.OS_Lib.OS_Exit (42 );
131
135
end Die_On_Uncaught ;
132
136
137
+ -- --------------
138
+ -- Print_Help --
139
+ -- --------------
140
+
141
+ procedure Print_Help (Option : VSS.Command_Line.Named_Option'Class) is
142
+ use type VSS.Strings.Character_Count;
143
+ Ok : Boolean := True;
144
+ Output : VSS.Text_Streams.Output_Text_Stream'Class :=
145
+ VSS.Text_Streams.Standadrs.Standard_Output;
146
+ Last : VSS.Strings.Character_Count :=
147
+ 3 + Option.Long_Name.Character_Length;
148
+ begin
149
+ Output.Put (" --" , Ok);
150
+ Output.Put (Option.Long_Name, Ok);
151
+ if Option in VSS.Command_Line.Value_Option'Class then
152
+ Output.Put (" =ARG" , Ok);
153
+ Last := Last + 4 ;
154
+ end if ;
155
+
156
+ for J in Last + 1 .. 17 loop
157
+ Output.Put (' ' , Ok);
158
+ end loop ;
159
+ Output.Put_Line (Option.Description, Ok);
160
+ end Print_Help ;
161
+
133
162
-- ---------------------
134
163
-- Register_Commands --
135
164
-- ---------------------
@@ -173,9 +202,7 @@ procedure LSP.Ada_Driver is
173
202
Command'Tag);
174
203
end Register_Commands ;
175
204
176
- use GNAT.Strings;
177
-
178
- Cmdline : Command_Line_Configuration;
205
+ use type VSS.Strings.Virtual_String;
179
206
180
207
Fuzzing_Activated : constant Boolean :=
181
208
not VSS.Application.System_Environment.Value (" ALS_FUZZING" ).Is_Empty;
@@ -198,64 +225,68 @@ procedure LSP.Ada_Driver is
198
225
GNATdebug : constant Virtual_File := Create_From_Base
199
226
(" .gnatdebug" );
200
227
201
- Traces_File_Path : aliased String_Access;
202
- Config_File_Path : aliased String_Access;
203
- Traces_File : Virtual_File;
228
+ Trace_File_Option : constant VSS.Command_Line.Value_Option :=
229
+ (Short_Name => " " ,
230
+ Long_Name => " tracefile" ,
231
+ Description => " Full path to a file containing traces configuration" ,
232
+ Value_Name => " ARG" );
233
+
234
+ Config_Description : constant VSS.Strings.Virtual_String :=
235
+ " Full path to a JSON file containing initialization "
236
+ & " options for the server (i.e: all the settings that can be specified "
237
+ & " through LSP 'initialize' request's initializattionOptions)" ;
238
+
239
+ Config_File_Option : constant VSS.Command_Line.Value_Option :=
240
+ (Short_Name => " " ,
241
+ Long_Name => " config" ,
242
+ Description => Config_Description,
243
+ Value_Name => " ARG" );
244
+
245
+ Language_GPR_Option : constant VSS.Command_Line.Binary_Option :=
246
+ (Short_Name => " " ,
247
+ Long_Name => " language-gpr" ,
248
+ Description => " Handle GPR language instead of Ada" );
249
+
250
+ Version_Option : constant VSS.Command_Line.Binary_Option :=
251
+ (Short_Name => " " ,
252
+ Long_Name => " version" ,
253
+ Description => " Display the program version" );
254
+
255
+ Help_Option : constant VSS.Command_Line.Binary_Option :=
256
+ (Short_Name => " " ,
257
+ Long_Name => " help" ,
258
+ Description => " Display this help" );
259
+
204
260
Config_File : Virtual_File;
205
- Help_Arg : aliased Boolean := False;
206
- Version_Arg : aliased Boolean := False;
207
- Language_GPR_Arg : aliased Boolean := False;
208
261
209
262
Memory_Monitor_Enabled : Boolean;
210
263
begin
211
264
-- Handle the command line
212
- Set_Usage
213
- (Cmdline,
214
- Help => " Command line interface for the Ada Language Server" );
215
-
216
- Define_Switch
217
- (Cmdline,
218
- Output => Traces_File_Path'Access ,
219
- Long_Switch => " --tracefile=" ,
220
- Help => " Full path to a file containing traces configuration" );
221
-
222
- Define_Switch
223
- (Cmdline,
224
- Output => Config_File_Path'Access ,
225
- Long_Switch => " --config=" ,
226
- Help => " Full path to a JSON file containing initialization "
227
- & " options for the server (i.e: all the settings that can be specified "
228
- & " through LSP 'initialize' request's initializattionOptions)" );
229
-
230
- Define_Switch
231
- (Cmdline,
232
- Output => Language_GPR_Arg'Access ,
233
- Long_Switch => " --language-gpr" ,
234
- Help => " Handle GPR language instead of Ada" );
235
-
236
- Define_Switch
237
- (Cmdline,
238
- Output => Version_Arg'Access ,
239
- Long_Switch => " --version" ,
240
- Help => " Display the program version" );
241
-
242
- Define_Switch
243
- (Cmdline,
244
- Output => Help_Arg'Access ,
245
- Long_Switch => " --help" ,
246
- Help => " Display this help" );
247
-
248
- begin
249
- Getopt (Cmdline);
250
- exception
251
- when GNAT.Command_Line.Exit_From_Command_Line =>
252
- Free (Cmdline);
253
- GNAT.OS_Lib.OS_Exit (0 );
254
- end ;
255
-
256
- Free (Cmdline);
265
+ -- Help => "Command line interface for the Ada Language Server");
266
+
267
+ VSS.Command_Line.Add_Option (Trace_File_Option);
268
+ VSS.Command_Line.Add_Option (Config_File_Option);
269
+ VSS.Command_Line.Add_Option (Language_GPR_Option);
270
+ VSS.Command_Line.Add_Option (Version_Option);
271
+ VSS.Command_Line.Add_Option (Help_Option);
272
+ VSS.Command_Line.Process; -- Will exit if errors
273
+
274
+ if VSS.Command_Line.Is_Specified (Help_Option) then
275
+ Ada.Text_IO.Put_Line
276
+ (" Language Server Ada and SPARK." );
277
+ -- TBD: Print list of options using VSS
278
+ Ada.Text_IO.Put_Line
279
+ (" Usage: ada_language_server [switches] [arguments]" );
280
+ Ada.Text_IO.New_Line;
281
+
282
+ Print_Help (Trace_File_Option);
283
+ Print_Help (Config_File_Option);
284
+ Print_Help (Language_GPR_Option);
285
+ Print_Help (Version_Option);
286
+ Print_Help (Help_Option);
257
287
258
- if Version_Arg then
288
+ GNAT.OS_Lib.OS_Exit (0 );
289
+ elsif VSS.Command_Line.Is_Specified (Version_Option) then
259
290
Ada.Text_IO.Put_Line (" ALS version: " & $VERSION);
260
291
GNAT.OS_Lib.OS_Exit (0 );
261
292
end if ;
@@ -264,16 +295,19 @@ begin
264
295
-- - passed on the command line via --tracefile,
265
296
-- - in a .gnatdebug file locally
266
297
-- - in "traces.cfg" in the ALS home directory
267
- if Traces_File_Path /= null
268
- and then Traces_File_Path.all /= " "
269
- then
270
- Traces_File := Create (+Traces_File_Path.all );
271
- if not Traces_File.Is_Regular_File then
272
- Ada.Text_IO.Put_Line (" Could not find the specified traces file" );
273
- GNAT.OS_Lib.OS_Exit (1 );
274
- end if ;
275
- Parse_Config_File (Traces_File);
298
+ if VSS.Command_Line.Is_Specified (Trace_File_Option) then
299
+ declare
300
+ Traces_File : constant Virtual_File := Create_From_UTF8
301
+ (VSS.Strings.Conversions.To_UTF_8_String
302
+ (VSS.Command_Line.Value (Trace_File_Option)));
303
+ begin
304
+ if not Traces_File.Is_Regular_File then
305
+ Ada.Text_IO.Put_Line (" Could not find the specified traces file" );
306
+ GNAT.OS_Lib.OS_Exit (1 );
307
+ end if ;
276
308
309
+ Parse_Config_File (Traces_File);
310
+ end ;
277
311
elsif GNATdebug.Is_Regular_File then
278
312
Parse_Config_File (GNATdebug);
279
313
@@ -289,19 +323,14 @@ begin
289
323
" .$T.$$.log:buffer_size=0" );
290
324
end if ;
291
325
292
- if Traces_File_Path /= null then
293
- Free (Traces_File_Path);
294
- end if ;
295
-
296
326
-- Look for a config file, that contains the configuration for the server
297
327
-- (i.e: the configuration that can be specified through the 'initialize'
298
328
-- request initializationOptions).
299
329
300
- if Config_File_Path /= null
301
- and then Config_File_Path.all /= " "
302
- then
303
- Config_File := Create (+Config_File_Path.all );
304
-
330
+ if VSS.Command_Line.Is_Specified (Config_File_Option) then
331
+ Config_File := Create_From_UTF8
332
+ (VSS.Strings.Conversions.To_UTF_8_String
333
+ (VSS.Command_Line.Value (Config_File_Option)));
305
334
if not Config_File.Is_Regular_File then
306
335
Ada.Text_IO.Put_Line (" Could not find the specified config file" );
307
336
GNAT.OS_Lib.OS_Exit (1 );
@@ -327,8 +356,6 @@ begin
327
356
328
357
Ada_Handler.Change_Configuration (Parse_Result.Value);
329
358
end ;
330
-
331
- Free (Config_File_Path);
332
359
end if ;
333
360
334
361
Server_Trace.Trace (" ALS version: " & $VERSION);
@@ -347,7 +374,7 @@ begin
347
374
GNATCOLL.Memory.Configure (Activate_Monitor => True);
348
375
end if ;
349
376
350
- if not Language_GPR_Arg then
377
+ if not VSS.Command_Line.Is_Specified (Language_GPR_Option) then
351
378
-- Load predefined completion items
352
379
LSP.Predefined_Completion.Load_Predefined_Completion_Db (Server_Trace);
353
380
Register_Commands;
@@ -356,7 +383,7 @@ begin
356
383
Server.Initialize (Stream'Unchecked_Access);
357
384
358
385
begin
359
- if Language_GPR_Arg then
386
+ if VSS.Command_Line.Is_Specified (Language_GPR_Option) then
360
387
Server.Run
361
388
(GPR_Handler'Unchecked_Access,
362
389
GPR_Handler'Unchecked_Access,
0 commit comments