Skip to content

Commit 9d4a275

Browse files
author
Philippe Gil
committed
Merge branch 'topic/gil-1338-alire-toml-file-support' into 'master'
Add Alire/GPR support Closes #1338 See merge request eng/ide/ada_language_server!1578
2 parents 3f3fdcd + 14df231 commit 9d4a275

30 files changed

+564
-150
lines changed

source/ada/lsp-ada_client_capabilities.adb

+23
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
pragma Ada_2022;
1919

20+
with URIs;
21+
2022
with VSS.Characters.Latin;
2123
with VSS.JSON.Streams;
2224
with VSS.String_Vectors;
@@ -25,6 +27,7 @@ with VSS.Strings.Conversions;
2527
with LSP.Ada_Configurations;
2628
with LSP.Constants;
2729
with LSP.Enumerations;
30+
with LSP.GPR_Files;
2831
with LSP.Structures.Unwrap;
2932

3033
with LSP.Structures.LSPAny_Vectors;
@@ -205,6 +208,9 @@ package body LSP.Ada_Client_Capabilities is
205208
end if;
206209

207210
Self.Parse_Experimental;
211+
212+
LSP.GPR_Files.Set_Environment (Client_Capability (Self));
213+
208214
end Initialize;
209215

210216
------------------------
@@ -593,4 +599,21 @@ package body LSP.Ada_Client_Capabilities is
593599
return (if Result.Is_Set then Result.Value else False);
594600
end Versioned_Documents;
595601

