Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic-merge committed Apr 13, 2024
2 parents c2781f5 + 145eeaa commit 01071eb
Show file tree
Hide file tree
Showing 11 changed files with 3,609 additions and 202 deletions.
488 changes: 380 additions & 108 deletions source/gpr/lsp-gpr_completions.adb

Large diffs are not rendered by default.

255 changes: 161 additions & 94 deletions source/gpr/lsp-gpr_files-references.adb

Large diffs are not rendered by default.

128 changes: 128 additions & 0 deletions source/gpr/lsp-gpr_files-references.ads
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,139 @@
--
-- This package provides GPR references API.

with Gpr_Parser.Common;

package LSP.GPR_Files.References is

type Reference is private;

type Ref_Kind is
(No_Ref, Project_Ref, Type_Ref, Variable_Ref, Attribute_Ref, Package_Ref);

function Kind (Ref : Reference) return Ref_Kind;

function Token_Reference
(File : LSP.GPR_Files.File_Access;
Position : LSP.Structures.Position)
return Gpr_Parser.Common.Token_Reference;

function Identifier_Reference
(File : LSP.GPR_Files.File_Access;
Current_Package : GPR2.Package_Id;
Token : Gpr_Parser.Common.Token_Reference)
return Reference;
-- return the Project, Type, Variable, Attribute, Package reference
-- found at 'Location'. 'Current_Package' useful for package's variable.

function Referenced_File
(File : LSP.GPR_Files.File_Access;
Reference : LSP.GPR_Files.References.Reference)
return LSP.GPR_Files.File_Access;

function Referenced_Package
(Reference : LSP.GPR_Files.References.Reference)
return GPR2.Package_Id;

function Has_Project
(Reference : LSP.GPR_Files.References.Reference) return Boolean;

function Is_Project_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean;

function Has_Package
(Reference : LSP.GPR_Files.References.Reference) return Boolean;

function Is_Package_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean;

function Is_Type_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean;

function Is_Variable_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean;

function Is_Attribute_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean;

function In_Type_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean;

No_Reference : constant Reference;
-- No reference found

function Get_Referenced_File
(File : LSP.GPR_Files.File_Access;
Reference : LSP.GPR_Files.References.Reference)
return LSP.GPR_Files.File_Access;

private

package GPC renames Gpr_Parser.Common;

type Reference (Kind : Ref_Kind := No_Ref) is record
Token : Gpr_Parser.Common.Token_Reference := GPC.No_Token;
case Kind is
when No_Ref =>
null;
when others =>
Project : Project_Id := No_Project;
In_Type_Reference : Boolean := False;
case Kind is
when Project_Ref =>
null;
when Type_Ref =>
Typ : Type_Id := No_Type;
when others =>
Pack : GPR2.Package_Id := GPR2.Project_Level_Scope;
case Kind is
when Variable_Ref =>
Variable : Variable_Id := No_Variable;
when Attribute_Ref =>
Attribute : GPR2.Optional_Attribute_Id :=
GPR2.No_Attribute;
Index : Index_Type := No_Index;
when others =>
null;
end case;
end case;
end case;
end record;

No_Reference : constant Reference := (Kind => No_Ref, Token => GPC.No_Token);
-- No reference found

function Has_Project
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
(Reference.Kind /= No_Ref);

function Is_Project_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
(Reference.Kind = Project_Ref);

function Has_Package
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
(Reference.Kind not in No_Ref | Project_Ref | Type_Ref);

function Is_Package_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
(Reference.Kind = Package_Ref);

function Is_Type_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
(Reference.Kind = Type_Ref);

function Is_Variable_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
(Reference.Kind = Variable_Ref);

function Is_Attribute_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
(Reference.Kind = Attribute_Ref);

function In_Type_Reference
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
(if Reference.Kind in Project_Ref | Type_Ref | Package_Ref
then Reference.In_Type_Reference
else False);

end LSP.GPR_Files.References;
99 changes: 99 additions & 0 deletions source/gpr/lsp-gpr_files.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,10 @@ package body LSP.GPR_Files is
begin
File.Token_To_File_Map.Insert (Extended_Index, Extended_Path);
Extended := Parse (File.File_Provider, Extended_Path);
if not File.Name_To_File_Map.Contains (Extended.Name)
then
File.Name_To_File_Map.Insert (Extended.Name, Extended_Path);
end if;
File.Extended := Extended.Name;
File.Extended_All := Extends_All;
File.Extended_Path := Extended_Path;
Expand Down Expand Up @@ -1495,4 +1499,99 @@ package body LSP.GPR_Files is
return Path_Name.Undefined;
end Get_Referenced_GPR;

-----------
-- Types --
-----------

function Types
(Self : LSP.GPR_Files.File)
return VSS.String_Vectors.Virtual_String_Vector
is
Types : VSS.String_Vectors.Virtual_String_Vector;

procedure Handle_Element (Position : Type_Maps.Cursor);

--------------------
-- Handle_Element --
--------------------

procedure Handle_Element (Position : Type_Maps.Cursor) is
begin
Types.Append (Image (Type_Maps.Key (Position)));
end Handle_Element;

