Skip to content

Commit eb7d6cb

Browse files
author
mergerepo
committed
Merge remote branch 'origin/master' into edge
(no-precommit-check no-tn-check)
2 parents 3d92029 + 658ba16 commit eb7d6cb

11 files changed

+319
-505
lines changed

source/ada/lsp-ada_contexts.adb

Lines changed: 71 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ with Ada.Characters.Handling; use Ada.Characters.Handling;
1919

2020
with GNAT.Strings;
2121

22+
with GNATCOLL.Projects; use GNATCOLL.Projects;
2223
with GNATCOLL.Traces; use GNATCOLL.Traces;
2324
with GNATCOLL.VFS; use GNATCOLL.VFS;
2425

25-
with GPR2.Containers;
26-
with GPR2.Path_Name;
27-
with GPR2.Project.Attribute;
28-
with GPR2.Project.Attribute_Index;
29-
with GPR2.Project.Source;
30-
3126
with VSS.Strings.Conversions;
3227

3328
with URIs;
@@ -265,7 +260,7 @@ package body LSP.Ada_Contexts is
265260
File : GNATCOLL.VFS.Virtual_File;
266261
Reparse : Boolean := False) return Libadalang.Analysis.Analysis_Unit is
267262
begin
268-
if not Is_Ada_File (Self.Tree.all, File) then
263+
if not Is_Ada_File (Self.Tree, File) then
269264
return Libadalang.Analysis.No_Analysis_Unit;
270265
end if;
271266

@@ -687,10 +682,10 @@ package body LSP.Ada_Contexts is
687682
------------------
688683

689684
procedure Load_Project
690-
(Self : in out Context;
691-
Tree : GPR2.Project.Tree.Object;
692-
Root : GPR2.Project.View.Object;
693-
Charset : String)
685+
(Self : in out Context;
686+
Tree : not null GNATCOLL.Projects.Project_Tree_Access;
687+
Root : Project_Type;
688+
Charset : String)
694689
is
695690
procedure Update_Source_Files;
696691
-- Update the value of Self.Source_Files
@@ -702,47 +697,44 @@ package body LSP.Ada_Contexts is
702697
-------------------------
703698

