Skip to content

Commit a593ef6

Browse files
committed
Merge branch 'topic/master_edge_merge' into 'edge'
merge master into edge See merge request eng/ide/ada_language_server!1139
2 parents 66be0c8 + d02a358 commit a593ef6

File tree

8 files changed

+132
-55
lines changed

8 files changed

+132
-55
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The `ada_language_server` doesn't require any command line options,
9191
but it understands these options:
9292

9393
* `--tracefile=<FILE>` - Full path to a file containing traces configuration
94+
* `--config=<FILE>` - Full path to a JSON file containing the server's configuration
9495
* `--help` - Display supported command like options and exit.
9596

9697
You can turn some debugging and experimental features trought
@@ -99,7 +100,9 @@ You can turn some debugging and experimental features trought
99100
The server also gets configuration via `workspace/didChangeConfiguration`
100101
notification and `initializationOptions` of `initialize` request.
101102
See more [details here](doc/settings.md). Each LSP
102-
client provides its-own way to set such settings.
103+
client provides its-own way to set such settings. You can use the `--config`
104+
option if you want to provide the configuration directly via a JSON file
105+
instead of specifying it via the requests listed just above.
103106

104107
## Supported LSP Server Requests
105108

source/ada/lsp-ada_driver.adb

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
with Ada.Characters.Latin_1;
2121
with Ada.Text_IO;
2222
with Ada.Exceptions; use Ada.Exceptions;
23+
with Ada.Strings.Unbounded;
2324
with GNAT.Command_Line; use GNAT.Command_Line;
2425
with GNAT.Traceback.Symbolic; use GNAT.Traceback.Symbolic;
2526
with GNAT.OS_Lib;
@@ -33,9 +34,11 @@ with VSS.Application;
3334
with VSS.Standard_Paths;
3435
with VSS.Strings.Conversions;
3536

37+
with GNATCOLL.JSON;
3638
with GNATCOLL.Memory; use GNATCOLL.Memory;
3739
with GNATCOLL.Traces; use GNATCOLL.Traces;
3840
with GNATCOLL.VFS; use GNATCOLL.VFS;
41+
with GNATCOLL.Utils;
3942

4043
with LSP.Ada_Handlers;
4144
with LSP.Ada_Handlers.Named_Parameters_Commands;
@@ -195,7 +198,9 @@ procedure LSP.Ada_Driver is
195198
GNATdebug : constant Virtual_File := Create_From_Base
196199
(".gnatdebug");
197200

198-
Tracefile_Name : aliased String_Access;
201+
Traces_File_Path : aliased String_Access;
202+
Config_File_Path : aliased String_Access;
203+
Traces_File : Virtual_File;
199204
Config_File : Virtual_File;
200205
Help_Arg : aliased Boolean := False;
201206
Version_Arg : aliased Boolean := False;
@@ -210,10 +215,18 @@ begin
210215

211216
Define_Switch
212217
(Cmdline,
213-
Output => Tracefile_Name'Access,
218+
Output => Traces_File_Path'Access,
214219
Long_Switch => "--tracefile=",
215220
Help => "Full path to a file containing traces configuration");
216221

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+
217230
Define_Switch
218231
(Cmdline,
219232
Output => Language_GPR_Arg'Access,
@@ -251,15 +264,15 @@ begin
251264
-- - passed on the command line via --tracefile,
252265
-- - in a .gnatdebug file locally
253266
-- - in "traces.cfg" in the ALS home directory
254-
if Tracefile_Name /= null
255-
and then Tracefile_Name.all /= ""
267+
if Traces_File_Path /= null
268+
and then Traces_File_Path.all /= ""
256269
then
257-
Config_File := Create (+Tracefile_Name.all);
258-
if not Config_File.Is_Regular_File then
270+
Traces_File := Create (+Traces_File_Path.all);
271+
if not Traces_File.Is_Regular_File then
259272
Ada.Text_IO.Put_Line ("Could not find the specified traces file");
260273
GNAT.OS_Lib.OS_Exit (1);
261274
end if;
262-
Parse_Config_File (Config_File);
275+
Parse_Config_File (Traces_File);
263276

264277
elsif GNATdebug.Is_Regular_File then
265278
Parse_Config_File (GNATdebug);
@@ -276,8 +289,46 @@ begin
276289
".$T.$$.log:buffer_size=0");
277290
end if;
278291