begin
Self.Types.Iterate (Handle_Element'Access);
return Types;
end Types;

---------------
-- Variables --
---------------

function Variables
(Self : LSP.GPR_Files.File;
Pack : GPR2.Package_Id)
return VSS.String_Vectors.Virtual_String_Vector is
Vars : VSS.String_Vectors.Virtual_String_Vector;

procedure Handle_Element (Position : Variable_Maps.Cursor);

--------------------
-- Handle_Element --
--------------------

procedure Handle_Element (Position : Variable_Maps.Cursor) is
begin
Vars.Append (Image (Variable_Maps.Key (Position)));
end Handle_Element;

begin

if Pack = GPR2.Project_Level_Scope then
Self.Project_Level_Scope_Defs.Variables.Iterate
(Handle_Element'Access);
else
declare
Cursor : constant LSP.GPR_Files.Package_Maps.Cursor :=
Self.Packages.Find (Pack);
begin
if LSP.GPR_Files.Package_Maps.Has_Element (Cursor) then
LSP.GPR_Files.Package_Maps.Element (Cursor).Variables.Iterate
(Handle_Element'Access);
end if;
end;
end if;
return Vars;
end Variables;

-------------
-- Projects--
-------------

function Projects
(Self : LSP.GPR_Files.File)
return VSS.String_Vectors.Virtual_String_Vector
is
Projects : VSS.String_Vectors.Virtual_String_Vector;

procedure Handle_Element (Position : Project_Id_List.Cursor);

--------------------
-- Handle_Element --
--------------------

procedure Handle_Element (Position : Project_Id_List.Cursor) is
begin
Projects.Append (Image (Project_Id_List.Element (Position)));
end Handle_Element;

begin
Self.Imported.Iterate (Handle_Element'Access);
if Self.Extended /= No_Project then
Projects.Append (Image (Self.Extended));
end if;
return Projects;
end Projects;

end LSP.GPR_Files;
25 changes: 25 additions & 0 deletions source/gpr/lsp-gpr_files.ads
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@ package LSP.GPR_Files is
Token : Gpr_Parser.Common.Token_Reference) return Path_Name.Object;
-- find file pointed by gpr token useful for imported & extended files

function Name
(Self : LSP.GPR_Files.File)
return VSS.Strings.Virtual_String;
-- Self file' name

function Types
(Self : LSP.GPR_Files.File)
return VSS.String_Vectors.Virtual_String_Vector;
-- Self file's types.

function Variables
(Self : LSP.GPR_Files.File;
Pack : GPR2.Package_Id)
return VSS.String_Vectors.Virtual_String_Vector;
-- Self file's package types.

function Projects
(Self : LSP.GPR_Files.File)
return VSS.String_Vectors.Virtual_String_Vector;
-- Self file's non limited imported projects & extended projects.

private

type Source_Position is record
Expand Down Expand Up @@ -675,4 +696,8 @@ private
return Gpr_Parser.Common.Token_Reference is
(Self.Unit.Lookup_Token (Location));

function Name
(Self : LSP.GPR_Files.File)
return VSS.Strings.Virtual_String is (Image (Self.Name));

end LSP.GPR_Files;
9 changes: 9 additions & 0 deletions testsuite/gpr_lsp/completion_references/extended.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project Extended is
type Extended_Type is ("a");
Extended_Variable := "";
for Warning_Message use "warning message";
package Emulator is
Extended_Emulator_Variable := "";
for Board use "";
end Emulator;
end Extended;
9 changes: 9 additions & 0 deletions testsuite/gpr_lsp/completion_references/imported.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project Imported is
type Imported_Type is ("a");
Imported_Variable := "";
for Warning_Message use "warning message";
package Compiler is
Imported_Compiler_Variable := "";
for Local_Configuration_Pragmas use "";
end Compiler;
end Imported;
9 changes: 9 additions & 0 deletions testsuite/gpr_lsp/completion_references/imported_limited.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project Imported_Limited is
type Imported_Limited_Type is ("a");
Imported_Limited_Variable := "";
for Warning_Message use "warning message";
package Compiler is
Imported_Limited_Compiler_Variable := "";
for Local_Configuration_Pragmas use "";
end Compiler;
end Imported_Limited;
68 changes: 68 additions & 0 deletions testsuite/gpr_lsp/completion_references/prj.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
with "imported";
limited with "imported_limited";
project Prj extends "extended" is

type T1 is ("a");

package Compiler is
V1 := "";
for Local_Configuration_Pragmas use "";
end Compiler;

V2 :=
Imported.
Compiler.
Imported_Compiler_Variable;

V3 := project'
Name;

V4 := Extended.Emulator'
Board;

for Object_Dir use
Prj.Compiler'
Local_Configuration_Pragmas;

for Source_Dirs use (
".");

for Source_Dirs use ("." &
".");

for Source_Dirs use (".",
"..");

V5 :
Imported.
Imported_Type := "a";

V5 :
Extended.
Extended_Type := "a";

V5 :
E ;

V5 :=
I;

for Object_Dir use
P ;

V5 := (
E );

V5 := V5 &
I ;

V5 := ("",
P );

V5 := project'
N ;

V5 := Extended.
E ;

end Prj;
Loading

0 comments on commit 01071eb

Please sign in to comment.