Skip to content

Commit

Permalink
Merge branch 'laltools_issue_163' into 'edge'
Browse files Browse the repository at this point in the history
Replace Boolean imprecise by Ref_Result_Kind

See merge request eng/ide/ada_language_server!1528
  • Loading branch information
joaopsazevedo committed Apr 3, 2024
2 parents 98c4407 + fae9c29 commit baf0cfa
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test-vscode-extension:

# Run VSCode extension tests
- echo -e "\e[0Ksection_start:`date +%s`:test_vscode[collapsed=true]\r\e[0Kanod test vscode-extension"
- anod test vscode-extension --qualifier=$ACI_TRACK_QUALIFIER --minimal
- anod test vscode-extension $ACI_TRACK_QUALIFIER --minimal

- VSCODE_BUILD_SPACE=$(anod info test vscode-extension $ACI_TRACK_QUALIFIER --show working_dir)
- echo -e "\e[0Ksection_end:`date +%s`:test_vscode\r\e[0K"
Expand Down
22 changes: 11 additions & 11 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-2022, AdaCore --
-- Copyright (C) 2018-2024, 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 @@ -80,7 +80,7 @@ package body LSP.Ada_Contexts is
procedure Find_All_References_In_Hierarchy
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise : in out Boolean;
Imprecise : in out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Expand Down Expand Up @@ -210,13 +210,13 @@ package body LSP.Ada_Contexts is
function Find_All_Overrides
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Boolean)
Imprecise_Results : 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 := False;
Imprecise_Results := Libadalang.Common.Precise;

if Decl.Is_Null then
return (1 .. 0 => <>);
Expand All @@ -228,7 +228,7 @@ package body LSP.Ada_Contexts is
return Decl.P_Find_All_Overrides (Units);
exception
when E : Libadalang.Common.Property_Error =>
Imprecise_Results := True;
Imprecise_Results := Libadalang.Common.Imprecise;
Self.Tracer.Trace_Exception (E, "in Find_All_Overrides (precise)");
return Decl.P_Find_All_Overrides
(Units, Imprecise_Fallback => True);
Expand All @@ -246,7 +246,7 @@ package body LSP.Ada_Contexts is
function Find_All_Base_Declarations
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Boolean)
Imprecise_Results : out Libadalang.Common.Ref_Result_Kind)
return Libadalang.Analysis.Basic_Decl_Array
is
use Libadalang.Analysis;
Expand All @@ -259,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
Imprecise_Results := False;
Imprecise_Results := Libadalang.Common.Precise;

if Decl.Is_Null then
return (1 .. 0 => <>);
Expand Down Expand Up @@ -293,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");
Imprecise_Results := True;
Imprecise_Results := Libadalang.Common.Imprecise;
return (1 .. 0 => <>);
end Find_All_Base_Declarations;

Expand All @@ -304,7 +304,7 @@ package body LSP.Ada_Contexts is
procedure Find_All_References_In_Hierarchy
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise : in out Boolean;
Imprecise : in out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Expand Down Expand Up @@ -369,7 +369,7 @@ package body LSP.Ada_Contexts is
procedure Get_References_For_Renaming
(Self : Context;
Definition : Libadalang.Analysis.Defining_Name;
Imprecise_Results : out Boolean;
Imprecise_Results : out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Expand All @@ -381,7 +381,7 @@ package body LSP.Ada_Contexts is

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

if Decl.Is_Null then
return;
Expand Down
8 changes: 4 additions & 4 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-2019, AdaCore --
-- Copyright (C) 2018-2014, 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 @@ -100,7 +100,7 @@ package LSP.Ada_Contexts is
function Find_All_Overrides
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Boolean)
Imprecise_Results : 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
Expand All @@ -112,7 +112,7 @@ package LSP.Ada_Contexts is
function Find_All_Base_Declarations
(Self : Context;
Decl : Libadalang.Analysis.Basic_Decl;
Imprecise_Results : out Boolean)
Imprecise_Results : 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.
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 Boolean;
Imprecise_Results : out Libadalang.Common.Ref_Result_Kind;
Callback : not null access procedure
(Base_Id : Libadalang.Analysis.Base_Id;
Kind : Libadalang.Common.Ref_Result_Kind;
Expand Down
7 changes: 4 additions & 3 deletions source/ada/lsp-ada_definition.adb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ package body LSP.Ada_Definition is
Decl_For_Find_Overrides : Libadalang.Analysis.Basic_Decl;
Entry_Decl_Node : Libadalang.Analysis.Entry_Decl;

Ignore : Boolean;
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 @@ -241,12 +242,12 @@ package body LSP.Ada_Definition is
Overridings : constant Libadalang.Analysis.Basic_Decl_Array :=
Context.Find_All_Overrides
(Decl_For_Find_Overrides,
Imprecise_Results => Ignore);
Imprecise_Results => Imprecise_Ignore);

