@@ -19,10 +19,15 @@ with Ada.Characters.Handling; use Ada.Characters.Handling;
1919
2020with GNAT.Strings ;
2121
22- with GNATCOLL.Projects ; use GNATCOLL.Projects;
2322with GNATCOLL.Traces ; use GNATCOLL.Traces;
2423with GNATCOLL.VFS ; use GNATCOLL.VFS;
2524
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+
2631with VSS.Strings.Conversions ;
2732
2833with URIs ;
@@ -260,7 +265,7 @@ package body LSP.Ada_Contexts is
260265 File : GNATCOLL.VFS.Virtual_File;
261266 Reparse : Boolean := False) return Libadalang.Analysis.Analysis_Unit is
262267 begin
263- if not Is_Ada_File (Self.Tree, File) then
268+ if not Is_Ada_File (Self.Tree. all , File) then
264269 return Libadalang.Analysis.No_Analysis_Unit;
265270 end if ;
266271
@@ -682,10 +687,10 @@ package body LSP.Ada_Contexts is
682687 -- ----------------
683688
684689 procedure Load_Project
685- (Self : in out Context;
686- Tree : not null GNATCOLL.Projects.Project_Tree_Access ;
687- Root : Project_Type ;
688- Charset : String)
690+ (Self : in out Context;
691+ Tree : GPR2.Project.Tree.Object ;
692+ Root : GPR2.Project.View.Object ;
693+ Charset : String)
689694 is
690695 procedure Update_Source_Files ;
691696 -- Update the value of Self.Source_Files
@@ -697,44 +702,47 @@ package body LSP.Ada_Contexts is
697702 -- -----------------------
698703
699704 procedure Update_Source_Files is
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 ;
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);
711718 end if ;
712- end loop ;
719+ end Insert_Source ;
713720
714- Unchecked_Free (All_Sources);
721+ begin
715722 Self.Source_Files.Clear;
716723
717- for Index in 1 .. Free_Index - 1 loop
718- Self.Source_Files.Include (All_Ada_Sources (Index));
719- end loop ;
724+ Tree.For_Each_Source
725+ (View => Root,
726+ Action => Insert_Source'Access ,
727+ Language => GPR2.Ada_Language,
728+ Externally_Built => False);
720729
721730 Self.Source_Dirs.Clear;
722- Self.External_Source_Dirs.Clear;
723731
724- for Dir of Source_Dirs
725- (Project => Root,
726- Recursive => True,
727- Include_Externally_Built => False)
732+ for Dir of Tree.Source_Directories
733+ (View => Root,
734+ Externally_Built => False)
728735 loop
729- Self.Source_Dirs.Include (Dir);
736+ Self.Source_Dirs.Include (Dir.Virtual_File );
730737 end loop ;
731738
732- for Dir of Source_Dirs
733- (Project => Root,
734- Recursive => True,
735- Include_Externally_Built => True)
739+ Self.External_Source_Dirs.Clear;
740+
741+ for Dir of Tree.Source_Directories
742+ (View => Root,
743+ Externally_Built => True)
736744 loop
737- Self.External_Source_Dirs.Include (Dir);
745+ Self.External_Source_Dirs.Include (Dir.Virtual_File );
738746 end loop ;
739747 end Update_Source_Files ;
740748
@@ -744,39 +752,45 @@ package body LSP.Ada_Contexts is
744752
745753 procedure Pretty_Printer_Setup
746754 is
747- use type GNAT.Strings.String_Access;
748- Options : GNAT.Strings.String_List_Access;
749755 Validated : GNAT.Strings.String_List_Access;
750- Last : Integer;
751- Default : Boolean;
756+ Index : Integer := 0 ;
757+ Attribute : GPR2.Project.Attribute.Object;
758+ Values : GPR2.Containers.Value_List;
752759 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);
759760
760761 -- 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 ;
769762
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 );
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 ;
778790 end if ;
779- end loop ;
791+ else
792+ Validated := new GNAT.Strings.String_List (1 .. 0 );
793+ end if ;
780794
781795 Utils.Command_Lines.Parse
782796 (Validated,
@@ -786,24 +800,21 @@ package body LSP.Ada_Contexts is
786800 Collect_File_Names => False,
787801 Ignore_Errors => True);
788802
789- GNAT.Strings.Free (Options);
790803 GNAT.Strings.Free (Validated);
791804
792805 -- Set UTF-8 encoding
793806 Utils.Command_Lines.Common.Set_WCEM (Self.PP_Options, " 8" );
794807 end Pretty_Printer_Setup ;
795808
796809 begin
797- Self.Id := VSS.Strings.Conversions.To_Virtual_String (Root.Name);
798- Self.Tree := Tree;
810+ Self.Id := VSS.Strings.Conversions.To_Virtual_String
811+ (String (Root.Name));
812+ Self.Tree := Tree.Reference;
799813 Self.Charset := Ada.Strings.Unbounded.To_Unbounded_String (Charset);
800814
801815 Self.Unit_Provider :=
802816 Libadalang.Project_Provider.Create_Project_Unit_Provider
803- (Tree => Tree,
804- Project => Root,
805- Env => Get_Environment (Root),
806- Is_Project_Owner => False);
817+ (Tree => Tree, Project => Root);
807818
808819 Self.Event_Handler := Libadalang.Analysis.Create_Event_Handler_Reference
809820 (LSP_Context_Event_Handler_Type'(Trace => Self.Trace));
@@ -1163,12 +1174,49 @@ package body LSP.Ada_Contexts is
11631174
11641175 function Project_Attribute_Value
11651176 (Self : Context;
1166- Attribute : Attribute_Pkg_String ;
1177+ Attribute : GPR2.Q_Attribute_Id ;
11671178 Index : String := " " ;
11681179 Default : String := " " ;
11691180 Use_Extended : Boolean := False) return String
1170- is (if Self.Tree = null then Default
1171- else Root_Project (Self.Tree.all ).
1172- Attribute_Value (Attribute, Index, Default, Use_Extended));
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 ;
11731221
11741222end LSP.Ada_Contexts ;
0 commit comments