279-
if Tracefile_Name /= null then
280-
Free (Tracefile_Name);
292+
if Traces_File_Path /= null then
293+
Free (Traces_File_Path);
294+
end if;
295+
296+
-- Look for a config file, that contains the configuration for the server
297+
-- (i.e: the configuration that can be specified through the 'initialize'
298+
-- request initializationOptions).
299+
300+
if Config_File_Path /= null
301+
and then Config_File_Path.all /= ""
302+
then
303+
Config_File := Create (+Config_File_Path.all);
304+
305+
if not Config_File.Is_Regular_File then
306+
Ada.Text_IO.Put_Line ("Could not find the specified config file");
307+
GNAT.OS_Lib.OS_Exit (1);
308+
end if;
309+
310+
declare
311+
JSON_Contents : GNAT.Strings.String_Access := Config_File.Read_File;
312+
Parse_Result : GNATCOLL.JSON.Read_Result;
313+
begin
314+
Parse_Result := GNATCOLL.JSON.Read (JSON_Contents.all);
315+
GNAT.Strings.Free (JSON_Contents);
316+
317+
if not Parse_Result.Success then
318+
Ada.Text_IO.Put_Line
319+
("Error when parsing config file at "
320+
& GNATCOLL.Utils.Image (Parse_Result.Error.Line, 1)
321+
& ":"
322+
& GNATCOLL.Utils.Image (Parse_Result.Error.Column, 1));
323+
Ada.Text_IO.Put_Line
324+
(Ada.Strings.Unbounded.To_String (Parse_Result.Error.Message));
325+
GNAT.OS_Lib.OS_Exit (1);
326+
end if;
327+
328+
Ada_Handler.Change_Configuration (Parse_Result.Value);
329+
end;
330+
331+
Free (Config_File_Path);
281332
end if;
282333

283334
Server_Trace.Trace ("ALS version: " & $VERSION);

source/ada/lsp-ada_handlers.adb

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
2727
with Ada.Unchecked_Deallocation;
2828

2929
with GNAT.OS_Lib; use GNAT.OS_Lib;
30-
with GNATCOLL.JSON;
3130
with GNATCOLL.Utils; use GNATCOLL.Utils;
3231

3332
with GPR2.Containers;
@@ -325,11 +324,6 @@ package body LSP.Ada_Handlers is
325324
-- Attempt to load the given project file, with the scenario provided.
326325
-- This unloads all currently loaded project contexts.
327326

328-
procedure Change_Configuration
329-
(Self : access Message_Handler;
330-
Ada : LSP.Types.LSP_Any);
331-
-- Change server configuration with settings from Ada JSON object.
332-
333327
procedure Mark_Source_Files_For_Indexing (Self : access Message_Handler);
334328
-- Mark all sources in all projects for indexing. This factorizes code
335329
-- between Load_Project and Load_Implicit_Project.
@@ -4225,8 +4219,8 @@ package body LSP.Ada_Handlers is
42254219
--------------------------
42264220