Bases : constant Libadalang.Analysis.Basic_Decl_Array :=
Context.Find_All_Base_Declarations
(Decl_For_Find_Overrides,
Imprecise_Results => Ignore);
Imprecise_Results => Imprecise_Ignore);
begin
for Subp of Bases loop
Self.Parent.Context.Append_Location
Expand Down
7 changes: 4 additions & 3 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-2023, AdaCore --
-- Copyright (C) 2018-2024, 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,15 +313,16 @@ package body LSP.Ada_Handlers.Call_Hierarchy is
end if;
end Callback;

Imprecise : Boolean := False;
Imprecise_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);
Imprecise => Imprecise_Ignore);

Cursor := Result.First;
-- Iterate through all the results, converting them to protocol
Expand Down
57 changes: 32 additions & 25 deletions source/ada/lsp-ada_handlers.adb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- Language Server Protocol --
-- --
-- Copyright (C) 2018-2023, AdaCore --
-- Copyright (C) 2018-2024, 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 @@ -140,7 +140,7 @@ package body LSP.Ada_Handlers is
Id : LSP.Structures.Integer_Or_Virtual_String;
Context : LSP.Ada_Contexts.Context;
Name_Node : Libadalang.Analysis.Name;
Imprecise : out Boolean)
Imprecise : out Libadalang.Common.Ref_Result_Kind)
return Libadalang.Analysis.Defining_Name;
-- Toplayer Resolve_Name based on Laltools.Common.Resolve_Name.
-- This function is handling Imprecise and Error results during Nameres by
Expand Down Expand Up @@ -1737,7 +1737,8 @@ package body LSP.Ada_Handlers is
On_Defining_Name : Boolean := False;
-- Set to True if we are on a denfining name node

Imprecise : Boolean;
Imprecise_Ignore : Libadalang.Common.Ref_Result_Kind;

begin
if Name_Node.Is_Null then
return;
Expand All @@ -1754,7 +1755,7 @@ package body LSP.Ada_Handlers is
Id => Id,
Context => C.all,
Name_Node => Name_Node,
Imprecise => Imprecise);
Imprecise => Imprecise_Ignore);
else
On_Defining_Name := True;
end if;
Expand Down Expand Up @@ -1806,16 +1807,15 @@ package body LSP.Ada_Handlers is

if not Decl_For_Find_Overrides.Is_Null then
declare
Is_Imprecise : Boolean;
Overridings : constant Libadalang.Analysis.Basic_Decl_Array :=
C.Find_All_Overrides
(Decl_For_Find_Overrides,
Imprecise_Results => Is_Imprecise);
Imprecise_Results => Imprecise_Ignore);

Bases : constant Libadalang.Analysis.Basic_Decl_Array :=
C.Find_All_Base_Declarations
(Decl_For_Find_Overrides,
Imprecise_Results => Is_Imprecise);
Imprecise_Results => Imprecise_Ignore);
begin
for Subp of Bases loop
Self.Append_Location
Expand Down Expand Up @@ -2742,9 +2742,11 @@ package body LSP.Ada_Handlers is
end Update_Response;

Definition : Libadalang.Analysis.Defining_Name;
Imprecise : Boolean := False;
Decl : Libadalang.Analysis.Basic_Decl;

Imprecise_Ignore : Libadalang.Common.Ref_Result_Kind :=
Libadalang.Common.No_Ref;

begin
if Name_Node.Is_Null then
return;
Expand All @@ -2755,7 +2757,7 @@ package body LSP.Ada_Handlers is
Id => Id,
Context => C.all,
Name_Node => Name_Node,
Imprecise => Imprecise);
Imprecise => Imprecise_Ignore);

-- If we didn't find a definition, give up for this context
if Definition.Is_Null then
Expand All @@ -2764,7 +2766,8 @@ package body LSP.Ada_Handlers is

