Skip to content

Commit

Permalink
Merge branch 'topic/revert_edge_on_master' into 'edge'
Browse files Browse the repository at this point in the history
Revert edge on master

See merge request eng/ide/ada_language_server!1553
  • Loading branch information
AnthonyLeonardoGracio committed Apr 25, 2024
2 parents 4c50e83 + be6d142 commit 349c921
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 167 deletions.
88 changes: 37 additions & 51 deletions source/ada/lsp-ada_contexts.adb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- Language Server Protocol --
-- --
-- Copyright (C) 2018-2024, AdaCore --
-- Copyright (C) 2018-2022, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -78,10 +78,10 @@ package body LSP.Ada_Contexts is
-- Return the charset with which the context was initialized

procedure Find_All_References_In_Hierarchy
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : in out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise : in out Boolean;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Cancel : in out Boolean));
Expand Down Expand Up @@ -208,15 +208,15 @@ package body LSP.Ada_Contexts is
------------------------

function Find_All_Overrides
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : out Libadalang.Common.Ref_Result_Kind)
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Boolean)
return Libadalang.Analysis.Basic_Decl_Array
is
Units : constant Libadalang.Analysis.Analysis_Unit_Array :=
Self.Analysis_Units;
begin
Result_Kind := Libadalang.Common.Precise;
Imprecise_Results := False;

if Decl.Is_Null then
return (1 .. 0 => <>);
Expand All @@ -228,14 +228,13 @@ package body LSP.Ada_Contexts is
return Decl.P_Find_All_Overrides (Units);
exception
when E : Libadalang.Common.Property_Error =>
Result_Kind := Libadalang.Common.Imprecise;
Imprecise_Results := True;
Self.Tracer.Trace_Exception (E, "in Find_All_Overrides (precise)");
return Decl.P_Find_All_Overrides
(Units, Imprecise_Fallback => True);
end;
exception
when E : Libadalang.Common.Property_Error =>
Result_Kind := Libadalang.Common.Error;
Self.Tracer.Trace_Exception (E, "in Find_All_Overrides (imprecise)");
return (1 .. 0 => <>);
end Find_All_Overrides;
Expand All @@ -245,9 +244,9 @@ package body LSP.Ada_Contexts is
--------------------------------

function Find_All_Base_Declarations
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : out Libadalang.Common.Ref_Result_Kind)
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Boolean)
return Libadalang.Analysis.Basic_Decl_Array
is
use Libadalang.Analysis;
Expand All @@ -260,7 +259,7 @@ package body LSP.Ada_Contexts is
Langkit_Support.Slocs.Start_Sloc (Left.Sloc_Range) =
Langkit_Support.Slocs.Start_Sloc (Right.Sloc_Range));
begin
Result_Kind := Libadalang.Common.Precise;
Imprecise_Results := False;

if Decl.Is_Null then
return (1 .. 0 => <>);
Expand Down Expand Up @@ -294,7 +293,7 @@ package body LSP.Ada_Contexts is
exception
when E : Libadalang.Common.Property_Error =>
Self.Tracer.Trace_Exception (E, "in Find_All_Base_Declarations");
Result_Kind := Libadalang.Common.Error;
Imprecise_Results := True;
return (1 .. 0 => <>);
end Find_All_Base_Declarations;

Expand All @@ -303,10 +302,10 @@ package body LSP.Ada_Contexts is
--------------------------------------

procedure Find_All_References_In_Hierarchy
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : in out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise : in out Boolean;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Cancel : in out Boolean))
Expand All @@ -324,44 +323,31 @@ package body LSP.Ada_Contexts is
else
Decl);

Overriding_Result_Kind : Libadalang.Common.Ref_Result_Kind;
Bases_Result_Kind : Libadalang.Common.Ref_Result_Kind;

Overriding_Decls : constant Libadalang.Analysis.Basic_Decl_Array :=
Self.Find_All_Overrides
(Subp_Decl,
Result_Kind => Overriding_Result_Kind);
Imprecise_Results => Imprecise);

Base_Decls : constant Libadalang.Analysis.Basic_Decl_Array :=
Self.Find_All_Base_Declarations
(Subp_Decl,
Result_Kind => Bases_Result_Kind);
Imprecise_Results => Imprecise);

