Skip to content

Commit 89c59e3

Browse files
committed
VB30-016 Read initial configuration
from `initializationOptions` of `initialize` request. Closes #1079
1 parent f4283a7 commit 89c59e3

File tree

13 files changed

+219
-18
lines changed

13 files changed

+219
-18
lines changed

doc/initialization.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# initializationOptions
2+
3+
## Short introduction
4+
5+
The ALS reads initial configuration from the `initializationOptions`
6+
property of the `initialize` request.
7+
8+
## Change description
9+
10+
The `initializationOptions` of the `initialize` request is a JSON
11+
object to be processed as `ada` object of `workspace/didChangeConfiguration`
12+
notification.

doc/settings.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
# Ada Language Server configuration
22

3-
The LSP has a dedicated notification to signal the server the change of configuration settings. Any setting should be inside a `ada` JSON object.
3+
The ALS reads initial configuration from the `initializationOptions`
4+
property of the `initialize` request (if any) and then updates
5+
the configuration with each `workspace/didChangeConfiguration`
6+
notification. Any setting in `workspace/didChangeConfiguration` should
7+
be inside an `ada` JSON object, while there is no such wrapping object
8+
for `initializationOptions`. On the protocol level messages look like:
9+
10+
```json
11+
{
12+
"jsonrpc": "2.0",
13+
"id": 123,
14+
"method": "initialize",
15+
"params": {
16+
"initializationOptions": {
17+
"projectFile": "right_project.gpr"
18+
},
19+
...
20+
}
21+
}
22+
23+
{
24+
"jsonrpc": "2.0",
25+
"method": "workspace/didChangeConfiguration",
26+
"params": {
27+
"settings": {
28+
"ada": {
29+
"projectFile": "right_project.gpr"
30+
}
31+
}
32+
}
33+
}
34+
```
35+
436
Ada Language Server understands these settings:
537

638
* [projectFile](#projectFile)

scripts/io_gen.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
'ALS_ShowDependenciesKind',
280280
'ALS_Unit_Description',
281281
'ALS_ShowDependenciesParams',
282+
'ALS_Source_Dir_Description',
282283
# 'ALS_Debug_Kinds',
283284
# 'ALSDebugParams',
284285
'Search_Kind',
@@ -506,6 +507,7 @@
506507
"write": "write",
507508
"static_call": "call",
508509
"dispatching_call": "dispatching call",
510+
"overriding_decl": "overriding",
509511
"parent": "parent",
510512
"child": "child",
511513
"empty": "", # For CodeActionKind

source/ada/lsp-ada_handlers.adb

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2022, AdaCore --
4+
-- Copyright (C) 2018-2023, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -315,6 +315,11 @@ package body LSP.Ada_Handlers is
315315
-- Attempt to load the given project file, with the scenario provided.
316316
-- This unloads all currently loaded project contexts.
317317

318+
procedure Change_Configuration
319+
(Self : access Message_Handler;
320+
Ada : LSP.Types.LSP_Any);
321+
-- Change server configuration with settings from Ada JSON object.
322+
318323
procedure Mark_Source_Files_For_Indexing (Self : access Message_Handler);
319324
-- Mark all sources in all projects for indexing. This factorizes code
320325
-- between Load_Project and Load_Implicit_Project.
@@ -1236,6 +1241,10 @@ package body LSP.Ada_Handlers is
12361241
Self.Experimental_Client_Capabilities :=
12371242
Parse (Experimental_Client_Capabilities);
12381243

1244+
if Value.initializationOptions.Is_Set then
1245+
Self.Change_Configuration (Value.initializationOptions.Value);
1246+
end if;
1247+
12391248
return Response;
12401249
end On_Initialize_Request;
12411250

@@ -4135,13 +4144,13 @@ package body LSP.Ada_Handlers is
41354144
end return;
41364145
end On_Rename_Request;
41374146

4138-
--------------------------------------------
4139-
-- On_DidChangeConfiguration_Notification --
4140-
--------------------------------------------
4147+
--------------------------
4148+
-- Change_Configuration --
4149+
--------------------------
41414150

4142-
overriding procedure On_DidChangeConfiguration_Notification
4151+
procedure Change_Configuration
41434152
(Self : access Message_Handler;
4144-
Value : LSP.Messages.DidChangeConfigurationParams)
4153+
Ada : LSP.Types.LSP_Any)
41454154
is
41464155
use type GNATCOLL.JSON.JSON_Value_Type;
41474156

@@ -4178,7 +4187,6 @@ package body LSP.Ada_Handlers is
41784187
logThreshold : constant String :=
41794188
"logThreshold";
41804189

4181-
Ada : constant LSP.Types.LSP_Any := Value.settings.Get ("ada");
41824190
Variables : Scenario_Variable_List;
41834191

41844192
function Property (Name : String) return VSS.Strings.Virtual_String is
@@ -4403,6 +4411,21 @@ package body LSP.Ada_Handlers is
44034411
Self.Server.On_RegisterCapability_Request (Request);
44044412
end;
44054413
end if;
4414+
end Change_Configuration;
4415+
4416+
--------------------------------------------
4417+
-- On_DidChangeConfiguration_Notification --
4418+
--------------------------------------------
4419+
4420+
overriding procedure On_DidChangeConfiguration_Notification
4421+
(Self : access Message_Handler;
4422+
Value : LSP.Messages.DidChangeConfigurationParams)
4423+
is
4424+
4425+
Ada : constant LSP.Types.LSP_Any := Value.settings.Get ("ada");
4426+
4427+
begin
4428+
Self.Change_Configuration (Ada);
44064429
end On_DidChangeConfiguration_Notification;
44074430