-- First list the bodies of this definition
Update_Response
(Laltools.Common.List_Bodies_Of (Definition, Trace, Imprecise),
(Laltools.Common.List_Bodies_Of
(Definition, Trace, Imprecise_Ignore),
LSP.Constants.Empty);

-- Then list the bodies of the parent implementations
Expand All @@ -2777,19 +2780,19 @@ package body LSP.Ada_Handlers is
(Display_Method_Policy = Usage_And_Abstract_Only
and then Decl.Kind in Ada_Abstract_Subp_Decl_Range)
then
for Subp of C.Find_All_Base_Declarations (Decl, Imprecise)
for Subp of C.Find_All_Base_Declarations (Decl, Imprecise_Ignore)
loop
Update_Response
(Laltools.Common.List_Bodies_Of
(Subp.P_Defining_Name, Trace, Imprecise),
(Subp.P_Defining_Name, Trace, Imprecise_Ignore),
Is_Parent);
end loop;

-- And finally the bodies of child implementations
for Subp of C.Find_All_Overrides (Decl, Imprecise) loop
for Subp of C.Find_All_Overrides (Decl, Imprecise_Ignore) loop
Update_Response
(Laltools.Common.List_Bodies_Of
(Subp.P_Defining_Name, Trace, Imprecise),
(Subp.P_Defining_Name, Trace, Imprecise_Ignore),
Is_Child);
end loop;
end if;
Expand Down Expand Up @@ -3310,7 +3313,11 @@ package body LSP.Ada_Handlers is

Defining_Name : Libadalang.Analysis.Defining_Name;

Imprecise : Boolean := False;
Imprecise : Libadalang.Common.Ref_Result_Kind :=
Libadalang.Common.No_Ref;

use type Libadalang.Common.Ref_Result_Kind;

begin
if not Name_Node.Is_Null then
Defining_Name := Resolve_Name
Expand All @@ -3323,7 +3330,7 @@ package body LSP.Ada_Handlers is

if not Name_Node.Is_Null
and then not Defining_Name.Is_Null
and then not Imprecise
and then Imprecise in Libadalang.Common.Precise
then
-- Success only if the node is a name and can be resolved precisely
Response :=
Expand Down Expand Up @@ -3923,7 +3930,9 @@ package body LSP.Ada_Handlers is
Response : LSP.Structures.Definition_Result (LSP.Structures.Variant_1);
Vector : LSP.Structures.Location_Vector renames Response.Variant_1;
Filter : LSP.Locations.File_Span_Sets.Set;
Imprecise : Boolean := False;

Imprecise_Ignore : Libadalang.Common.Ref_Result_Kind :=
Libadalang.Common.No_Ref;

procedure Resolve_In_Context (C : LSP.Ada_Context_Sets.Context_Access);
-- Utility function to gather results on one context
Expand Down Expand Up @@ -3960,7 +3969,7 @@ package body LSP.Ada_Handlers is
Id => Id,
Context => C.all,
Name_Node => Type_Expr.P_Type_Name,
Imprecise => Imprecise);
Imprecise => Imprecise_Ignore);
end if;
end;
else
Expand Down Expand Up @@ -4064,19 +4073,18 @@ package body LSP.Ada_Handlers is
Id : LSP.Structures.Integer_Or_Virtual_String;
Context : LSP.Ada_Contexts.Context;
Name_Node : Libadalang.Analysis.Name;
Imprecise : out Boolean)
Imprecise : out Libadalang.Common.Ref_Result_Kind)
return Libadalang.Analysis.Defining_Name
is
Definition : Libadalang.Analysis.Defining_Name;
Result_Kind : Libadalang.Common.Ref_Result_Kind;
Trace : constant GNATCOLL.Traces.Trace_Handle :=
LSP.GNATCOLL_Tracers.Handle (Self.Tracer.all);
Id_Image : constant String :=
(if Id.Is_Integer
then Id.Integer'Image
else VSS.Strings.Conversions.To_UTF_8_String (Id.Virtual_String));
begin
Imprecise := False;
Imprecise := Libadalang.Common.No_Ref;

if Name_Node.Is_Null then
-- Internal tracing of resolve on null node
Expand All @@ -4086,9 +4094,9 @@ package body LSP.Ada_Handlers is

-- Find the definition
Definition := Laltools.Common.Resolve_Name
(Name_Node, Trace, Result_Kind);
(Name_Node, Trace, Imprecise);

if Result_Kind in Libadalang.Common.Error then
if Imprecise in Libadalang.Common.Error then
declare
Err_Msg : constant String :=
"Failed to resolve " & Name_Node.Image;
Expand Down Expand Up @@ -4138,7 +4146,7 @@ package body LSP.Ada_Handlers is
return Libadalang.Analysis.No_Defining_Name;
end;

elsif Result_Kind in Libadalang.Common.Imprecise then
elsif Imprecise in Libadalang.Common.Imprecise then
-- Internal tracing of imprecise resolving
Self.Tracer.Trace
("Imprecise result when resolving "
Expand All @@ -4147,7 +4155,6 @@ package body LSP.Ada_Handlers is
& VSS.Strings.Conversions.To_UTF_8_String (Context.Id)
& " for request "
& Id_Image);
Imprecise := True;
end if;

return Definition;
Expand Down
Loading

0 comments on commit baf0cfa

Please sign in to comment.