Skip to content

Commit 679968f

Browse files
committedAug 13, 2024
Merge branch 'topic/merge_fix' into 'edge'
Rewrite project status data See merge request eng/ide/ada_language_server!1657
2 parents 7bdced7 + 107f564 commit 679968f

File tree

24 files changed

+1058
-495
lines changed

24 files changed

+1058
-495
lines changed
 

‎.github/workflows/build-binaries.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,24 @@ jobs:
4040
uses: actions/checkout@v3
4141
with:
4242
fetch-depth: 0
43-
- name: Get GNAT toolchain with alire (AArch64)
44-
if: ${{ matrix.os == 'macos-14' }}
43+
- name: Get GNAT toolchain with alire
44+
shell: bash
4545
run: |
4646
# alire-project/setup-alire doesn't work for ARM64 Mac OS X for now.
4747
# https://github.com/alire-project/setup-alire/pull/74
48-
curl -L -O https://github.com/alire-project/alire/releases/download/nightly/alr-nightly-bin-aarch64-macos.zip
49-
unzip alr-nightly-bin-aarch64-macos.zip
48+
# Also it depends on `engineerd/configurator@v0.0.10` not approved by IT.
49+
# https://github.com/alire-project/setup-alire/issues/75
50+
# So we fetch Alire with curl then toolchain with Alire.
51+
if [[ "$RUNNER_ARCH" == ARM64 ]] ; then
52+
ZIP=nightly/alr-nightly-bin-aarch64-macos.zip
53+
else
54+
ZIP=v2.0.1/alr-2.0.1-bin-x86_64-${RUNNER_OS}.zip
55+
fi
56+
curl -L -O https://github.com/alire-project/alire/releases/download/$ZIP
57+
unzip $(basename $ZIP)
5058
bin/alr index --reset-community
5159
bin/alr toolchain --select gnat_native^14 gprbuild
5260
echo $PWD/bin >> $GITHUB_PATH
53-
- name: Get GNAT toolchain with alire (x86_64)
54-
if: ${{ matrix.os != 'macos-14' }}
55-
uses: alire-project/setup-alire@v3
56-
with:
57-
toolchain: gnat_native^14 gprbuild
5861
- name: Build
5962
shell: bash
6063
run: |

‎alire.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ libgpr2 = "^24.0.0"
2626
vss = "^24.0.0"
2727
libadalang_tools = "^24.0.0"
2828
lal_refactor = "25.0.0-20240625"
29+
gnatformat = "25.0.0-20240625"
2930
gnatdoc = "^24.0.0"
3031
spawn = "^24.0.0"
3132

‎gnat/lsp_server.gpr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ project LSP_Server is
3939

4040
for Object_Dir use "../.obj/server";
4141
for Main use ("lsp-ada_driver.adb");
42+
-- Need C++ to use a linker compatible with libfswatch
4243
for Languages use ("Ada", "C++");
4344

4445
package Naming is
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name = "gnatformat"
2+
description = "An opinionated code formatter for the Ada language."
3+
version = "25.0.0-20240625"
4+
5+
authors = ["AdaCore"]
6+
maintainers = ["João Azevedo <azevedo@adacore.com>"]
7+
maintainers-logins = ["joaopsazevedo"]
8+
licenses = "Apache-2.0 WITH LLVM-exception"
9+
website = "https://github.com/AdaCore/gnatformat"
10+
11+
project-files = ["gnat/gnatformat.gpr"]
12+
13+
[environment.'case(os)'.macos.DYLD_LIBRARY_PATH]
14+
append = "${CRATE_ROOT}/.libs/relocatable"
15+
16+
[environment.'case(os)'.windows.PATH]
17+
append = "${CRATE_ROOT}/.libs/relocatable"
18+
19+
[configuration]
20+
disabled = true
21+
22+
[[depends-on]]
23+
libadalang = "^24"
24+
prettier_ada = "25.0.0-20240625"
25+
26+
[origin]
27+
url = "git+https://github.com/AdaCore/gnatformat"
28+
commit = "b418fcc894877777ecf4102410ba4eeee279e219"
29+

‎scripts/build_als.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PINS="
1717
adasat
1818
gnatcoll
1919
gnatdoc
20+
gnatformat
2021
lal_refactor
2122
langkit_support
2223
libadalang
@@ -45,6 +46,7 @@ repo_vss=VSS
4546

4647
branch_gnatdoc=edge
4748
branch_lal_refactor=edge
49+
branch_gnatformat=edge
4850
branch_libgpr2=next
4951
branch_prettier_ada=main
5052

@@ -53,7 +55,7 @@ SETENV=$PWD/subprojects/libadalang/setenv.sh
5355

5456
# Set `prod` build mode
5557
########################
56-
# for adasat,lal,langkit,lal_refactor,laltools,markdown,spawn
58+
# for adasat,gnatformat,lal,langkit,lal_refactor,laltools,markdown,spawn
5759
export BUILD_MODE=prod
5860
# for others
5961
export GNATCOLL_BUILD_MODE=PROD

