Skip to content

Commit

Permalink
Merge branch 'topic/bump_merge_conflict' into 'edge'
Browse files Browse the repository at this point in the history
Improve handling of Error during Resolve_Name

See merge request eng/ide/ada_language_server!1542
  • Loading branch information
AdrienBoulanger committed Apr 17, 2024
2 parents 01071eb + 558bc83 commit a1f91ec
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 119 deletions.
82 changes: 48 additions & 34 deletions source/ada/lsp-ada_contexts.adb
Original file line number Diff line number Diff line change
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;
Imprecise : in out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : in out Libadalang.Common.Ref_Result_Kind;
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;
Imprecise_Results : out Libadalang.Common.Ref_Result_Kind)
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : out Libadalang.Common.Ref_Result_Kind)
return Libadalang.Analysis.Basic_Decl_Array
is
Units : constant Libadalang.Analysis.Analysis_Unit_Array :=
Self.Analysis_Units;
begin
Imprecise_Results := Libadalang.Common.Precise;
Result_Kind := Libadalang.Common.Precise;

if Decl.Is_Null then
return (1 .. 0 => <>);
Expand All @@ -228,13 +228,14 @@ package body LSP.Ada_Contexts is
return Decl.P_Find_All_Overrides (Units);
exception
when E : Libadalang.Common.Property_Error =>
Imprecise_Results := Libadalang.Common.Imprecise;
Result_Kind := Libadalang.Common.Imprecise;
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 @@ -244,9 +245,9 @@ package body LSP.Ada_Contexts is
--------------------------------

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

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

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

procedure Find_All_References_In_Hierarchy
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise : in out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : in out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Cancel : in out Boolean))
Expand All @@ -323,31 +324,44 @@ 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,
Imprecise_Results => Imprecise);
Result_Kind => Overriding_Result_Kind);

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

Hierarchy : constant Libadalang.Analysis.Basic_Decl_Array :=
Overriding_Decls & Base_Decls;
Result_Kind => Bases_Result_Kind);
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);
if Overriding_Result_Kind in Libadalang.Common.Error
or else Bases_Result_Kind in Libadalang.Common.Error
then
Result_Kind := Libadalang.Common.Error;
return;
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 Down
20 changes: 10 additions & 10 deletions source/ada/lsp-ada_contexts.ads
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ package LSP.Ada_Contexts is
-- context.

function Find_All_Overrides
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Libadalang.Common.Ref_Result_Kind)
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Result_Kind : out Libadalang.Common.Ref_Result_Kind)
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.
-- Imprecise_Results is set to True if we don't know whether the results
-- are precise.
-- Result_Kind indicates if LAL encountered an Error or if the result are
-- Imprecise.
-- Returns an empty array if Decl is null.

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

procedure Find_All_Calls
Expand Down
21 changes: 16 additions & 5 deletions source/ada/lsp-ada_declaration.adb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ package body LSP.Ada_Declaration is
On_Defining_Name : Boolean := False;
-- Set to True if we are on a denfining name node

Ignore : Libadalang.Common.Ref_Result_Kind;
Imprecise_Ignore : Boolean;
Result_Kind : 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 @@ -172,12 +173,13 @@ 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, Ignore);
Definition := Laltools.Common.Resolve_Name
(Name_Node, Trace, Result_Kind);
else
On_Defining_Name := True;
end if;

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

Expand Down Expand Up @@ -228,16 +230,25 @@ 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,
Imprecise_Results => Ignore);
Result_Kind => Overriding_Result_Kind);

Bases : constant Libadalang.Analysis.Basic_Decl_Array :=
Context.Find_All_Base_Declarations
(Decl_For_Find_Overrides,
Imprecise_Results => Ignore);
Result_Kind => Bases_Result_Kind);
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
16 changes: 11 additions & 5 deletions source/ada/lsp-ada_definition.adb
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ 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;

Imprecise_Ignore : 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 @@ -239,16 +236,25 @@ 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,
Imprecise_Results => Imprecise_Ignore);
Result_Kind => Overriding_Result_Kind);

Bases : constant Libadalang.Analysis.Basic_Decl_Array :=
Context.Find_All_Base_Declarations
(Decl_For_Find_Overrides,
Imprecise_Results => Imprecise_Ignore);
Result_Kind => Bases_Result_Kind);
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
Loading

0 comments on commit a1f91ec

Please sign in to comment.