602+
--------------------
603+
-- Root_Directory --
604+
--------------------
605+
606+
function Root_Directory (Client : Client_Capability'Class)
607+
return GNATCOLL.VFS.Virtual_File
608+
is
609+
Value : constant VSS.Strings.Virtual_String := Client.Root;
610+
Root : constant String :=
611+
VSS.Strings.Conversions.To_UTF_8_String (Value);
612+
begin
613+
return GNATCOLL.VFS.Create_From_UTF8
614+
(if Value.Starts_With ("file://")
615+
then URIs.Conversions.To_File (Root, True)
616+
else Root);
617+
end Root_Directory;
618+
596619
end LSP.Ada_Client_Capabilities;

source/ada/lsp-ada_client_capabilities.ads

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with GNATCOLL.VFS;
19+
1820
with VSS.Strings;
1921

2022
with LSP.Structures;
@@ -46,6 +48,10 @@ package LSP.Ada_Client_Capabilities is
4648
-- if not rootUri/rootPath is provided, then it means no folder is open.
4749
-- Return an empty string in this case.
4850

51+
function Root_Directory
52+
(Client : Client_Capability'Class) return GNATCOLL.VFS.Virtual_File;
53+
-- Return the root directory of the client workspace
54+
4955
procedure Set_Root_If_Empty
5056
(Self : in out Client_Capability'Class;
5157
Value : VSS.Strings.Virtual_String);

source/ada/lsp-ada_handlers-project_loading.adb

+13-39
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ with Libadalang.Preprocessing;
2929

3030
with VSS.Strings.Conversions;
3131

32-
with Spawn.Environments;
33-
3432
with LSP.Ada_Contexts;
3533
with LSP.Ada_Context_Sets;
36-
with LSP.Ada_Handlers.Alire;
34+
with LSP.Alire;
3735
with LSP.Ada_Handlers.File_Readers;
3836
with LSP.Ada_Indexing;
3937
with LSP.Enumerations;
@@ -85,10 +83,6 @@ package body LSP.Ada_Handlers.Project_Loading is
8583
-- Mark all sources in all projects for indexing. This factorizes code
8684
-- between Load_Project and Load_Implicit_Project.
8785

88-
function Root
89-
(Self : Message_Handler'Class) return GNATCOLL.VFS.Virtual_File;
90-
-- Return the root directory of the client workspace
91-
9286
---------------------------
9387
-- Ensure_Project_Loaded --
9488
---------------------------
@@ -125,7 +119,7 @@ package body LSP.Ada_Handlers.Project_Loading is
125119
if not Self.Client.Root.Is_Empty then
126120
declare
127121
Files : GNATCOLL.VFS.File_Array_Access :=
128-
Root (Self).Read_Dir (GNATCOLL.VFS.Files_Only);
122+
Self.Client.Root_Directory.Read_Dir (GNATCOLL.VFS.Files_Only);
129123
begin
130124
for X of Files.all loop
131125
if X.Has_Suffix (".gpr") then
@@ -203,7 +197,7 @@ package body LSP.Ada_Handlers.Project_Loading is
203197
-- root directory in the workspace.
204198

205199
if not Self.Client.Root.Is_Empty then
206-
Self.Project_Dirs_Loaded.Include (Root (Self));
200+
Self.Project_Dirs_Loaded.Include (Self.Client.Root_Directory);
207201
end if;
208202

209203
Reload_Implicit_Project_Dirs (Self);
@@ -313,8 +307,11 @@ package body LSP.Ada_Handlers.Project_Loading is
313307
-- relative path; if so, we're assuming it's relative
314308
-- to Self.Root.
315309

316-
if not Project_File.Is_Absolute_Path and then not Self.Client.Root.Is_Empty then
317-
Project_File := GNATCOLL.VFS.Join (Root (Self), Project_File);
310+
if not Project_File.Is_Absolute_Path
311+
and then not Self.Client.Root.Is_Empty
312+
then
313+
Project_File := GNATCOLL.VFS.Join (Self.Client.Root_Directory,
314+
Project_File);
318315
end if;
319316

320317
-- Unload the project tree and the project environment
@@ -424,30 +421,24 @@ package body LSP.Ada_Handlers.Project_Loading is
424421
Environment : GPR2.Environment.Object :=
425422
GPR2.Environment.Process_Environment;
426423

427-
Alire_TOML : constant GNATCOLL.VFS.Virtual_File :=
428-
(if Self.Client.Root.Is_Empty then GNATCOLL.VFS.No_File
429-
else Root (Self).Create_From_Dir ("alire.toml"));
430-
431424
begin
432-
if Alire_TOML.Is_Regular_File
433-
and Spawn.Environments.System_Environment.Value ("ALIRE") /= "True"
434-
then
425+
if LSP.Alire.Alire_Active (Self.Client) then
435426

436427
Self.Tracer.Trace ("Check alire:");
437428

438429
if Project.Is_Empty then
439430

440-
LSP.Ada_Handlers.Alire.Determine_Alire_Project
441-
(Root => Root (Self).Display_Full_Name,
431+
LSP.Alire.Determine_Alire_Project
432+
(Root => Self.Client.Root_Directory.Display_Full_Name,
442433
Has_Alire => Has_Alire,
443434
Error => Errors,
444435
Project => Project);
445436

446437
Status := Alire_Project;
447438
end if;
448439

449-
LSP.Ada_Handlers.Alire.Setup_Alire_Env
450-
(Root => Root (Self).Display_Full_Name,
440+
LSP.Alire.Setup_Alire_Env
441+
(Root => Self.Client.Root_Directory.Display_Full_Name,
451442
Has_Alire => Has_Alire,
452443
Error => Errors,
453444
Environment => Environment);
@@ -628,23 +619,6 @@ package body LSP.Ada_Handlers.Project_Loading is
628619
end if;
629620
end Reload_Project;
630621

631-
----------
632-
-- Root --
633-
----------
634-
635-
function Root
636-
(Self : Message_Handler'Class) return GNATCOLL.VFS.Virtual_File
637-
is
638-
Value : constant VSS.Strings.Virtual_String := Self.Client.Root;
639-
Root : constant String :=
640-
VSS.Strings.Conversions.To_UTF_8_String (Value);
641-
begin
642-
return GNATCOLL.VFS.Create_From_UTF8
643-
(if Value.Starts_With ("file://")
644-
then URIs.Conversions.To_File (Root, True)
645-
else Root);
646-
end Root;
647-
648622
---------------------------------------
649623
-- Update_Project_Predefined_Sources --
650624
---------------------------------------

source/ada/lsp-ada_handlers-alire.adb renamed to source/ada/lsp-alire.adb

+20-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
with Ada.Streams;
1919
with GNAT.OS_Lib;
20+
with GNATCOLL.VFS;
2021

2122
with VSS.Stream_Element_Vectors;
2223
with VSS.Strings.Conversions;
@@ -25,12 +26,13 @@ with VSS.String_Vectors;
2526
with VSS.Characters.Latin;
2627
with VSS.Regular_Expressions;
2728

29+
with Spawn.Environments;
2830
with Spawn.Processes;
2931
with Spawn.Processes.Monitor_Loop;
3032
with Spawn.Process_Listeners;
3133
with Spawn.String_Vectors;
3234

33-
package body LSP.Ada_Handlers.Alire is
35+
package body LSP.Alire is
3436

3537
type Process_Listener is limited
3638
new Spawn.Process_Listeners.Process_Listener with record
@@ -347,4 +349,20 @@ package body LSP.Ada_Handlers.Alire is
347349
end loop;
348350
end Standard_Output_Available;
349351

350-
end LSP.Ada_Handlers.Alire;
352+
------------------
353+
-- Alire_Active --
354+
------------------
355+
356+
function Alire_Active
357+
(Client : LSP.Ada_Client_Capabilities.Client_Capability) return Boolean is
358+
Alire_TOML : constant GNATCOLL.VFS.Virtual_File :=
359+
(if Client.Root.Is_Empty then GNATCOLL.VFS.No_File
360+
else Client.Root_Directory.Create_From_Dir
361+
("alire.toml"));
362+
363+
begin
364+
return Alire_TOML.Is_Regular_File
365+
and Spawn.Environments.System_Environment.Value ("ALIRE") /= "True";
366+
end Alire_Active;
367+
368+
end LSP.Alire;

source/ada/lsp-ada_handlers-alire.ads renamed to source/ada/lsp-alire.ads

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919

2020
with GPR2.Environment;
2121

22+
with LSP.Ada_Client_Capabilities;
23+
2224
with VSS.Strings;
2325

2426
private
25-
package LSP.Ada_Handlers.Alire is
27+
package LSP.Alire is
28+
29+
function Alire_Active
30+
(Client : LSP.Ada_Client_Capabilities.Client_Capability) return Boolean;
31+
-- True if 'alire.toml' exists at 'Client' root & $ALIRE variable is True
2632

2733
procedure Determine_Alire_Project
2834
(Root : String;
@@ -39,4 +45,4 @@ package LSP.Ada_Handlers.Alire is
3945
Environment : in out GPR2.Environment.Object);
4046
-- Run `alr printenv` and set up the obtained environment variables
4147

42-
end LSP.Ada_Handlers.Alire;
48+
end LSP.Alire;

source/ada/lsp-utils.ads

+5
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,9 @@ package LSP.Utils is
131131
(VSS.Strings.Conversions.To_Virtual_String (Value.Display_Full_Name));
132132
-- Cast Virtual_File to Virtual_String
133133

134+
function To_Virtual_String
135+
(Path : GPR2.Path_Name.Object) return VSS.Strings.Virtual_String is
136+
(VSS.Strings.Conversions.To_Virtual_String (Path.Value));
137+
-- Cast GPR2.Path_Name.Object to Virtual_String
138+
134139
end LSP.Utils;

source/gpr/lsp-gpr_client_capabilities.adb

-55
This file was deleted.

source/gpr/lsp-gpr_client_capabilities.ads

-40
This file was deleted.

source/gpr/lsp-gpr_did_change_document.adb

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ package body LSP.GPR_Did_Change_Document is
104104

105105
-- Load gpr tree & prepare diagnostics
106106

107-
Self.Document.Load (Self.Parent.Context.Get_Configuration);
107+
Self.Document.Load
108+
(Client => Self.Parent.Context.Get_Client.all,
109+
Configuration => Self.Parent.Context.Get_Configuration);
108110

109111
-- Build GPR file for LSP needs.
110112

source/gpr/lsp-gpr_documents.adb

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ package body LSP.GPR_Documents is
150150

151151
procedure Load
152152
(Self : in out Document;
153+
Client : LSP.Ada_Client_Capabilities.Client_Capability;
153154
Configuration : LSP.Ada_Configurations.Configuration) is
154155

155156
procedure Update_Diagnostics;
@@ -186,7 +187,7 @@ package body LSP.GPR_Documents is
186187
Context => Configuration.Context,
187188
Build_Path => Configuration.Build_Path (Self.File),
188189
File_Reader => Self.File_Provider.Get_File_Reader,
189-
Environment => Self.Environment);
190+
Environment => LSP.GPR_Files.Environment);
190191

191192
Update_Diagnostics;
192193

0 commit comments

Comments
 (0)