44084431
-------------------------------------------

source/protocol/generated/lsp-message_io.adb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4506,6 +4506,8 @@ package body LSP.Message_IO is
45064506
Optional_Nullable_String'Read (S, V.rootPath);
45074507
elsif Key = "rootUri" then
45084508
Nullable_String'Read (S, V.rootUri);
4509+
elsif Key = "initializationOptions" then
4510+
LSP.Types.Optional_LSP_Any'Read (S, V.initializationOptions);
45094511
elsif Key = "capabilities" then
45104512
ClientCapabilities'Read (S, V.capabilities);
45114513
elsif Key = "trace" then
@@ -4540,6 +4542,8 @@ package body LSP.Message_IO is
45404542
Optional_Nullable_String'Write (S, V.rootPath);
45414543
JS.Key ("rootUri");
45424544
Nullable_String'Write (S, V.rootUri);
4545+
JS.Key ("initializationOptions");
4546+
LSP.Types.Optional_LSP_Any'Write (S, V.initializationOptions);
45434547
JS.Key ("capabilities");
45444548
ClientCapabilities'Write (S, V.capabilities);
45454549
JS.Key ("trace");

source/protocol/lsp-messages.ads

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2021, AdaCore --
4+
-- Copyright (C) 2018-2023, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -4934,15 +4934,15 @@ package LSP.Messages is
49344934
--}
49354935
--```
49364936
type InitializeParams is new WorkDoneProgressParams with record
4937-
processId : Optional_Number;
4938-
clientInfo : Optional_ProgramInfo;
4939-
locale : Optional_Virtual_String;
4940-
rootPath : Optional_Nullable_String;
4941-
rootUri : Nullable_String;
4942-
-- initializationOptions?: any;
4943-
capabilities : ClientCapabilities;
4944-
trace : Optional_TraceValue;
4945-
workspaceFolders : Optional_WorkspaceFolder_Vector;
4937+
processId : Optional_Number;
4938+
clientInfo : Optional_ProgramInfo;
4939+
locale : Optional_Virtual_String;
4940+
rootPath : Optional_Nullable_String;
4941+
rootUri : Nullable_String;
4942+
initializationOptions : LSP.Types.Optional_LSP_Any;
4943+
capabilities : ClientCapabilities;
4944+
trace : Optional_TraceValue;
4945+
workspaceFolders : Optional_WorkspaceFolder_Vector;
49464946
end record;
49474947

49484948
procedure Read_InitializeParams
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with To_Be_Called;
2+
procedure Aaa is
3+
Text : String := "cba";
4+
begin
5+
To_Be_Called (Text);
6+
end Aaa;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
[
2+
{
3+
"comment":[
4+
"This test check language server is able to find a project file",
5+
"specified in `initializationOptions`.",
6+
"To check it we search for a custom named subprogram."
7+
]
8+
}, {
9+
"start": {
10+
"cmd": ["${ALS}"]
11+
}
12+
}, {
13+
"send": {
14+
"request": {
15+
"jsonrpc": "2.0",
16+
"id": 0,
17+
"method": "initialize",
18+
"params": {
19+
"processId": 1,
20+
"rootUri": "$URI{.}",
21+
"capabilities": {},
22+
"initializationOptions": {
23+
"projectFile": "right_project.gpr"
24+
}
25+
}
26+
},
27+
"wait":[{
28+
"id": 0,
29+
"result":{
30+
"capabilities":{
31+
"textDocumentSync": 2,
32+
"definitionProvider":true
33+
}
34+
}
35+
}]
36+
}
37+
}, {
38+
"send": {
39+
"request": {
40+
"jsonrpc":"2.0",
41+
"method":"textDocument/didOpen",
42+
"params":{
43+
"textDocument": {
44+
"uri": "$URI{aaa.adb}",
45+
"languageId": "ada",
46+
"version": 1,
47+
"text": "with To_Be_Called;\nprocedure Aaa is\n Text : String := \"cba\";\nbegin\n To_Be_Called (Text);\nend Aaa;\n"
48+
}
49+
}
50+
},
51+
"wait":[]
52+
}
53+
}, {
54+
"send": {
55+
"request": {
56+
"jsonrpc":"2.0",
57+
"id":"defname-1",
58+
"method":"textDocument/definition",
59+
"params":{
60+
"textDocument": {
61+
"uri": "$URI{aaa.adb}"
62+
},
63+
"position": {
64+
"line": 4,
65+
"character": 11
66+
}
67+
}
68+
},
69+
"wait":[{
70+
"id": "defname-1",
71+
"result":[{
72+
"uri": "$URI{second.ads}",
73+
"range": {
74+
"start": {
75+
"line": 0,
76+
"character": 10
77+
},
78+
"end": {
79+
"line": 0,
80+
"character": 22
81+
}
82+
}
83+
}]
84+
}]
85+
}
86+
}, {
87+
"send": {
88+
"request": {
89+
"jsonrpc":"2.0",
90+
"id": "shutdown",
91+
"method":"shutdown",
92+
"params":null
93+
},
94+
"wait":[{ "id": "shutdown", "result": null }]
95+
}
96+
}, {
97+
"send": {
98+
"request": {"jsonrpc":"2.0", "method":"exit", "params":{}},
99+
"wait":[]
100+
}
101+
}, {
102+
"stop": {
103+
"exit_code": 0
104+
}
105+
}
106+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project Right_Project is
2+
package Naming is
3+
for Spec ("To_Be_Called") use "second.ads";
4+
end Naming;
5+
end Right_Project;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
procedure To_Be_Called (Text : String);

0 commit comments

Comments
 (0)