Skip to content

Commit 218d67f

Browse files
author
Philippe Gil
committed
Use configuration when loading project
Closes eng/ide/ada_language_server#1357
1 parent 4cefdec commit 218d67f

15 files changed

+474
-97
lines changed

source/ada/lsp-ada_configurations.adb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pragma Ada_2022;
2020
with Ada.Containers.Generic_Anonymous_Array_Sort;
2121

2222
with GNATCOLL.Traces;
23+
with GNATCOLL.VFS;
24+
25+
with LSP.Utils;
2326

2427
with VSS.JSON.Pull_Readers.Simple;
2528
with VSS.JSON.Streams;
@@ -71,6 +74,43 @@ package body LSP.Ada_Configurations is
7174
From : Positive;
7275
Reload : out Boolean);
7376

77+
----------------
78+
-- Build_Path --
79+
----------------
80+
81+
function Build_Path
82+
(Self : Configuration'Class;
83+
File : GPR2.Path_Name.Object)
84+
return GPR2.Path_Name.Object
85+
is
86+
Result : GPR2.Path_Name.Object;
87+
88+
Relocate_Build_Tree : constant GNATCOLL.VFS.Virtual_File :=
89+
LSP.Utils.To_Virtual_File
90+
(Self.Relocate_Build_Tree);
91+
92+
Root_Dir : constant GNATCOLL.VFS.Virtual_File :=
93+
LSP.Utils.To_Virtual_File (Self.Relocate_Root);
94+
95+
begin
96+
if not Self.Relocate_Build_Tree.Is_Empty then
97+
Result := GPR2.Path_Name.Create (Relocate_Build_Tree);
98+
99+
if not Self.Relocate_Root.Is_Empty and then File.Is_Defined
100+
then
101+
if not Root_Dir.Is_Absolute_Path then
102+
Result :=
103+
GPR2.Path_Name.Create_Directory
104+
(File.Relative_Path
105+
(GPR2.Path_Name.Create (Root_Dir)),
106+
GPR2.Filename_Type
107+
(Result.Value));
108+
end if;
109+
end if;
110+
end if;
111+
return Result;
112+
end Build_Path;
113+
74114
---------------------------
75115
-- Completion_Formatting --
76116
---------------------------
@@ -217,6 +257,17 @@ package body LSP.Ada_Configurations is
217257
Self.Variables_Names := Variables_Names;
218258
Self.Variables_Values := Variables_Values;
219259

260+
-- Replace Context with user provided values
261+
Self.Context.Clear;
262+
for J in 1 .. Variables_Names.Length loop
263+
Self.Context.Insert
264+
(GPR2.Optional_Name_Type
265+
(VSS.Strings.Conversions.To_UTF_8_String
266+
(Variables_Names (J))),
267+
VSS.Strings.Conversions.To_UTF_8_String
268+
(Variables_Values (J)));
269+
end loop;
270+
220271
elsif Name = "defaultCharset"
221272
and then JSON (Index).Kind = String_Value
222273
then

source/ada/lsp-ada_configurations.ads

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ with VSS.String_Vectors;
2424
with LSP.Enumerations;
2525
with LSP.Structures;
2626

27+
with GPR2.Context;
28+
with GPR2.Path_Name;
29+
2730
package LSP.Ada_Configurations is
2831

