@@ -19,15 +19,10 @@ with Ada.Characters.Handling; use Ada.Characters.Handling;
1919
2020with GNAT.Strings ;
2121
22+ with GNATCOLL.Projects ; use GNATCOLL.Projects;
2223with GNATCOLL.Traces ; use GNATCOLL.Traces;
2324with 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-
3126with VSS.Strings.Conversions ;
3227
3328with 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
12221174end LSP.Ada_Contexts ;
0 commit comments