‎source/ada/lsp-ada_configurations.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ package body LSP.Ada_Configurations is
261261
Self.Context.Clear;
262262
for J in 1 .. Variables_Names.Length loop
263263
Self.Context.Insert
264-
(GPR2.Optional_Name_Type
264+
(GPR2.External_Name_Type
265265
(VSS.Strings.Conversions.To_UTF_8_String
266266
(Variables_Names (J))),
267267
VSS.Strings.Conversions.To_UTF_8_String

‎source/ada/lsp-ada_handlers-project_diagnostics.adb

Lines changed: 8 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -15,188 +15,26 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with GPR2.Source_Reference;
19-
with GPR2.Message;
20-
with GPR2.Path_Name;
21-
22-
with VSS.Strings;
23-
24-
with LSP.Enumerations;
25-
with LSP.Utils;
26-
2718
package body LSP.Ada_Handlers.Project_Diagnostics is
2819

29-
Project_Loading_Status_Messages : constant array (Load_Project_Status)
30-
of VSS.Strings.Virtual_String :=
31-
(Single_Project_Found =>
32-
VSS.Strings.To_Virtual_String
33-
("Unique project in root directory was found and "
34-
& "loaded, but it wasn't explicitly configured."),
35-
No_Runtime_Found =>
36-
VSS.Strings.To_Virtual_String
37-
("The project was loaded, but no Ada runtime found. "
38-
& "Please check the installation of the Ada compiler."),
39-
No_Project_Found =>
40-
VSS.Strings.To_Virtual_String
41-
("No project found in root directory. "
42-
& "Please create a project file and add it to the "
43-
& "configuration."),
44-
Multiple_Projects_Found =>
45-
VSS.Strings.To_Virtual_String
46-
("No project was loaded, because more than one "
47-
& "project file has been found in the root directory. "
48-
& "Please change configuration to point a correct project "
49-
& "file."),
50-
Invalid_Project_Configured =>
51-
VSS.Strings.To_Virtual_String
52-
("Project file has errors and can't be loaded."),
53-
others => VSS.Strings.Empty_Virtual_String);
54-
-- The diagnostics' messages depending on the project loading status.
55-
56-
Project_Loading_Status_Severities : constant array (Load_Project_Status)
57-
of LSP.Enumerations.DiagnosticSeverity :=
58-
(Valid_Project_Configured => LSP.Enumerations.Hint,
59-
Alire_Project => LSP.Enumerations.Hint,
60-
Single_Project_Found => LSP.Enumerations.Hint,
61-
No_Runtime_Found => LSP.Enumerations.Warning,
62-
Multiple_Projects_Found => LSP.Enumerations.Error,
63-
No_Project_Found => LSP.Enumerations.Error,
64-
Invalid_Project_Configured => LSP.Enumerations.Error);
65-
-- The diagnostics' severities depending on the project loading status.
66-
6720
--------------------
6821
-- Get_Diagnostic --
6922
--------------------
7023

7124
overriding procedure Get_Diagnostic
7225
(Self : in out Diagnostic_Source;
7326
Context : LSP.Ada_Contexts.Context;
74-
Errors : out LSP.Structures.Diagnostic_Vector)
75-
is
76-
use LSP.Structures;
77-
78-
Parent_Diagnostic : LSP.Structures.Diagnostic;
79-
GPR2_Messages : GPR2.Log.Object renames
80-
Self.Handler.Project_Status.GPR2_Messages;
81-
82-
procedure Create_Project_Loading_Diagnostic;
83-
-- Create a parent diagnostic for the project loading status.
84-
85-
procedure Append_GPR2_Diagnostics;
86-
-- Append the GPR2 messages to the given parent diagnostic, if any.
87-
88-
---------------------------------------
89-
-- Create_Project_Loading_Diagnostic --
90-
---------------------------------------
91-
92-
procedure Create_Project_Loading_Diagnostic is
93-
Sloc : constant LSP.Structures.A_Range :=
94-
(start => (0, 0),
95-
an_end => (0, 0));
96-
begin
97-
-- Initialize the parent diagnostic.
98-
Parent_Diagnostic.a_range := ((0, 0), (0, 0));
99-
Parent_Diagnostic.source := "project";
100-
Parent_Diagnostic.severity :=
101-
(True, Project_Loading_Status_Severities (Self.Last_Status));
102-
103-
-- If we don't have any GPR2 messages, display the project loading
104-
-- status message in the parent diagnostic directly.
105-
-- Otherwise display a generic message in the parent amnd append it
106-
-- to its children, along with the other GPR2 messages.
107-
if GPR2_Messages.Is_Empty then
108-
Parent_Diagnostic.message := Project_Loading_Status_Messages
109-
(Self.Last_Status);
110-
else
111-
declare
112-
Project_File : GNATCOLL.VFS.Virtual_File renames
113-
Self.Handler.Project_Status.Project_File;
114-
URI : constant LSP.Structures.DocumentUri :=
115-
Self.Handler.To_URI
116-
(Project_File.Display_Full_Name);
117-
begin
118-
Parent_Diagnostic.message := "Project Problems";
119-
Parent_Diagnostic.relatedInformation.Append
120-
(LSP.Structures.DiagnosticRelatedInformation'
121-
(location =>
122-
LSP.Structures.Location'
123-
(uri => URI, a_range => Sloc,
124-
others => <>),
125-
message =>
126-
Project_Loading_Status_Messages
127-
(Self.Last_Status)));
128-
end;
129-
end if;
130-
end Create_Project_Loading_Diagnostic;
131-
132-
-----------------------------
133-
-- Append_GPR2_Diagnostics --
134-
-----------------------------
135-
136-
procedure Append_GPR2_Diagnostics is
137-
use GPR2.Message;
138-
use LSP.Enumerations;
139-
begin
140-
for Msg of GPR2_Messages loop
141-
if Msg.Level in GPR2.Message.Warning .. GPR2.Message.Error then
142-
declare
143-
Sloc : constant GPR2.Source_Reference.Object :=
144-
GPR2.Message.Sloc (Msg);
145-
File : constant GPR2.Path_Name.Object :=
146-
(if Sloc.Is_Defined and then Sloc.Has_Source_Reference
147-
then
148-
GPR2.Path_Name.Create_File
149-
(GPR2.Filename_Type (Sloc.Filename))
150-
else
151-
Self.Handler.Project_Tree.Root_Project.Path_Name);
152-
begin
153-
-- Display a diagnostic for GPR2 messages only if the file
154-
-- attached to the message is defined.
155-
if File.Is_Defined and then File.Has_Value then
156-
Parent_Diagnostic.relatedInformation.Append
157-
(LSP .Structures.DiagnosticRelatedInformation'
158-
(location => LSP.Structures.Location'
159-
(uri => LSP.Utils.To_URI (File),
160-
a_range => LSP.Utils.To_Range (Sloc),
161-
others => <>),
162-
message =>
163-
VSS.Strings.Conversions.To_Virtual_String
164-
(Msg.Message)));
165-
end if;
166-
end;
167-
168-
-- If we have one error in the GPR2 messages, the parent
169-
-- diagnostic's severity should be "error" too, otherwise
170-
-- "warning".
171-
if Msg.Level = GPR2.Message.Error then
172-
Parent_Diagnostic.severity :=
173-
(True, LSP.Enumerations.Error);
174-
elsif Parent_Diagnostic.severity.Value /=
175-
LSP.Enumerations.Error
176-
then
177-
Parent_Diagnostic.severity :=
178-
(True, LSP.Enumerations.Warning);
179-
end if;
180-
end if;
181-
end loop;
182-
end Append_GPR2_Diagnostics;
183-
27+
Errors : out LSP.Structures.Diagnostic_Vector) is
18428
begin
185-
Self.Last_Status := Self.Handler.Project_Status.Load_Status;
29+
Self.Last_Status := Self.Handler.Project_Status;
18630

31+
Self.Handler.Tracer.Trace ("Diag: " & Self.Last_Status'Image);
18732
-- If we have a valid project return immediately: we want to display
18833
-- diagnostics only if there is an issue to solve or a potential
18934
-- enhancement.
190-
if Self.Last_Status = Valid_Project_Configured
191-
or else (Self.Last_Status = Alire_Project and then GPR2_Messages.Is_Empty)
192-
then
193-
return;
194-
end if;
195-
196-
Create_Project_Loading_Diagnostic;
197-
Append_GPR2_Diagnostics;
19835

199-
Errors.Append (Parent_Diagnostic);
36+
Errors.Append_Vector
37+
(LSP.Ada_Project_Loading.Get_Diagnostics (Self.Last_Status));
20038
end Get_Diagnostic;
20139

20240
------------------------
@@ -210,9 +48,9 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
21048
is
21149
pragma Unreferenced (Context);
21250
begin
213-
return
214-
(Self.Last_Status /= Self.Handler.Project_Status.Load_Status
215-
or else not Self.Handler.Project_Status.GPR2_Messages.Is_Empty);
51+
return LSP.Ada_Project_Loading.Has_New_Diagnostics
52+
(Self.Last_Status,
53+
Self.Handler.Project_Status);
21654
end Has_New_Diagnostic;
21755

21856
end LSP.Ada_Handlers.Project_Diagnostics;

‎source/ada/lsp-ada_handlers-project_diagnostics.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
------------------------------------------------------------------------------
1717

1818
with LSP.Ada_Contexts;
19+
with LSP.Ada_Project_Loading;
1920
with LSP.Diagnostic_Sources;
2021

2122
package LSP.Ada_Handlers.Project_Diagnostics is
@@ -39,7 +40,7 @@ private
3940
type Diagnostic_Source
4041
(Handler : not null access LSP.Ada_Handlers.Message_Handler)
4142
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with record
42-
Last_Status : Load_Project_Status := No_Project_Found;
43+
Last_Status : LSP.Ada_Project_Loading.Project_Status_Type;
4344
end record;
4445

4546
end LSP.Ada_Handlers.Project_Diagnostics;

‎source/ada/lsp-ada_handlers-project_loading.adb

Lines changed: 147 additions & 95 deletions
Large diffs are not rendered by default.

‎source/ada/lsp-ada_handlers-project_loading.ads

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,19 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with VSS.Strings;
19-
with GPR2.Environment;
20-
with GPR2.Context;
21-
22-
private
23-
2418
package LSP.Ada_Handlers.Project_Loading is
2519

26-
procedure Load_Project
27-
(Self : in out Message_Handler'Class;
28-
Project_Path : VSS.Strings.Virtual_String;
29-
Context : GPR2.Context.Object;
30-
Environment : GPR2.Environment.Object;
31-
Charset : VSS.Strings.Virtual_String;
32-
Status : Load_Project_Status);
33-
-- Attempt to load the given project file, with the scenario provided.
34-
-- This unloads all currently loaded project contexts. This factorizes code
35-
-- between Load_Project_With_Alire and Ensure_Project_Loaded.
36-
3720
procedure Ensure_Project_Loaded (Self : in out Message_Handler'Class);
21+
-- Search and load a project from the current workspace.
22+
-- The search will be done in this order:
23+
-- 1- search for an alire crate
24+
-- 2- if there is only one project then load it
25+
-- 3- load the implicit project and warn if there were multiple projects
26+
-- Do nothing if a project has been loaded.
3827

3928
procedure Reload_Project (Self : in out Message_Handler'CLass);
29+
-- Reload the project set in the configuration or Load the project if
30+
-- none is already yet.
4031

4132
procedure Release_Contexts_And_Project_Info
4233
(Self : in out Message_Handler'Class);

‎source/ada/lsp-ada_handlers.adb

Lines changed: 26 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ with VSS.Strings.Formatters.Integers;
2828
with VSS.Strings.Formatters.Strings;
2929
with VSS.Strings.Templates;
3030
with VSS.String_Vectors;
31-
with VSS.JSON.Streams;
3231

3332
with Laltools.Common;
3433
with Laltools.Partial_GNATPP;
@@ -83,7 +82,6 @@ with LSP.Ada_Handlers.Symbols;
8382
with LSP.Ada_Commands;
8483
with LSP.Client_Side_File_Monitors;
8584
with LSP.Diagnostic_Sources;
86-
with LSP.Enumerations;
8785
with LSP.Errors;
8886
with LSP.Formatters.Texts;
8987
with LSP.Generic_Cancel_Check;
@@ -93,6 +91,7 @@ with LSP.Servers;
9391
with LSP.Servers.FS_Watch;
9492
with LSP.Structures.LSPAny_Vectors;
9593
with LSP.Utils;
94+
with LSP.Enumerations;
9695

9796
package body LSP.Ada_Handlers is
9897

@@ -572,10 +571,6 @@ package body LSP.Ada_Handlers is
572571
-- Result with Code_Actions in this case. Return Done = True if futher
573572
-- analysis has no sense.
574573

575-
procedure Append_Project_Status_Code_Actions
576-
(Result : in out LSP.Structures.Command_Or_CodeAction_Vector);
577-
-- Append project status code action if needed
578-
579574
------------------------
580575
-- Analyse_In_Context --
581576
------------------------
@@ -1242,111 +1237,6 @@ package body LSP.Ada_Handlers is
12421237
end if;
12431238
end Analyse_Node;
12441239

1245-
----------------------------------------
1246-
-- Append_Project_Status_Code_Actions --
1247-
----------------------------------------
1248-
1249-
procedure Append_Project_Status_Code_Actions
1250-
(Result : in out LSP.Structures.Command_Or_CodeAction_Vector)
1251-
is
1252-
use type VSS.Strings.Virtual_String;
1253-
1254-
Diagnostics : LSP.Structures.Diagnostic_Vector;
1255-
1256-
begin
1257-
for Item of Value.context.diagnostics loop
1258-
if Item.source = "project" then
1259-
Diagnostics.Append (Item);
1260-
end if;
1261-
end loop;
1262-
1263-
case Self.Project_Status.Load_Status is
1264-
when Valid_Project_Configured | Alire_Project =>
1265-
null;
1266-
when No_Runtime_Found =>
1267-
-- TODO: Provide help with the compiler installation
1268-
null;
1269-
when Single_Project_Found | Multiple_Projects_Found =>
1270-
declare
1271-
Item : LSP.Structures.CodeAction;
1272-
Command : LSP.Structures.Command;
1273-
Arg : constant VSS.JSON.Streams.JSON_Stream_Element :=
1274-
VSS.JSON.Streams.JSON_Stream_Element'
1275-
(Kind => VSS.JSON.Streams.String_Value,
1276-
String_Value => "ada.projectFile");
1277-
begin
1278-
Command.title := "Open settings for ada.projectFile";
1279-
Command.command := "workbench.action.openSettings";
1280-
Command.arguments.Append (Arg);
1281-
1282-
Item :=
1283-
(title => Command.title,
1284-
kind => (True, LSP.Enumerations.QuickFix),
1285-
diagnostics => Diagnostics,
1286-
disabled => (Is_Set => False),
1287-
edit => (Is_Set => False),
1288-
isPreferred => LSP.Constants.True,
1289-
command => (True, Command),
1290-
data => <>);
1291-
1292-
Result.Append
1293-
(LSP.Structures.Command_Or_CodeAction'
1294-
(Is_Command => False, CodeAction => Item));
1295-
end;
1296-
when No_Project_Found =>
1297-
declare
1298-
Title : constant VSS.Strings.Virtual_String :=
1299-
"Create a default project file (default.gpr)";
1300-
URI : constant LSP.Structures.DocumentUri :=
1301-
Self.To_URI
1302-
(GNATCOLL.VFS.Create_From_UTF8
1303-
(VSS.Strings.Conversions.To_UTF_8_String
1304-
(Self.Client.Root)).Join
1305-
("default.gpr").Display_Full_Name);
1306-
1307-
Create : constant LSP.Structures.
1308-
documentChanges_OfWorkspaceEdit_Item :=
1309-
(Kind => LSP.Structures.create,
1310-
create => (uri => URI,
1311-
others => <>));
1312-
1313-
Text : constant LSP.Structures.
1314-
TextEdit_Or_AnnotatedTextEdit :=
1315-
(Is_TextEdit => True,
1316-
TextEdit =>
1317-
(a_range => ((0, 0), (0, 0)),
1318-
newText => "project Default is end Default;"));
1319-
Insert : LSP.Structures.
1320-
documentChanges_OfWorkspaceEdit_Item :=
1321-
(LSP.Structures.Variant_1,
1322-
(textDocument => (uri => URI, others => <>),
1323-
edits => <>));
1324-
1325-
Item : LSP.Structures.CodeAction;
1326-
Edit : LSP.Structures.WorkspaceEdit;
1327-
begin
1328-
Insert.Variant_1.edits.Append (Text);
1329-
Edit.documentChanges.Append (Create);
1330-
Edit.documentChanges.Append (Insert);
1331-
Item :=
1332-
(title => Title,
1333-
kind => (True, LSP.Enumerations.QuickFix),
1334-
diagnostics => Diagnostics,
1335-
disabled => (Is_Set => False),
1336-
edit => (True, Edit),
1337-
isPreferred => LSP.Constants.True,
1338-
command => (Is_Set => False),
1339-
data => <>);
1340-
1341-
Result.Append
1342-
(LSP.Structures.Command_Or_CodeAction'
1343-
(Is_Command => False, CodeAction => Item));
1344-
end;
1345-
when Invalid_Project_Configured =>
1346-
null;
1347-
end case;
1348-
end Append_Project_Status_Code_Actions;
1349-
13501240
----------------------------------
13511241
-- Has_Assoc_Without_Designator --
13521242
----------------------------------
@@ -1500,7 +1390,29 @@ package body LSP.Ada_Handlers is
15001390
end loop;
15011391

15021392
if Value.a_range.start = LSP.Constants.Empty then
1503-
Append_Project_Status_Code_Actions (Response);
1393+
declare
1394+
Diagnostics : LSP.Structures.Diagnostic_Vector;
1395+
use type VSS.Strings.Virtual_String;
1396+
1397+
Default_URI : constant LSP.Structures.DocumentUri :=
1398+
Self.To_URI
1399+
(GNATCOLL.VFS.Create_From_UTF8
1400+
(URIs.Conversions.To_File
1401+
(VSS.Strings.Conversions.To_UTF_8_String
1402+
(Self.Client.Root), Normalize => True)).Join
1403+
("default.gpr").Display_Full_Name);
1404+
begin
1405+
for Item of Value.context.diagnostics loop
1406+
if Item.source = "project" then
1407+
Diagnostics.Append (Item);
1408+
end if;
1409+
end loop;
1410+
LSP.Ada_Project_Loading.Project_Status_Code_Actions
1411+
(Result => Response,
1412+
Project => Self.Project_Status,
1413+
Diagnostics => Diagnostics,
1414+
Default_URI => Default_URI);
1415+
end;
15041416
end if;
15051417

15061418
Self.Sender.On_CodeAction_Response (Id, Response);
@@ -2080,7 +1992,8 @@ package body LSP.Ada_Handlers is
20801992
-- Handle the case where we're loading the implicit project: do
20811993
-- we need to add the directory in which the document is open?
20821994

2083-
if Self.Project_Status.Load_Status in Implicit_Project_Loaded then
1995+
if LSP.Ada_Project_Loading.Is_Implicit_Fallback (Self.Project_Status)
1996+
then
20841997
declare
20851998
Dir : constant GNATCOLL.VFS.Virtual_File := Self.To_File (URI).Dir;
20861999
begin

‎source/ada/lsp-ada_handlers.ads

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ with Ada.Exceptions;
2525
with GNATCOLL.Traces;
2626
with GNATCOLL.VFS;
2727

28-
with GPR2.Log;
2928
with GPR2.Project.Tree;
3029

3130
with Libadalang.Analysis;
@@ -41,6 +40,7 @@ with LSP.Ada_Documents;
4140
with LSP.Ada_File_Sets;
4241
with LSP.Ada_Highlighters;
4342
with LSP.Ada_Job_Contexts;
43+
with LSP.Ada_Project_Loading;
4444
with LSP.Client_Message_Receivers;
4545
with LSP.Constants;
4646
with LSP.File_Monitors;
@@ -142,62 +142,8 @@ package LSP.Ada_Handlers is
142142
-- Remove the oldest logs in Dir
143143

144144
private
145-
146-
type Load_Project_Status is
147-
(Valid_Project_Configured,
148-
Single_Project_Found,
149-
Alire_Project,
150-
No_Runtime_Found,
151-
No_Project_Found,
152-
Multiple_Projects_Found,
153-
Invalid_Project_Configured);
154-
-- Variants for state of the project loaded into the handler:
155-
--
156-
-- @value Valid_Project_Configured didChangeConfiguration provided a valid
157-
-- project
158-
--
159-
-- @value Single_Project_Found no project in didChangeConfiguration, but
160-
-- just one project in Root dir
161-
--
162-
-- @value Alire_Project no project in didChangeConfiguration, but Alire
163-
-- knows what project to use
164-
--
165-
-- @value No_Runtime_Found project loaded, but no Ada runtime library was
166-
-- found
167-
--
168-
-- @value No_Project_Found no project in didChangeConfiguration and no
169-
-- project in Root dir
170-
--
171-
-- @value Multiple_Projects_Found no project in didChangeConfiguration and
172-
-- several projects in Root dir
173-
--
174-
-- @value Invalid_Project_Configured didChangeConfiguration provided a
175-
-- valid project
176-
177-
type Project_Status_Type is record
178-
Project_File : GNATCOLL.VFS.Virtual_File := GNATCOLL.VFS.No_File;
179-
-- The project file we have attempted to load, successfully or not.
180-
181-
Load_Status : Load_Project_Status := No_Project_Found;
182-
-- Project loading status.
183-
184-
GPR2_Messages : GPR2.Log.Object := GPR2.Log.Undefined;
185-
-- The warning/error messages emitted by GPR2 while loading the project.
186-
end record;
187-
-- Project loading status.
188-
189-
No_Project_Status : constant Project_Status_Type :=
190-
Project_Status_Type'
191-
(Project_File => GNATCOLL.VFS.No_File,
192-
Load_Status => No_Project_Found,
193-
GPR2_Messages => <>);
194-
195145
type Project_Stamp is mod 2**32;
196146

197-
subtype Implicit_Project_Loaded is Load_Project_Status range
198-
No_Project_Found .. Invalid_Project_Configured;
199-
-- Project status when an implicit project loaded
200-
201147
type Internal_Document_Access is access all LSP.Ada_Documents.Document;
202148

203149
procedure Free (Self : in out Internal_Document_Access);
@@ -271,7 +217,8 @@ private
271217
-- A cache for the predefined sources in the loaded project (typically,
272218
-- runtime files).
273219

274-
Project_Status : Project_Status_Type := No_Project_Status;
220+
Project_Status : LSP.Ada_Project_Loading.Project_Status_Type :=
221+
LSP.Ada_Project_Loading.No_Project_Status;
275222
-- Indicates whether a project has been successfully loaded and
276223
-- how. Stores GPR2 error/warning messages emitted while loading
277224
-- (or attempting to load) the project.

‎source/ada/lsp-ada_project_loading.adb

Lines changed: 486 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2024, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
with GNATCOLL.VFS;
19+
with GPR2.Log;
20+
with LSP.Structures;
21+
22+
package LSP.Ada_Project_Loading is
23+
24+
type Project_Status_Type is private;
25+
-- Description of the project after trying to load it.
26+
27+
No_Project_Status : constant Project_Status_Type;
28+
29+
type Project_Types is
30+
(Not_Set,
31+
Configured_Project,
32+
Single_Project_Found,
33+
Alire_Project,
34+
Implicit_Project);
35+
-- Variants for type of project loaded into the handler:
36+
--
37+
-- @value Not_Set: initial value when starting the server
38+
--
39+
-- @value Configured_Project: project provided by ada.projectFile
40+
--
41+
-- @value Single_Project_Found: no project in ada.projectFile, but
42+
-- just one project in Root dir
43+
--
44+
-- @value Alire_Project: toml file found so use Alire project, it has
45+
-- priority over the configured project.
46+
--
47+
-- @value Implicit_Project: use the implicit project as a last chance
48+
49+
type Project_Status is
50+
(Valid_Project,
51+
Warning_In_Project,
52+
No_Project,
53+
Multiple_Projects,
54+
Invalid_Project,
55+
Project_Not_Found);
56+
-- Variants for state of the project loaded into the handler:
57+
--
58+
-- @value Valid_Project: the project is valid
59+
--
60+
-- @value Warning_In_Project: warnings when loading the project
61+
--
62+
-- @value No_Project: no project found in Root dir
63+
--
64+
-- @value Multiple_Projects_Found: no project in ada.projectFile and
65+
-- several projects in Root dir
66+
--
67+
-- @value Invalid_Project: errors when loading the project
68+
--
69+
-- @value Project_Not_Found: the configured project was not found.
70+
71+
procedure Set_Load_Status
72+
(Project : in out Project_Status_Type;
73+
Status : Project_Status);
74+
-- Set the status of the project
75+
76+
procedure Set_Project_Type
77+
(Project : in out Project_Status_Type;
78+
Project_Type : Project_Types);
79+
-- Set the type of the project.
80+
81+
procedure Set_Has_Runtime
82+
(Project : in out Project_Status_Type;
83+
Has_Runtime : Boolean);
84+
-- Should be called when the runtime for Project is found
85+
86+
procedure Set_GPR2_Messages
87+
(Project : in out Project_Status_Type;
88+
GPR2_Messages : GPR2.Log.Object);
89+
-- Set the messages related to GPR2 project loading
90+
91+
procedure Set_Project_File
92+
(Project : in out Project_Status_Type;
93+
Project_File : GNATCOLL.VFS.Virtual_File);
94+
-- Set the file we are trying to load
95+
96+
function Is_Implicit_Fallback
97+
(Project : Project_Status_Type) return Boolean;
98+
-- Return True if the implicit project has been loaded
99+
100+
function Is_Project_Loaded
101+
(Project : Project_Status_Type) return Boolean;
102+
-- Return True if the project was loaded
103+
104+
function Has_New_Diagnostics
105+
(Old_Project : Project_Status_Type;
106+
New_Project : Project_Status_Type)
107+
return Boolean;
108+
-- Return True when the New_Project has a different status or different
109+
-- messages compare to Old_Project
110+
111+
procedure Project_Status_Code_Actions
112+
(Result : in out LSP.Structures.Command_Or_CodeAction_Vector;
113+
Project : Project_Status_Type;
114+
Diagnostics : LSP.Structures.Diagnostic_Vector;
115+
Default_URI : LSP.Structures.DocumentUri);
116+
-- Add code actions related to Project in Result
117+
118+
function Get_Diagnostics
119+
(Project : Project_Status_Type)
120+
return LSP.Structures.Diagnostic_Vector;
121+
-- Compute and return the diagnostics of the project
122+
123+
private
124+
125+
type Project_Status_Type is record
126+
Project_Type : Project_Types := Not_Set;
127+
-- The type of loaded project
128+
129+
Status : Project_Status := Valid_Project;
130+
-- Status of the loaded project
131+
132+
Project_File : GNATCOLL.VFS.Virtual_File := GNATCOLL.VFS.No_File;
133+
-- The project file we have attempted to load, successfully or not.
134+
135+
Has_Runtime : Boolean := False;
136+
-- Were we able to find the runtime for the project
137+
138+
GPR2_Messages : GPR2.Log.Object := GPR2.Log.Undefined;
139+
-- The warning/error messages emitted by GPR2 while loading the project.
140+
end record;
141+
142+
No_Project_Status : constant Project_Status_Type :=
143+
Project_Status_Type'
144+
(Project_Type => Not_Set,
145+
Status => Valid_Project,
146+
Project_File => GNATCOLL.VFS.No_File,
147+
Has_Runtime => False,
148+
GPR2_Messages => <>);
149+
150+
end LSP.Ada_Project_Loading;

‎subprojects/gnatformat.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name = "gnatformat"
2+
description = "An opinionated code formatter for the Ada language."
3+
version = "25.0.0-20240625"
4+
5+
authors = ["AdaCore"]
6+
maintainers = ["João Azevedo <azevedo@adacore.com>"]
7+
maintainers-logins = ["joaopsazevedo"]
8+
licenses = "Apache-2.0 WITH LLVM-exception"
9+
website = "https://github.com/AdaCore/gnatformat"
10+
11+
project-files = ["gnat/gnatformat.gpr"]
12+
13+
[environment.'case(os)'.macos.DYLD_LIBRARY_PATH]
14+
append = "${CRATE_ROOT}/.libs/relocatable"
15+
16+
[environment.'case(os)'.windows.PATH]
17+
append = "${CRATE_ROOT}/.libs/relocatable"
18+
19+
[configuration]
20+
disabled = true
21+
22+
[[depends-on]]
23+
libadalang = "^24"
24+
prettier_ada = "25.0.0-20240625"

‎testsuite/ada_lsp/editor.incremental/test.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@
422422
"character": 0
423423
}
424424
},
425-
"severity": 1,
425+
"severity": 2,
426426
"source": "project",
427-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
427+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
428428
}
429429
]
430430
},
@@ -478,9 +478,9 @@
478478
"character": 0
479479
}
480480
},
481-
"severity": 1,
481+
"severity": 2,
482482
"source": "project",
483-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
483+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
484484
}
485485
]
486486
},
@@ -547,9 +547,9 @@
547547
"character": 0
548548
}
549549
},
550-
"severity": 1,
550+
"severity": 2,
551551
"source": "project",
552-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
552+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
553553
}
554554
]
555555
},
@@ -603,9 +603,9 @@
603603
"character": 0
604604
}
605605
},
606-
"severity": 1,
606+
"severity": 2,
607607
"source": "project",
608-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
608+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
609609
}
610610
]
611611
},
@@ -685,9 +685,9 @@
685685
"character": 0
686686
}
687687
},
688-
"severity": 1,
688+
"severity": 2,
689689
"source": "project",
690-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
690+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
691691
}
692692
]
693693
},
@@ -741,9 +741,9 @@
741741
"character": 0
742742
}
743743
},
744-
"severity": 1,
744+
"severity": 2,
745745
"source": "project",
746-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
746+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
747747
}
748748
]
749749
},
@@ -823,9 +823,9 @@
823823
"character": 0
824824
}
825825
},
826-
"severity": 1,
826+
"severity": 2,
827827
"source": "project",
828-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
828+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
829829
}
830830
]
831831
},
@@ -879,9 +879,9 @@
879879
"character": 0
880880
}
881881
},
882-
"severity": 1,
882+
"severity": 2,
883883
"source": "project",
884-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
884+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
885885
}
886886
]
887887
},
@@ -961,9 +961,9 @@
961961
"character": 0
962962
}
963963
},
964-
"severity": 1,
964+
"severity": 2,
965965
"source": "project",
966-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
966+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
967967
}
968968
]
969969
},
@@ -1017,9 +1017,9 @@
10171017
"character": 0
10181018
}
10191019
},
1020-
"severity": 1,
1020+
"severity": 2,
10211021
"source": "project",
1022-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
1022+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
10231023
}
10241024
]
10251025
},