Hierarchy : constant Libadalang.Analysis.Basic_Decl_Array :=
Overriding_Decls & Base_Decls;
begin
if Overriding_Result_Kind in Libadalang.Common.Error
or else Bases_Result_Kind in Libadalang.Common.Error
then
Result_Kind := Libadalang.Common.Error;
return;
if Is_Param then
LSP.Ada_Id_Iterators.Find_All_Param_References_In_Hierarchy
(Param => Decl.As_Param_Spec,
Hierarchy => Hierarchy,
Units => Self.Analysis_Units,
Callback => Callback);
else
LSP.Ada_Id_Iterators.Find_All_Subp_References_In_Hierarchy
(Hierarchy => Hierarchy,
Tracer => Self.Tracer.all,
Callback => Callback);
end if;

declare
Hierarchy : constant Libadalang.Analysis.Basic_Decl_Array :=
Overriding_Decls & Base_Decls;
begin

if Is_Param then
LSP.Ada_Id_Iterators.Find_All_Param_References_In_Hierarchy
(Param => Decl.As_Param_Spec,
Hierarchy => Hierarchy,
Units => Self.Analysis_Units,
Callback => Callback);
else
LSP.Ada_Id_Iterators.Find_All_Subp_References_In_Hierarchy
(Hierarchy => Hierarchy,
Tracer => Self.Tracer.all,
Callback => Callback);
end if;
end;
end Find_All_References_In_Hierarchy;

--------------------
Expand All @@ -383,7 +369,7 @@ package body LSP.Ada_Contexts is
procedure Get_References_For_Renaming
(Self : Context;
Definition : Libadalang.Analysis.Defining_Name;
Imprecise_Results : out Libadalang.Common.Ref_Result_Kind;
Imprecise_Results : out Boolean;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Expand All @@ -395,7 +381,7 @@ package body LSP.Ada_Contexts is

begin
-- Make sure to initialize the "out" variable Imprecise_Results
Imprecise_Results := Libadalang.Common.Precise;
Imprecise_Results := False;

if Decl.Is_Null then
return;
Expand Down
24 changes: 12 additions & 12 deletions source/ada/lsp-ada_contexts.ads
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- Language Server Protocol --
-- --
-- Copyright (C) 2018-2014, AdaCore --
-- Copyright (C) 2018-2019, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -98,26 +98,26 @@ package LSP.Ada_Contexts is
-- context.

function Find_All_Overrides
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : out Libadalang.Common.Ref_Result_Kind)
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Boolean)
return Libadalang.Analysis.Basic_Decl_Array;
-- Finds all overriding subprograms of the given basic declaration.
-- This is used to propose all the implementations of a given subprogram
-- when textDocument/definition requests happen on dispatching calls.
-- Result_Kind indicates if LAL encountered an Error or if the result are
-- Imprecise.
-- Imprecise_Results is set to True if we don't know whether the results
-- are precise.
-- Returns an empty array if Decl is null.

function Find_All_Base_Declarations
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : out Libadalang.Common.Ref_Result_Kind)
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Boolean)
return Libadalang.Analysis.Basic_Decl_Array;
-- Given a subprogram declaration in Decl, find all the base subprograms
-- that it inherits, not including self.
-- Result_Kind indicates if LAL encountered an Error or if the result are
-- Imprecise.
-- Imprecise_Results is set to True if we don't know whether the results
-- are precise.
-- Returns an empty array if Decl is null.