2932
type Configuration is tagged private;
@@ -93,18 +96,19 @@ package LSP.Ada_Configurations is
9396
function Documentation_Style (Self : Configuration'Class)
9497
return GNATdoc.Comments.Options.Documentation_Style;
9598

96-
type Variable_List is record
97-
Names : VSS.String_Vectors.Virtual_String_Vector;
98-
Values : VSS.String_Vectors.Virtual_String_Vector;
99-
end record;
100-
101-
function Scenario_Variables
102-
(Self : Configuration'Class) return Variable_List;
103-
-- Scenario variables, if provided by the user on Configuration/Init
104-
10599
function Display_Method_Ancestry_Policy (Self : Configuration'Class)
106100
return LSP.Enumerations.AlsDisplayMethodAncestryOnNavigationPolicy;
107101

102+
function Build_Path
103+
(Self : Configuration'Class; File : GPR2.Path_Name.Object)
104+
return GPR2.Path_Name.Object;
105+
-- Convert Self.Relocate_Build_Tree, Self.Relocate_Root & File to
106+
-- GPR2.Project.Tree.Load procedures Build_Path parameter.
107+
108+
function Context (Self : Configuration'Class) return GPR2.Context.Object;
109+
-- Convert Configuration scenario variables to
110+
-- GPR2.Project.Tree.Load procedures Context parameter.
111+
108112
function Completion_Formatting return Boolean;
109113
-- Used in LSP.Ada_Completions.Pretty_Print_Snippet
110114

@@ -146,6 +150,8 @@ private
146150

147151
Variables_Names : VSS.String_Vectors.Virtual_String_Vector;
148152
Variables_Values : VSS.String_Vectors.Virtual_String_Vector;
153+
154+
Context : GPR2.Context.Object;
149155
end record;
150156

151157
function Project_File
@@ -164,10 +170,6 @@ private
164170
(Self : Configuration'Class) return VSS.Strings.Virtual_String is
165171
(Self.Relocate_Root);
166172

167-
function Scenario_Variables
168-
(Self : Configuration'Class) return Variable_List is
169-
((Self.Variables_Names, Self.Variables_Values));
170-
171173
function Diagnostics_Enabled (Self : Configuration'Class) return Boolean is
172174
(Self.Diagnostics_Enabled);
173175

@@ -216,4 +218,7 @@ private
216218
(firstTriggerCharacter => 1 * VSS.Characters.Latin.Line_Feed,
217219
moreTriggerCharacter => <>);
218220

221+
function Context (Self : Configuration'Class) return GPR2.Context.Object
222+
is (Self.Context);
223+
219224
end LSP.Ada_Configurations;

source/ada/lsp-ada_handlers-project_loading.adb

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
with GNATCOLL.Traces;
1919
with GNATCOLL.VFS;
2020

21-
with GPR2.Context;
2221
with GPR2.Path_Name;
2322
with GPR2.Project.View;
2423
with GPR2.Containers;
@@ -29,7 +28,6 @@ with GPR2.Project.Tree.View_Builder;
2928
with Libadalang.Preprocessing;
3029

3130
with VSS.Strings.Conversions;
32-
with VSS.String_Vectors;
3331

3432
with Spawn.Environments;
3533

@@ -40,6 +38,7 @@ with LSP.Ada_Handlers.File_Readers;
4038
with LSP.Ada_Indexing;
4139
with LSP.Enumerations;
4240
with LSP.Structures;
41+
with LSP.Utils;
4342

4443
with URIs;
4544
with LSP.Ada_Documents; use LSP.Ada_Documents;
@@ -54,7 +53,7 @@ package body LSP.Ada_Handlers.Project_Loading is
5453
procedure Load_Project_With_Alire
5554
(Self : in out Message_Handler'Class;
5655
Project_File : VSS.Strings.Virtual_String := "";
57-
Scenario_Variables : LSP.Ada_Configurations.Variable_List;
56+
Context : GPR2.Context.Object;
5857
Charset : VSS.Strings.Virtual_String);
5958
-- Core procedure to find project, search path, scenario and load the
6059
-- project.
@@ -86,26 +85,10 @@ package body LSP.Ada_Handlers.Project_Loading is
8685
-- Mark all sources in all projects for indexing. This factorizes code
8786
-- between Load_Project and Load_Implicit_Project.
8887

89-
function To_Virtual_String
90-
(Value : GNATCOLL.VFS.Virtual_File) return VSS.Strings.Virtual_String is
91-
(VSS.Strings.Conversions.To_Virtual_String (Value.Display_Full_Name));
92-
-- Cast Virtual_File to Virtual_String
93-
94-
function To_Virtual_File
95-
(Value : VSS.Strings.Virtual_String) return GNATCOLL.VFS.Virtual_File is
96-
(GNATCOLL.VFS.Create_From_UTF8
97-
(VSS.Strings.Conversions.To_UTF_8_String (Value)));
98-
-- Cast Virtual_String to Virtual_File
99-
10088
function Root
10189
(Self : Message_Handler'Class) return GNATCOLL.VFS.Virtual_File;
10290
-- Return the root directory of the client workspace
10391

104-
type Environment is record
105-
Context : GPR2.Context.Object := GPR2.Context.Empty;
106-
Build_Path : GPR2.Path_Name.Object := GPR2.Path_Name.Undefined;
107-
end record;
108-
10992
---------------------------
11093
-- Ensure_Project_Loaded --
11194
---------------------------
@@ -127,7 +110,7 @@ package body LSP.Ada_Handlers.Project_Loading is
127110
Load_Project_With_Alire
128111
(Self => Self,
129112
Project_File => VSS.Strings.Empty_Virtual_String,
130-
Scenario_Variables => Self.Configuration.Scenario_Variables,
113+
Context => Self.Configuration.Context,
131114
Charset => Self.Configuration.Charset);
132115

133116
if not Self.Contexts.Is_Empty then
@@ -148,7 +131,7 @@ package body LSP.Ada_Handlers.Project_Loading is
148131
if X.Has_Suffix (".gpr") then
149132
GPRs_Found := GPRs_Found + 1;
150133
exit when GPRs_Found > 1;
151-
Project_File := To_Virtual_String (X);
134+
Project_File := LSP.Utils.To_Virtual_String (X);
152135
end if;
153136
end loop;
154137

@@ -169,7 +152,7 @@ package body LSP.Ada_Handlers.Project_Loading is
169152

170153
Load_Project
171154
(Self => Self, Project_Path => Project_File,
172-
Scenario => Self.Configuration.Scenario_Variables,
155+
Context => Self.Configuration.Context,
173156
Environment => GPR2.Environment.Process_Environment,
174157
Charset => "iso-8859-1",
175158
Status => Single_Project_Found);
@@ -243,23 +226,13 @@ package body LSP.Ada_Handlers.Project_Loading is
243226
procedure Load_Project
244227
(Self : in out Message_Handler'Class;
245228
Project_Path : VSS.Strings.Virtual_String;
246-
Scenario : LSP.Ada_Configurations.Variable_List;
229+
Context : GPR2.Context.Object;
247230
Environment : GPR2.Environment.Object;
248231
Charset : VSS.Strings.Virtual_String;
249232
Status : Load_Project_Status)
250233
is
251-
use type GNATCOLL.VFS.Virtual_File;
252-
253234
Project_File : GNATCOLL.VFS.Virtual_File :=
254-
To_Virtual_File (Project_Path);
255-
256-
Project_Environment : Project_Loading.Environment;
257-
258-
Relocate_Build_Tree : constant GNATCOLL.VFS.Virtual_File :=
259-
To_Virtual_File (Self.Configuration.Relocate_Build_Tree);
260-
261-
Root_Dir : constant GNATCOLL.VFS.Virtual_File :=
262-
To_Virtual_File (Self.Configuration.Relocate_Root);
235+
LSP.Utils.To_Virtual_File (Project_Path);
263236

264237
procedure Create_Context_For_Non_Aggregate
265238
(View : GPR2.Project.View.Object);
@@ -276,7 +249,7 @@ package body LSP.Ada_Handlers.Project_Loading is
276249
use LSP.Ada_Contexts;
277250

278251
C : constant Context_Access :=
279-
new Context (Self.Tracer);
252+
new LSP.Ada_Contexts.Context (Self.Tracer);
280253

281254
Reader : LSP.Ada_Handlers.File_Readers.LSP_File_Reader
282255
(Self'Unchecked_Access);
@@ -350,37 +323,12 @@ package body LSP.Ada_Handlers.Project_Loading is
350323
-- Now load the new project
351324
Self.Project_Status.Load_Status := Status;
352325

353-
if not Self.Configuration.Relocate_Build_Tree.Is_Empty then
354-
Project_Environment.Build_Path :=
355-
GPR2.Path_Name.Create (Relocate_Build_Tree);
356-
357-
if not Self.Configuration.Relocate_Root.Is_Empty
358-
and then Project_File /= GNATCOLL.VFS.No_File
359-
then
360-
if not Root_Dir.Is_Absolute_Path then
361-
Project_Environment.Build_Path :=
362-
GPR2.Path_Name.Create_Directory
363-
(GPR2.Path_Name.Create (Project_File).Relative_Path
364-
(GPR2.Path_Name.Create (Root_Dir)),
365-
GPR2.Filename_Type
366-
(Project_Environment.Build_Path.Value));
367-
end if;
368-
end if;
369-
end if;
370-
371-
-- Update scenario variables with user provided values
372-
for J in 1 .. Scenario.Names.Length loop
373-
Project_Environment.Context.Insert
374-
(GPR2.Optional_Name_Type
375-
(VSS.Strings.Conversions.To_UTF_8_String (Scenario.Names (J))),
376-
VSS.Strings.Conversions.To_UTF_8_String (Scenario.Values (J)));
377-
end loop;
378-
379326
begin
380327
Self.Project_Tree.Load_Autoconf
381328
(Filename => GPR2.Path_Name.Create (Project_File),
382-
Context => Project_Environment.Context,
383-
Build_Path => Project_Environment.Build_Path,
329+
Context => Context,
330+
Build_Path => LSP.Ada_Configurations.Build_Path
331+
(Self.Configuration, GPR2.Path_Name.Create (Project_File)),
384332
Environment => Environment);
385333

386334
if Self.Project_Tree.Are_Sources_Loaded then
@@ -454,7 +402,7 @@ package body LSP.Ada_Handlers.Project_Loading is
454402
procedure Load_Project_With_Alire
455403
(Self : in out Message_Handler'Class;
456404
Project_File : VSS.Strings.Virtual_String := "";
457-
Scenario_Variables : LSP.Ada_Configurations.Variable_List;
405+
Context : GPR2.Context.Object;
458406
Charset : VSS.Strings.Virtual_String)
459407
is
460408

@@ -527,7 +475,7 @@ package body LSP.Ada_Handlers.Project_Loading is
527475
Load_Project
528476
(Self => Self,
529477
Project_Path => Project,
530-
Scenario => Scenario_Variables,
478+
Context => Context,
531479
Environment => Environment,
532480
Charset => (if Charset.Is_Empty then UTF_8 else Charset),
533481
Status => Status);
@@ -545,7 +493,7 @@ package body LSP.Ada_Handlers.Project_Loading is
545493
Load_Project
546494
(Self => Self,
547495
Project_Path => Project,
548-
Scenario => Scenario_Variables,
496+
Context => Context,
549497
Environment => Environment,
550498
Charset => Charset,
551499
Status => Valid_Project_Configured);
@@ -668,7 +616,7 @@ package body LSP.Ada_Handlers.Project_Loading is
668616
Load_Project_With_Alire
669617
(Self,
670618
Project_File,
671-
Self.Configuration.Scenario_Variables,
619+
Self.Configuration.Context,
672620
Self.Configuration.Charset);
673621
end if;
674622
end Reload_Project;

source/ada/lsp-ada_handlers-project_loading.ads

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
with VSS.Strings;
1919
with GPR2.Environment;
20-
21-
with LSP.Ada_Configurations;
20+
with GPR2.Context;
2221

2322
private
2423

@@ -27,7 +26,7 @@ package LSP.Ada_Handlers.Project_Loading is
2726
procedure Load_Project
2827
(Self : in out Message_Handler'Class;
2928
Project_Path : VSS.Strings.Virtual_String;
30-
Scenario : LSP.Ada_Configurations.Variable_List;
29+
Context : GPR2.Context.Object;
3130
Environment : GPR2.Environment.Object;
3231
Charset : VSS.Strings.Virtual_String;
3332
Status : Load_Project_Status);

source/ada/lsp-utils.adb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
with Ada.Strings.Unbounded;
1919
with System;
2020

21-
with GNATCOLL.VFS;
22-
2321
with Libadalang.Common;
2422
with Libadalang.Lexer;
2523
with Libadalang.Sources;
@@ -29,7 +27,6 @@ with Langkit_Support.Token_Data_Handlers;
2927
with Pp.Actions;
3028

3129
with VSS.Strings.Character_Iterators;
32-
with VSS.Strings.Conversions;
3330
with VSS.Strings.Formatters.Generic_Modulars;
3431
with VSS.Strings.Formatters.Integers;
3532
with VSS.Strings.Templates;

0 commit comments

Comments
 (0)