42274221
procedure Change_Configuration
4228-
(Self : access Message_Handler;
4229-
Ada : LSP.Types.LSP_Any)
4222+
(Self : access Message_Handler;
4223+
Options : GNATCOLL.JSON.JSON_Value'Class)
42304224
is
42314225
use type GNATCOLL.JSON.JSON_Value_Type;
42324226

@@ -4266,9 +4260,9 @@ package body LSP.Ada_Handlers is
42664260
Variables : Scenario_Variable_List;
42674261

42684262
function Property (Name : String) return VSS.Strings.Virtual_String is
4269-
(if Ada.Has_Field (Name)
4263+
(if Options.Has_Field (Name)
42704264
then VSS.Strings.Conversions.To_Virtual_String
4271-
(String'(Get (Get (Ada, Name))))
4265+
(String'(Options.Get (Name)))
42724266
else VSS.Strings.Empty_Virtual_String);
42734267

42744268
------------------
@@ -4300,7 +4294,7 @@ package body LSP.Ada_Handlers is
43004294
Value.dynamicRegistration.Is_Set = True;
43014295

43024296
begin
4303-
if Ada.Kind = GNATCOLL.JSON.JSON_Object_Type then
4297+
if Options.Kind = GNATCOLL.JSON.JSON_Object_Type then
43044298
Relocate := Property (relocateBuildTree);
43054299
Root := Property (rootDir);
43064300
Charset := Property (defaultCharset);
@@ -4311,76 +4305,80 @@ package body LSP.Ada_Handlers is
43114305
File := Self.URI_To_File (File);
43124306
end if;
43134307

4314-
if Ada.Has_Field (scenarioVariables) and then
4315-
Ada.Get (scenarioVariables).Kind = GNATCOLL.JSON.JSON_Object_Type
4308+
if Options.Has_Field (scenarioVariables) and then
4309+
Options.Get
4310+
(scenarioVariables).Kind = GNATCOLL.JSON.JSON_Object_Type
43164311
then
4317-
Ada.Get (scenarioVariables).Map_JSON_Object (Add_Variable'Access);
4312+
Options.Get
4313+
(scenarioVariables).Map_JSON_Object (Add_Variable'Access);
43184314
end if;
43194315

43204316
-- It looks like the protocol does not allow clients to say whether
43214317
-- or not they want diagnostics as part of
43224318
-- InitializeParams.capabilities.textDocument. So we support
43234319
-- deactivating of diagnostics via a setting here.
4324-
if Ada.Has_Field (enableDiagnostics) then
4325-
Self.Diagnostics_Enabled := Ada.Get (enableDiagnostics);
4320+
if Options.Has_Field (enableDiagnostics) then
4321+
Self.Diagnostics_Enabled := Options.Get (enableDiagnostics);
43264322
end if;
43274323

43284324
-- Similarly to diagnostics, we support selectively activating
43294325
-- indexing in the parameters to this request.
4330-
if Ada.Has_Field (enableIndexing) then
4331-
Self.Indexing_Enabled := Ada.Get (enableIndexing);
4326+
if Options.Has_Field (enableIndexing) then
4327+
Self.Indexing_Enabled := Options.Get (enableIndexing);
43324328
end if;
43334329

43344330
-- Retrieve the different textDocument/rename options if specified
43354331

4336-
if Ada.Has_Field (renameInComments) then
4332+
if Options.Has_Field (renameInComments) then
43374333
Self.Options.Refactoring.Renaming.In_Comments :=
4338-
Ada.Get (renameInComments);
4334+
Options.Get (renameInComments);
43394335
end if;
43404336

4341-
if Ada.Has_Field (foldComments) then
4342-
Self.Options.Folding.Comments := Ada.Get (foldComments);
4337+
if Options.Has_Field (foldComments) then
4338+
Self.Options.Folding.Comments := Options.Get (foldComments);
43434339
end if;
43444340

43454341
-- Retrieve the number of parameters / components at which point
43464342
-- named notation is used for subprogram/aggregate completion
43474343
-- snippets.
43484344

4349-
if Ada.Has_Field (namedNotationThreshold) then
4350-
Self.Named_Notation_Threshold := Ada.Get (namedNotationThreshold);
4345+
if Options.Has_Field (namedNotationThreshold) then
4346+
Self.Named_Notation_Threshold :=
4347+
Options.Get (namedNotationThreshold);
43514348
end if;
43524349

4353-
if Ada.Has_Field (logThreshold) then
4354-
Self.Log_Threshold := Ada.Get (logThreshold);
4350+
if Options.Has_Field (logThreshold) then
4351+
Self.Log_Threshold := Options.Get (logThreshold);
43554352
end if;
43564353

43574354
-- Check the 'useCompletionSnippets' flag to see if we should use
43584355
-- snippets in completion (if the client supports it).
43594356
if not Self.Completion_Snippets_Enabled then
43604357
Self.Use_Completion_Snippets := False;
4361-
elsif Ada.Has_Field (useCompletionSnippets) then
4362-
Self.Use_Completion_Snippets := Ada.Get (useCompletionSnippets);
4358+
elsif Options.Has_Field (useCompletionSnippets) then
4359+
Self.Use_Completion_Snippets :=
4360+
Options.Get (useCompletionSnippets);
43634361
end if;
43644362

43654363
-- Retrieve the policy for displaying type hierarchy on navigation
43664364
-- requests.
4367-
if Ada.Has_Field (displayMethodAncestryOnNavigation) then
4365+
if Options.Has_Field (displayMethodAncestryOnNavigation) then
43684366
Self.Display_Method_Ancestry_Policy :=
43694367
LSP.Messages.AlsDisplayMethodAncestryOnNavigationPolicy'Value
4370-
(Ada.Get (displayMethodAncestryOnNavigation));
4368+
(Options.Get (displayMethodAncestryOnNavigation));
43714369
end if;
43724370

43734371
-- Retrieve the follow symlinks policy.
43744372

4375-
if Ada.Has_Field (followSymlinks) then
4376-
Self.Follow_Symlinks := Ada.Get (followSymlinks);
4373+
if Options.Has_Field (followSymlinks) then
4374+
Self.Follow_Symlinks := Options.Get (followSymlinks);
43774375
end if;
43784376

4379-
if Ada.Has_Field (documentationStyle) then
4377+
if Options.Has_Field (documentationStyle) then
43804378
begin
43814379
Self.Options.Documentation.Style :=
43824380
GNATdoc.Comments.Options.Documentation_Style'Value
4383-
(Ada.Get (documentationStyle));
4381+
(Options.Get (documentationStyle));
43844382

43854383
exception
43864384
when Constraint_Error =>
@@ -4392,12 +4390,12 @@ package body LSP.Ada_Handlers is
43924390

43934391
if not File.Is_Empty then
43944392
Self.Load_Project
4395-
(File,
4396-
Variables,
4397-
Charset,
4398-
Valid_Project_Configured,
4399-
Relocate,
4400-
Root);
4393+
(Project_File => File,
4394+
Scenario => Variables,
4395+
Charset => Charset,
4396+
Status => Valid_Project_Configured,
4397+
Relocate_Build_Tree => Relocate,
4398+
Root_Dir => Root);
44014399
end if;
44024400

44034401
Self.Ensure_Project_Loaded;

source/ada/lsp-ada_handlers.ads

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with Ada.Containers.Hashed_Sets;
2323
with Ada.Strings.Unbounded;
2424
with VSS.String_Vectors;
2525

26+
with GNATCOLL.JSON;
2627
with GNATCOLL.VFS; use GNATCOLL.VFS;
2728
with GNATCOLL.Traces;
2829

@@ -71,6 +72,11 @@ package LSP.Ada_Handlers is
7172
-- This procedure will be called when an unexpected error is raised in the
7273
-- request processing loop.
7374

75+
procedure Change_Configuration
76+
(Self : access Message_Handler;
77+
Options : GNATCOLL.JSON.JSON_Value'Class);
78+
-- Change server configuration with settings from Ada JSON object.
79+
7480
procedure Stop_File_Monitoring (Self : access Message_Handler);
7581

7682
procedure Cleanup (Self : access Message_Handler);

source/tester/tester-tests.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ with Tester.Macros;
3636

3737
package body Tester.Tests is
3838

39-
Max_Wait : constant := 4.0;
39+
Max_Wait : constant := 16.0;
4040
-- Max number of seconds to wait on a given snippet
4141

4242
type Command_Kind is (Start, Stop, Send, Shell, Append_To_Env, Comment);

testsuite/.als/traces.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#ALS.OUT=yes > inout.txt:buffer_size=0
1010

1111
# Testing should include incremental text changes
12-
ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes #> inout.txt:buffer_size=0
12+
#ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes > inout.txt:buffer_size=0
13+
ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes
1314

1415
# Activate navigation warnings in test mode
1516
ALS.NOTIFICATIONS_FOR_IMPRECISE_NAVIGATION=yes

testsuite/ada_lsp/refactoring_replace_type/Q817-007/test.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,16 @@
108108
}
109109
}
110110
},
111-
"wait": []
111+
"wait": [
112+
{
113+
"jsonrpc": "2.0",
114+
"id": 2,
115+
"method": "window/workDoneProgress/create",
116+
"params": {
117+
"token": "<ANY>"
118+
}
119+
}
120+
]
112121
}
113122
},
114123
{

testsuite/ada_lsp/refactoring_sort_dependencies/SA22-035/test.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@
107107
}
108108
}
109109
},
110-
"wait": []
110+
"wait": [
111+
{
112+
"jsonrpc": "2.0",
113+
"id": 2,
114+
"method": "window/workDoneProgress/create",
115+
"params": {
116+
"token": "<ANY>"
117+
}
118+
}
119+
]
111120
}
112121
},
113122
{
@@ -283,4 +292,4 @@
283292
"exit_code": 0
284293
}
285294
}
286-
]
295+
]

0 commit comments

Comments
 (0)