procedure Find_All_Calls
Expand Down Expand Up @@ -145,7 +145,7 @@ package LSP.Ada_Contexts is
procedure Get_References_For_Renaming
(Self : Context;
Definition : Libadalang.Analysis.Defining_Name;
Imprecise_Results : out Libadalang.Common.Ref_Result_Kind;
Imprecise_Results : out Boolean;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Expand Down
22 changes: 6 additions & 16 deletions source/ada/lsp-ada_declaration.adb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ package body LSP.Ada_Declaration is
On_Defining_Name : Boolean := False;
-- Set to True if we are on a denfining name node

Imprecise_Ignore : Boolean;
Result_Kind : Libadalang.Common.Ref_Result_Kind;
Ignore : Boolean;
Dummy : Libadalang.Common.Ref_Result_Kind;
begin
if Self.Contexts.Is_Empty then
-- No more contexts to process, sort and return collected results
Expand Down Expand Up @@ -173,13 +173,12 @@ package body LSP.Ada_Declaration is

if Definition.Is_Null then
-- If we aren't on a defining_name already then try to resolve
Definition := Laltools.Common.Resolve_Name
(Name_Node, Trace, Result_Kind);
Definition := Laltools.Common.Resolve_Name (Name_Node, Trace, Dummy);
else
On_Defining_Name := True;
end if;

if Result_Kind in Libadalang.Common.Error or else Definition.Is_Null then
if Definition.Is_Null then
return; -- Name resolution fails, nothing to do.
end if;

Expand Down Expand Up @@ -230,25 +229,16 @@ package body LSP.Ada_Declaration is

if not Decl_For_Find_Overrides.Is_Null then
declare
Overriding_Result_Kind : Libadalang.Common.Ref_Result_Kind;
Bases_Result_Kind : Libadalang.Common.Ref_Result_Kind;
Overridings : constant Libadalang.Analysis.Basic_Decl_Array :=
Context.Find_All_Overrides
(Decl_For_Find_Overrides,
Result_Kind => Overriding_Result_Kind);
Imprecise_Results => Ignore);

Bases : constant Libadalang.Analysis.Basic_Decl_Array :=
Context.Find_All_Base_Declarations
(Decl_For_Find_Overrides,
Result_Kind => Bases_Result_Kind);
Imprecise_Results => Ignore);
begin
if Overriding_Result_Kind in Libadalang.Common.Error
or else Bases_Result_Kind in Libadalang.Common.Error
then
-- Abort
return;
end if;

for Subp of Bases loop
Self.Parent.Context.Append_Location
(Self.Response,
Expand Down
15 changes: 4 additions & 11 deletions source/ada/lsp-ada_definition.adb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ package body LSP.Ada_Definition is
Definition_Node : Libadalang.Analysis.Basic_Decl;
Decl_For_Find_Overrides : Libadalang.Analysis.Basic_Decl;
Entry_Decl_Node : Libadalang.Analysis.Entry_Decl;

Ignore : Boolean;
begin
if Self.Contexts.Is_Empty then
-- No more contexts to process, sort and return collected results
Expand Down Expand Up @@ -236,25 +238,16 @@ package body LSP.Ada_Definition is

if not Decl_For_Find_Overrides.Is_Null then
declare
Overriding_Result_Kind : Libadalang.Common.Ref_Result_Kind;
Bases_Result_Kind : Libadalang.Common.Ref_Result_Kind;
Overridings : constant Libadalang.Analysis.Basic_Decl_Array :=
Context.Find_All_Overrides
(Decl_For_Find_Overrides,
Result_Kind => Overriding_Result_Kind);
Imprecise_Results => Ignore);

Bases : constant Libadalang.Analysis.Basic_Decl_Array :=
Context.Find_All_Base_Declarations
(Decl_For_Find_Overrides,
Result_Kind => Bases_Result_Kind);
Imprecise_Results => Ignore);
begin
if Overriding_Result_Kind in Libadalang.Common.Error
or else Bases_Result_Kind in Libadalang.Common.Error
then
-- Abort
return;
end if;

for Subp of Bases loop
Self.Parent.Context.Append_Location
(Self.Response,
Expand Down
8 changes: 4 additions & 4 deletions source/ada/lsp-ada_handlers-call_hierarchy.adb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- Language Server Protocol --
-- --
-- Copyright (C) 2018-2024, AdaCore --
-- Copyright (C) 2018-2023, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -313,16 +313,16 @@ package body LSP.Ada_Handlers.Call_Hierarchy is
end if;
end Callback;

Imprecise_Ignore : Libadalang.Common.Ref_Result_Kind :=
Cursor : Laltools.Common.References_By_Subprogram.Cursor;
Ignore : Libadalang.Common.Ref_Result_Kind :=
Libadalang.Common.No_Ref;
Cursor : Laltools.Common.References_By_Subprogram.Cursor;

begin
Laltools.Call_Hierarchy.Find_Outgoing_Calls
(Definition => Definition,
Callback => Callback'Access,
Trace => Trace,
Imprecise => Imprecise_Ignore);
Imprecise => Ignore);

Cursor := Result.First;
-- Iterate through all the results, converting them to protocol
Expand Down
Loading

0 comments on commit 349c921

Please sign in to comment.