Skip to content

Commit 2c0f858

Browse files
VB24-035: Add LAL Event_Handler to log unfound units
1 parent 05f7812 commit 2c0f858

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

source/ada/lsp-ada_contexts.adb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ with Langkit_Support.Slocs;
3838
with Utils.Command_Lines.Common;
3939

4040
with Pp.Actions;
41+
with Langkit_Support.Text;
4142

4243
package body LSP.Ada_Contexts is
4344

@@ -47,6 +48,31 @@ package body LSP.Ada_Contexts is
4748

4849
use type Libadalang.Analysis.Analysis_Unit;
4950

51+
type LSP_Context_Event_Handler_Type
52+
is new Libadalang.Analysis.Event_Handler_Interface with record
53+
Trace : Trace_Handle;
54+
end record;
55+
-- LAL event handler used to log units that have notbeen found when
56+
-- requested.
57+
58+
overriding procedure Unit_Requested_Callback
59+
(Self : in out LSP_Context_Event_Handler_Type;
60+
Context : Libadalang.Analysis.Analysis_Context'Class;
61+
Name : Langkit_Support.Text.Text_Type;
62+
From : Libadalang.Analysis.Analysis_Unit'Class;
63+
Found : Boolean;
64+
Is_Not_Found_Error : Boolean);
65+
66+
overriding procedure Unit_Parsed_Callback
67+
(Self : in out LSP_Context_Event_Handler_Type;
68+
Context : Libadalang.Analysis.Analysis_Context'Class;
69+
Unit : Libadalang.Analysis.Analysis_Unit'Class;
70+
Reparsed : Boolean)
71+
is null;
72+
73+
overriding procedure Release (Self : in out LSP_Context_Event_Handler_Type)
74+
is null;
75+
5076
function Get_Charset (Self : Context'Class) return String;
5177
-- Return the charset with which the context was initialized
5278

@@ -83,6 +109,25 @@ package body LSP.Ada_Contexts is
83109
-- Options that are explicitly specified in the .gpr file take precedence
84110
-- over LSP options.
85111

112+
-----------------------------
113+
-- Unit_Requested_Callback --
114+
-----------------------------
115+
116+
overriding procedure Unit_Requested_Callback
117+
(Self : in out LSP_Context_Event_Handler_Type;
118+
Context : Libadalang.Analysis.Analysis_Context'Class;
119+
Name : Langkit_Support.Text.Text_Type;
120+
From : Libadalang.Analysis.Analysis_Unit'Class;
121+
Found : Boolean;
122+
Is_Not_Found_Error : Boolean) is
123+
begin
124+
if not Found then
125+
Self.Trace.Trace
126+
("Failed to request the following unit: "
127+
& Langkit_Support.Text.To_UTF8 (Name));
128+
end if;
129+
end Unit_Requested_Callback;
130+
86131
-------------------------
87132
-- Append_Declarations --
88133
-------------------------
@@ -757,6 +802,9 @@ package body LSP.Ada_Contexts is
757802
Env => Get_Environment (Root),
758803
Is_Project_Owner => False);
759804

805+
Self.Event_Handler := Libadalang.Analysis.Create_Event_Handler_Reference
806+
(LSP_Context_Event_Handler_Type'(Trace => Self.Trace));
807+
760808
Self.Reload;
761809
Update_Source_Files;
762810
Pretty_Printer_Setup;

source/ada/lsp-ada_contexts.ads

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ private
321321
type Context (Trace : GNATCOLL.Traces.Trace_Handle) is tagged limited record
322322
Id : VSS.Strings.Virtual_String;
323323
Unit_Provider : Libadalang.Analysis.Unit_Provider_Reference;
324+
Event_Handler : Libadalang.Analysis.Event_Handler_Reference;
324325
LAL_Context : Libadalang.Analysis.Analysis_Context;
325326
Charset : Ada.Strings.Unbounded.Unbounded_String;
326327

0 commit comments

Comments
 (0)