@@ -47,6 +47,34 @@ package body LSP.GPR_Files is
4747 package Convert is new VSS.Strings.Formatters.Generic_Integers (Unit_Index);
4848 package Conversions renames VSS.Strings.Conversions;
4949
50+ function Is_Between
51+ (Position : LSP.Structures.Position;
52+ Span : LSP.Structures.A_Range)
53+ return Boolean
54+ is ((Position.line = Span.start.line
55+ and then Position.character >= Span.start.character)
56+ or else (Position.line = Span.an_end.line
57+ and then Position.character <= Span.an_end.character)
58+ or else (Position.line > Span.start.line
59+ and then Position.line < Span.an_end.line));
60+ -- Checks if Position is inside Span
61+
62+ -- ---------------
63+ -- Get_Package --
64+ -- ---------------
65+
66+ function Get_Package
67+ (Self : File; Position : LSP.Structures.Position) return GPR2.Package_Id
68+ is
69+ begin
70+ for P of Self.Packages loop
71+ if Is_Between (Position, P.Package_Range) then
72+ return P.Name;
73+ end if ;
74+ end loop ;
75+ return GPR2.Project_Level_Scope;
76+ end Get_Package ;
77+
5078 -- ------
5179 -- Id --
5280 -- ------
@@ -315,6 +343,26 @@ package body LSP.GPR_Files is
315343 begin
316344 if Current_Package.Name /= Project_Level_Scope then
317345 Current_Package.Last := Last_Index;
346+
347+ -- Initialize Package_Range
348+
349+ declare
350+ Location_Range : Slocs.Source_Location_Range :=
351+ Gpr_Parser.Common.Sloc_Range
352+ (Gpr_Parser.Common.Data (Current_Package.First));
353+ begin
354+ Current_Package.Package_Range.start.line :=
355+ To_Position_Value (Location_Range.Start_Line);
356+ Current_Package.Package_Range.start.character :=
357+ To_Position_Value (Location_Range.Start_Column);
358+ Location_Range := Gpr_Parser.Common.Sloc_Range
359+ (Gpr_Parser.Common.Data (Current_Package.Last));
360+ Current_Package.Package_Range.an_end.line :=
361+ To_Position_Value (Location_Range.Start_Line);
362+ Current_Package.Package_Range.an_end.character :=
363+ To_Position_Value (Location_Range.Start_Column);
364+ end ;
365+
318366 if not File.Packages.Contains (Current_Package.Name) then
319367 File.Packages.Insert (Current_Package.Name, Current_Package);
320368 end if ;
@@ -981,4 +1029,21 @@ package body LSP.GPR_Files is
9811029 end if ;
9821030 end Cleanup ;
9831031
1032+ -- ---------
1033+ -- Token --
1034+ -- ---------
1035+
1036+ function Token
1037+ (Self : File;
1038+ Position : LSP.Structures.Position)
1039+ return Gpr_Parser.Common.Token_Reference is
1040+ Sloc : constant Source_Location :=
1041+ (To_Line_Number (Position.line),
1042+ To_Column_Number (Position.character));
1043+
1044+ begin
1045+ return Self.Unit.Lookup_Token (Sloc);
1046+
1047+ end Token ;
1048+
9841049end LSP.GPR_Files ;
0 commit comments