@@ -19,15 +19,10 @@ with Ada.Characters.Handling; use Ada.Characters.Handling;
19
19
20
20
with GNAT.Strings ;
21
21
22
+ with GNATCOLL.Projects ; use GNATCOLL.Projects;
22
23
with GNATCOLL.Traces ; use GNATCOLL.Traces;
23
24
with GNATCOLL.VFS ; use GNATCOLL.VFS;
24
25
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
-
31
26
with VSS.Strings.Conversions ;
32
27
33
28
with URIs ;
@@ -265,7 +260,7 @@ package body LSP.Ada_Contexts is
265
260
File : GNATCOLL.VFS.Virtual_File;
266
261
Reparse : Boolean := False) return Libadalang.Analysis.Analysis_Unit is
267
262
begin
268
- if not Is_Ada_File (Self.Tree. all , File) then
263
+ if not Is_Ada_File (Self.Tree, File) then
269
264
return Libadalang.Analysis.No_Analysis_Unit;
270
265
end if ;
271
266
@@ -687,10 +682,10 @@ package body LSP.Ada_Contexts is
687
682
-- ----------------
688
683
689
684
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)
694
689
is
695
690
procedure Update_Source_Files ;
696
691
-- Update the value of Self.Source_Files
@@ -702,47 +697,44 @@ package body LSP.Ada_Contexts is
702
697
-- -----------------------
703
698
704
699
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 ;
718
711
end if ;
719
- end Insert_Source ;
712
+ end loop ;
720
713
721
- begin
714
+ Unchecked_Free (All_Sources);
722
715
Self.Source_Files.Clear;
723
716
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 ;
729
720
730
721
Self.Source_Dirs.Clear;
722
+ Self.External_Source_Dirs.Clear;
731
723
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)
735
728
loop
736
- Self.Source_Dirs.Include (Dir.Virtual_File );
729
+ Self.Source_Dirs.Include (Dir);
737
730
end loop ;
738
731
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)
744
736
loop
745
- Self.External_Source_Dirs.Include (Dir.Virtual_File );
737
+ Self.External_Source_Dirs.Include (Dir);
746
738
end loop ;
747
739
end Update_Source_Files ;
748
740
@@ -752,45 +744,39 @@ package body LSP.Ada_Contexts is
752
744
753
745
procedure Pretty_Printer_Setup
754
746
is
747
+ use type GNAT.Strings.String_Access;
748
+ Options : GNAT.Strings.String_List_Access;
755
749
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;
759
752
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);
760
759
761
760
-- 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 ;
762
769
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 );
790
778
end if ;
791
- else
792
- Validated := new GNAT.Strings.String_List (1 .. 0 );
793
- end if ;
779
+ end loop ;
794
780
795
781
Utils.Command_Lines.Parse
796
782
(Validated,
@@ -800,21 +786,24 @@ package body LSP.Ada_Contexts is
800
786
Collect_File_Names => False,
801
787
Ignore_Errors => True);
802
788
789
+ GNAT.Strings.Free (Options);
803
790
GNAT.Strings.Free (Validated);
804
791
805
792
-- Set UTF-8 encoding
806
793
Utils.Command_Lines.Common.Set_WCEM (Self.PP_Options, " 8" );
807
794
end Pretty_Printer_Setup ;
808
795
809
796
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;
813
799
Self.Charset := Ada.Strings.Unbounded.To_Unbounded_String (Charset);
814
800
815
801
Self.Unit_Provider :=
816
802
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);
818
807
819
808
Self.Event_Handler := Libadalang.Analysis.Create_Event_Handler_Reference
820
809
(LSP_Context_Event_Handler_Type'(Trace => Self.Trace));
@@ -1174,49 +1163,12 @@ package body LSP.Ada_Contexts is
1174
1163
1175
1164
function Project_Attribute_Value
1176
1165
(Self : Context;
1177
- Attribute : GPR2.Q_Attribute_Id ;
1166
+ Attribute : Attribute_Pkg_String ;
1178
1167
Index : String := " " ;
1179
1168
Default : String := " " ;
1180
1169
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));
1221
1173
1222
1174
end LSP.Ada_Contexts ;
0 commit comments