704699
procedure Update_Source_Files is
705-
706-
procedure Insert_Source (Source : GPR2.Project.Source.Object);
707-
-- Insert Source in Self.Source_Files
708-
709-
-------------------
710-
-- Insert_Source --
711-
-------------------
712-
713-
procedure Insert_Source (Source : GPR2.Project.Source.Object) is
714-
Path : constant Virtual_File := Source.Path_Name.Virtual_File;
715-
begin
716-
if not Self.Source_Files.Contains (Path) then
717-
Self.Source_Files.Include (Path);
700+
All_Sources : File_Array_Access :=
701+
Root.Source_Files (Recursive => True);
702+
All_Ada_Sources : File_Array (1 .. All_Sources'Length);
703+
Free_Index : Natural := All_Ada_Sources'First;
704+
begin
705+
-- Iterate through all sources, returning only those that have Ada
706+
-- as language.
707+
for J in All_Sources'Range loop
708+
if Is_Ada_File (Self.Tree, All_Sources (J)) then
709+
All_Ada_Sources (Free_Index) := All_Sources (J);
710+
Free_Index := Free_Index + 1;
718711
end if;
719-
end Insert_Source;
712+
end loop;
720713

721-
begin
714+
Unchecked_Free (All_Sources);
722715
Self.Source_Files.Clear;
723716

724-
Tree.For_Each_Source
725-
(View => Root,
726-
Action => Insert_Source'Access,
727-
Language => GPR2.Ada_Language,
728-
Externally_Built => True);
717+
for Index in 1 .. Free_Index - 1 loop
718+
Self.Source_Files.Include (All_Ada_Sources (Index));
719+
end loop;
729720

730721
Self.Source_Dirs.Clear;
722+
Self.External_Source_Dirs.Clear;
731723

732-
for Dir of Tree.Source_Directories
733-
(View => Root,
734-
Externally_Built => False)
724+
for Dir of Source_Dirs
725+
(Project => Root,
726+
Recursive => True,
727+
Include_Externally_Built => False)
735728
loop
736-
Self.Source_Dirs.Include (Dir.Virtual_File);
729+
Self.Source_Dirs.Include (Dir);
737730
end loop;
738731

739-
Self.External_Source_Dirs.Clear;
740-
741-
for Dir of Tree.Source_Directories
742-
(View => Root,
743-
Externally_Built => True)
732+
for Dir of Source_Dirs
733+
(Project => Root,
734+
Recursive => True,
735+
Include_Externally_Built => True)
744736
loop
745-
Self.External_Source_Dirs.Include (Dir.Virtual_File);
737+
Self.External_Source_Dirs.Include (Dir);
746738
end loop;
747739
end Update_Source_Files;
748740

@@ -752,45 +744,39 @@ package body LSP.Ada_Contexts is
752744

753745
procedure Pretty_Printer_Setup
754746
is
747+
use type GNAT.Strings.String_Access;
748+
Options : GNAT.Strings.String_List_Access;
755749
Validated : GNAT.Strings.String_List_Access;
756-
Index : Integer := 0;
757-
Attribute : GPR2.Project.Attribute.Object;
758-
Values : GPR2.Containers.Value_List;
750+
Last : Integer;
751+
Default : Boolean;
759752
begin
753+
Root.Switches
754+
(In_Pkg => "Pretty_Printer",
755+
File => GNATCOLL.VFS.No_File,
756+
Language => "ada",
757+
Value => Options,
758+
Is_Default_Value => Default);
760759

761760
-- Initialize an gnatpp command line object
761+
Last := Options'First - 1;
762+
for Item of Options.all loop
763+
if Item /= null
764+
and then Item.all /= ""
765+
then
766+
Last := Last + 1;
767+
end if;
768+
end loop;
762769

763-
if Root.Check_Attribute
764-
(Name => LSP.Common.Pretty_Printer.Switches,
765-
Index => LSP.Common.Ada_Index,
766-
Result => Attribute)
767-
then
768-
769-
-- Fill 'Values' with non empty value
770-
771-
for Value of Attribute.Values loop
772-
declare
773-
Text : constant String := Value.Text;
774-
begin
775-
if Text /= "" then
776-
Values.Append (Text);
777-
Index := Index + 1;
778-
end if;
779-
end;
780-
end loop;
781-
782-
Validated := new GNAT.Strings.String_List (1 .. Index);
783-
784-
if Index > 0 then
785-
Index := Validated'First;
786-
for Text of Values loop
787-
Validated (Index) := new String'(Text);
788-
Index := Index + 1;
789-
end loop;
770+
Validated := new GNAT.Strings.String_List (Options'First .. Last);
771+
Last := Options'First - 1;
772+
for Item of Options.all loop
773+
if Item /= null
774+
and then Item.all /= ""
775+
then
776+
Last := Last + 1;
777+
Validated (Last) := new String'(Item.all);
790778
end if;
791-
else
792-
Validated := new GNAT.Strings.String_List (1 .. 0);
793-
end if;
779+
end loop;
794780

795781
Utils.Command_Lines.Parse
796782
(Validated,
@@ -800,21 +786,24 @@ package body LSP.Ada_Contexts is
800786
Collect_File_Names => False,
801787
Ignore_Errors => True);
802788

789+
GNAT.Strings.Free (Options);
803790
GNAT.Strings.Free (Validated);
804791

805792
-- Set UTF-8 encoding
806793
Utils.Command_Lines.Common.Set_WCEM (Self.PP_Options, "8");
807794
end Pretty_Printer_Setup;
808795

809796
begin
810-
Self.Id := VSS.Strings.Conversions.To_Virtual_String
811-
(String (Root.Name));
812-
Self.Tree := Tree.Reference;
797+
Self.Id := VSS.Strings.Conversions.To_Virtual_String (Root.Name);
798+
Self.Tree := Tree;
813799
Self.Charset := Ada.Strings.Unbounded.To_Unbounded_String (Charset);
814800

815801
Self.Unit_Provider :=
816802
Libadalang.Project_Provider.Create_Project_Unit_Provider
817-
(Tree => Tree, Project => Root);
803+
(Tree => Tree,
804+
Project => Root,
805+
Env => Get_Environment (Root),
806+
Is_Project_Owner => False);
818807

819808
Self.Event_Handler := Libadalang.Analysis.Create_Event_Handler_Reference
820809
(LSP_Context_Event_Handler_Type'(Trace => Self.Trace));
@@ -1174,49 +1163,12 @@ package body LSP.Ada_Contexts is
11741163

11751164
function Project_Attribute_Value
11761165
(Self : Context;
1177-
Attribute : GPR2.Q_Attribute_Id;
1166+
Attribute : Attribute_Pkg_String;
11781167
Index : String := "";
11791168
Default : String := "";
11801169
Use_Extended : Boolean := False) return String
1181-
is
1182-
Attribute_Index : constant GPR2.Project.Attribute_Index.Object :=
1183-
(if Index = ""
1184-
then GPR2.Project.Attribute_Index.Undefined
1185-
else GPR2.Project.Attribute_Index.Create (Index));
1186-
1187-
Attribute_Value : GPR2.Project.Attribute.Object;
1188-
1189-
begin
1190-
if Self.Tree.Root_Project.Check_Attribute
1191-
(Name => Attribute,
1192-
Index => Attribute_Index,
1193-
Result => Attribute_Value)
1194-
then
1195-
return Attribute_Value.Value.Text;
1196-
elsif Use_Extended and then Self.Tree.Root_Project.Is_Extending then
1197-
-- Look at Extended project list as attribute not found in
1198-
-- Root_Project and Use_Extended requested.
1199-
1200-
declare
1201-
Extended_Root : GPR2.Project.View.Object :=
1202-
Self.Tree.Root_Project.Extended_Root;
1203-
begin
1204-
while Extended_Root.Is_Defined loop
1205-
if Extended_Root.Check_Attribute
1206-
(Name => Attribute,
1207-
Index => Attribute_Index,
1208-
Result => Attribute_Value)
1209-
then
1210-
return Attribute_Value.Value.Text;
1211-
elsif Extended_Root.Is_Extending then
1212-
Extended_Root := Extended_Root.Extended_Root;
1213-
else
1214-
Extended_Root := GPR2.Project.View.Undefined;
1215-
end if;
1216-
end loop;
1217-
end;
1218-
end if;
1219-
return Default;
1220-
end Project_Attribute_Value;
1170+
is (if Self.Tree = null then Default
1171+
else Root_Project (Self.Tree.all).
1172+
Attribute_Value (Attribute, Index, Default, Use_Extended));
12211173

12221174
end LSP.Ada_Contexts;

source/ada/lsp-ada_contexts.ads

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
with Ada.Strings.Unbounded;
2121
with Ada.Strings.UTF_Encoding;
2222

23+
with GNATCOLL.Projects;
2324
with GNATCOLL.Traces;
2425
with GNATCOLL.VFS;
2526

2627
with GNATdoc.Comments.Options;
2728

28-
with GPR2.Project.Tree;
29-
with GPR2.Project.View;
30-
3129
with Langkit_Support.File_Readers; use Langkit_Support.File_Readers;
3230
with Laltools.Common;
3331

@@ -66,10 +64,10 @@ package LSP.Ada_Contexts is
6664
-- in particular.
6765

6866
procedure Load_Project
69-
(Self : in out Context;
70-
Tree : GPR2.Project.Tree.Object;
71-
Root : GPR2.Project.View.Object;
72-
Charset : String);
67+
(Self : in out Context;
68+
Tree : not null GNATCOLL.Projects.Project_Tree_Access;
69+
Root : GNATCOLL.Projects.Project_Type;
70+
Charset : String);
7371
-- Use the given project tree, and root project within this project
7472
-- tree, as project for this context. Root must be a non-aggregate
7573
-- project tree representing the root of a hierarchy inside Tree.
@@ -311,7 +309,7 @@ package LSP.Ada_Contexts is
311309

312310
function Project_Attribute_Value
313311
(Self : Context;
314-
Attribute : GPR2.Q_Attribute_Id;
312+
Attribute : GNATCOLL.Projects.Attribute_Pkg_String;
315313
Index : String := "";
316314
Default : String := "";
317315
Use_Extended : Boolean := False) return String;
@@ -340,7 +338,7 @@ private
340338
-- Indicate that this is a "fallback" context, ie the context
341339
-- holding any file, in the case no valid project was loaded.
342340

343-
Tree : access GPR2.Project.Tree.Object;
341+
Tree : GNATCOLL.Projects.Project_Tree_Access;
344342
-- The loaded project tree: we need to keep a reference to this
345343
-- in order to figure out which files are Ada and which are not.
346344
-- Do not deallocate: this is owned by the Message_Handler.

source/ada/lsp-ada_handlers-other_file_commands.adb

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
with Ada.Strings.UTF_Encoding;
1919

20-
with GNATCOLL.Tribooleans;
21-
22-
with GPR2.Project.Source;
23-
2420
with LSP.Messages.Client_Requests;
2521

2622
with VSS.Strings.Conversions;
@@ -78,50 +74,8 @@ package body LSP.Ada_Handlers.Other_File_Commands is
7874
File : constant GNATCOLL.VFS.Virtual_File :=
7975
Message_Handler.To_File (Self.URI);
8076

81-
function Other_File return GNATCOLL.VFS.Virtual_File;
82-
83-
----------------
84-
-- Other_File --
85-
----------------
86-
87-
function Other_File return GNATCOLL.VFS.Virtual_File is
88-
F : constant GPR2.Path_Name.Object := GPR2.Path_Name.Create (File);
89-
begin
90-
for V in Message_Handler.Project_Tree.Iterate
91-
(Status => (GPR2.Project.S_Externally_Built =>
92-
GNATCOLL.Tribooleans.Indeterminate))
93-
loop
94-
declare
95-
Source : constant GPR2.Project.Source.Object :=
96-
GPR2.Project.Tree.Element (V).Source (F);
97-
Other_Part : GPR2.Project.Source.Source_Part;
98-
begin
99-
if Source.Is_Defined then
100-
Other_Part := Source.Other_Part_Unchecked (GPR2.No_Index);
101-
if Other_Part.Source.Is_Defined then
102-
return Other_Part.Source.Path_Name.Virtual_File;
103-
end if;
104-
end if;
105-
end;
106-
end loop;
107-
108-
if Message_Handler.Project_Tree.Has_Runtime_Project then
109-
declare
110-
Source : constant GPR2.Project.Source.Object :=
111-
Message_Handler.Project_Tree.Runtime_Project.
112-
Source (F);
113-
Other_Part : GPR2.Project.Source.Source_Part;
114-
begin
115-
if Source.Is_Defined then
116-
Other_Part := Source.Other_Part_Unchecked (GPR2.No_Index);
117-
if Other_Part.Source.Is_Defined then
118-
return Other_Part.Source.Path_Name.Virtual_File;
119-
end if;
120-
end if;
121-
end;
122-
end if;
123-
return File;
124-
end Other_File;
77+
Other_File : constant GNATCOLL.VFS.Virtual_File :=
78+
Message_Handler.Project_Tree.Other_File (File);
12579

12680
URI : constant LSP.Messages.DocumentUri :=
12781
Message_Handler.From_File (Other_File);

0 commit comments

Comments
 (0)