‎testsuite/ada_lsp/project_config.missing_file/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
}
9696
}
9797
},
98-
"message": "Project file has errors and can't be loaded."
98+
"message": "The project file has errors and could not be loaded."
9999
},
100100
{
101101
"location": {

‎testsuite/ada_lsp/project_config.multiple_project_diagnostics/test.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
},
9393
"severity": 1,
9494
"source": "project",
95-
"message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file."
95+
"message": "No project was loaded because multiple project files were found in the root directory. Please change the configuration to point to a single project file."
9696
}
9797
]
9898
}
@@ -133,7 +133,7 @@
133133
"character": 0
134134
}
135135
},
136-
"message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file.",
136+
"message": "No project was loaded because multiple project files were found in the root directory. Please change the configuration to point to a single project file.",
137137
"severity": 1,
138138
"source": "project"
139139
}
@@ -178,7 +178,7 @@
178178
"character": 0
179179
}
180180
},
181-
"message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file.",
181+
"message": "No project was loaded because multiple project files were found in the root directory. Please change the configuration to point to a single project file.",
182182
"severity": 1,
183183
"source": "project"
184184
}
@@ -192,7 +192,7 @@
192192
"id": 13,
193193
"result": [
194194
{
195-
"title": "Open settings for ada.projectFile",
195+
"title": "Open settings to set ada.projectFile to a valid project",
196196
"kind": "quickfix",
197197
"diagnostics": [
198198
{
@@ -208,12 +208,12 @@
208208
},
209209
"severity": 1,
210210
"source": "project",
211-
"message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file."
211+
"message": "No project was loaded because multiple project files were found in the root directory. Please change the configuration to point to a single project file."
212212
}
213213
],
214214
"isPreferred": true,
215215
"command": {
216-
"title": "Open settings for ada.projectFile",
216+
"title": "Open settings to set ada.projectFile to a valid project",
217217
"command": "workbench.action.openSettings",
218218
"arguments": "ada.projectFile"
219219
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Foo is
2+
begin
3+
null;
4+
end Foo;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
[
2+
{
3+
"comment": [
4+
"This test checks a diagnostic is produced when the project ",
5+
"file defined in the configuration doesn't exist."
6+
]
7+
}, {
8+
"start": {
9+
"cmd": ["${ALS}"]
10+
}
11+
}, {
12+
"send": {
13+
"request": {
14+
"jsonrpc": "2.0",
15+
"id": 0,
16+
"method": "initialize",
17+
"params": {
18+
"processId": 1,
19+
"rootUri": "$URI{.}",
20+
"capabilities": {},
21+
"initializationOptions": {}
22+
}
23+
},
24+
"wait":[{
25+
"id": 0,
26+
"result":{
27+
"capabilities":{
28+
"textDocumentSync": 2,
29+
"definitionProvider":true
30+
}
31+
}
32+
}]
33+
}
34+
},
35+
{
36+
"send": {
37+
"request": {
38+
"jsonrpc": "2.0",
39+
"method": "initialized",
40+
"params": {}
41+
},
42+
"wait": []
43+
}
44+
},
45+
{
46+
"send": {
47+
"request": {
48+
"jsonrpc": "2.0",
49+
"method": "workspace/didChangeConfiguration",
50+
"params": {
51+
"settings": {
52+
"ada": {
53+
"projectFile": "$URI{foo_bar.gpr}"
54+
}
55+
}
56+
}
57+
},
58+
"wait": []
59+
}
60+
},
61+
{
62+
"send": {
63+
"request": {
64+
"jsonrpc": "2.0",
65+
"method": "textDocument/didOpen",
66+
"params": {
67+
"textDocument": {
68+
"uri": "$URI{foo.adb}",
69+
"languageId": "ada",
70+
"version": 1,
71+
"text": "procedure Foo is\nbegin\n null;\nend Foo;"
72+
}
73+
}
74+
},
75+
"wait": [
76+
{
77+
"jsonrpc": "2.0",
78+
"method": "textDocument/publishDiagnostics",
79+
"params": {
80+
"uri": "$URI{foo.adb}",
81+
"diagnostics": [
82+
{
83+
"range": {
84+
"start": { "line": 0, "character": 0 },
85+
"end": { "line": 0, "character": 0 }
86+
},
87+
"severity": 1,
88+
"source": "project",
89+
"message": "The configured project $URI{foo_bar.gpr} does not exist."
90+
}
91+
]
92+
}
93+
}
94+
]
95+
}
96+
},
97+
{
98+
"stop": {
99+
"exit_code": 0
100+
}
101+
}
102+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'project_configured_not_found'

‎testsuite/ada_lsp/publish_diag/diag_on_open.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
"character": 0
7575
}
7676
},
77-
"severity": 1,
77+
"severity": 2,
7878
"source": "project",
79-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
79+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
8080
}
8181
]
8282
}

‎testsuite/ada_lsp/publish_diag/publish_diag.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@
110110
"character": 0
111111
}
112112
},
113-
"severity": 1,
113+
"severity": 2,
114114
"source": "project",
115-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
115+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
116116
}
117117
]
118118
}

‎testsuite/ada_lsp/refactoring_diagnostics/test.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,25 @@
169169
},
170170
"severity": 4,
171171
"source": "project",
172-
"message": "Unique project in root directory was found and loaded, but it wasn't explicitly configured."
172+
"message": "Project Problems",
173+
"relatedInformation": [
174+
{
175+
"location": {
176+
"uri": "$URI{default.gpr}",
177+
"range": {
178+
"start": {
179+
"line": 0,
180+
"character": 0
181+
},
182+
"end": {
183+
"line": 0,
184+
"character": 0
185+
}
186+
}
187+
},
188+
"message": "A unique project in the root directory was found and loaded but it was not explicitly configured."
189+
}
190+
]
173191
},
174192
{
175193
"message": "Failed to execute the Add Parameter refactoring.",

0 commit comments

Comments
 (0)
Please sign in to comment.