Skip to content

Commit bd6866d

Browse files
Merge branch 'topic/#1524' into 'master'
Workspace-specific diagnostics for project issues See merge request eng/ide/ada_language_server!1845
2 parents 6717d13 + 4bdac9e commit bd6866d

File tree

44 files changed

+319
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+319
-297
lines changed

source/ada/lsp-ada_context_sets.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ with LSP.Ada_File_Sets;
2323

2424
package body LSP.Ada_Context_Sets is
2525

26-
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
27-
(LSP.Ada_Contexts.Context, Context_Access);
26+
procedure Unchecked_Free is new
27+
Ada.Unchecked_Deallocation (LSP.Ada_Contexts.Context, Context_Access);
2828

2929
-------------
3030
-- Cleanup --

source/ada/lsp-ada_context_sets.ads

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,17 @@ package LSP.Ada_Context_Sets is
3434

3535
type Context_Access is access LSP.Ada_Contexts.Context;
3636

37-
package Context_Lists is new Ada.Containers.Doubly_Linked_Lists
38-
(Context_Access);
37+
package Context_Lists is new
38+
Ada.Containers.Doubly_Linked_Lists (Context_Access);
3939

4040
function Is_Empty (Self : Context_Set'Class) return Boolean;
4141
-- Check if the set has no contexts
4242

43-
procedure Prepend
44-
(Self : in out Context_Set'Class;
45-
Item : Context_Access);
43+
procedure Prepend (Self : in out Context_Set'Class; Item : Context_Access);
4644
-- Append an item to the set
4745

4846
procedure Reload_All_Contexts (Self : in out Context_Set'Class);
49-
-- Reload ech context in the set
47+
-- Reload each context in the set
5048

5149
function Get_Best_Context
5250
(Self : Context_Set'Class;
@@ -97,9 +95,12 @@ private
9795
"=" => "=");
9896

9997
type Context_Set is tagged limited record
100-
Contexts : Context_Lists.List;
101-
Map : Maps.Map; -- A map from Context.Id to Context access
102-
Total : Natural := 0;
98+
Contexts : Context_Lists.List;
99+
100+
Map : Maps.Map;
101+
-- A map from Context.Id to Context access
102+
103+
Total : Natural := 0;
103104
end record;
104105

105106
end LSP.Ada_Context_Sets;

source/ada/lsp-ada_contexts.ads

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ package LSP.Ada_Contexts is
8585
-- context after calling this.
8686

8787
function URI_To_File
88-
(Self : Context;
89-
URI : LSP.Structures.DocumentUri)
88+
(Self : Context; URI : LSP.Structures.DocumentUri)
9089
return GNATCOLL.VFS.Virtual_File;
9190

9291
procedure Find_All_References

source/ada/lsp-ada_documents.adb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,18 +1132,16 @@ package body LSP.Ada_Documents is
11321132
----------------
11331133

11341134
procedure Initialize
1135-
(Self : in out Document;
1136-
URI : LSP.Structures.DocumentUri;
1137-
Text : VSS.Strings.Virtual_String;
1138-
Diagnostic : LSP.Diagnostic_Sources.Diagnostic_Source_Access) is
1135+
(Self : in out Document;
1136+
URI : LSP.Structures.DocumentUri;
1137+
Text : VSS.Strings.Virtual_String) is
11391138
begin
11401139
LSP.Text_Documents.Constructors.Initialize (Self, URI, Text);
11411140

1142-
Self.Refresh_Symbol_Cache := True;
1143-
Self.Diagnostic_Sources (1) := new
1144-
LSP.Ada_Documents.LAL_Diagnostics.Diagnostic_Source
1145-
(Self'Unchecked_Access);
1146-
Self.Diagnostic_Sources (2) := Diagnostic;
1141+
Self.Refresh_Symbol_Cache := True;
1142+
Self.Diagnostic_Sources.Append
1143+
(new LSP.Ada_Documents.LAL_Diagnostics.Diagnostic_Source
1144+
(Self'Unchecked_Access));
11471145
end Initialize;
11481146

11491147
----------------------

source/ada/lsp-ada_documents.ads

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ limited with LSP.Ada_Contexts;
3333
limited with LSP.Ada_Handlers;
3434
with LSP.Ada_Completions;
3535
with LSP.Constants;
36-
with LSP.Diagnostic_Sources;
36+
with LSP.Diagnostic_Sources; use LSP.Diagnostic_Sources;
3737
with LSP.Text_Documents.Langkit_Documents;
3838
with LSP.Search;
3939
with LSP.Structures;
@@ -52,12 +52,10 @@ package LSP.Ada_Documents is
5252
with Storage_Size => 0;
5353

5454
procedure Initialize
55-
(Self : in out Document;
56-
URI : LSP.Structures.DocumentUri;
57-
Text : VSS.Strings.Virtual_String;
58-
Diagnostic : LSP.Diagnostic_Sources.Diagnostic_Source_Access);
59-
-- Create a new document from a TextDocumentItem. Use Diagnostic as
60-
-- project status diagnostic source.
55+
(Self : in out Document;
56+
URI : LSP.Structures.DocumentUri;
57+
Text : VSS.Strings.Virtual_String);
58+
-- Create a new document from a TextDocumentItem.
6159

6260
procedure Cleanup (Self : in out Document);
6361
-- Free all the data associated to this document.
@@ -306,16 +304,13 @@ private
306304
"<" => VSS.Strings."<",
307305
"=" => Name_Vectors."=");
308306

309-
type Diagnostic_Source_Array is array (Natural range <>) of
310-
LSP.Diagnostic_Sources.Diagnostic_Source_Access;
311-
312307
type Document (Tracer : not null LSP.Tracers.Tracer_Access) is
313308
new LSP.Text_Documents.Langkit_Documents.Langkit_Text_Document with record
314309
Symbol_Cache : Symbol_Maps.Map;
315310
-- Cache of all defining name symbol of the document.
316311
Refresh_Symbol_Cache : Boolean := False;
317312
-- Symbol_Cache rebuild is required before.
318-
Diagnostic_Sources : Diagnostic_Source_Array (1 .. 2);
313+
Diagnostic_Sources : Diagnostic_Source_Vectors.Vector;
319314
-- Known sources of diagnostics
320315
end record;
321316

source/ada/lsp-ada_driver.adb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ begin
564564
Gnatformat.Configuration.Elaborate_GPR2;
565565

566566
declare
567-
Allow_Incremental_Text_Changes : constant GNATCOLL.Traces.Trace_Handle
568-
:= GNATCOLL.Traces.Create ("ALS.ALLOW_INCREMENTAL_TEXT_CHANGES",
569-
GNATCOLL.Traces.On);
567+
Allow_Incremental_Text_Changes : constant GNATCOLL.Traces.Trace_Handle :=
568+
GNATCOLL.Traces.Create
569+
("ALS.ALLOW_INCREMENTAL_TEXT_CHANGES", GNATCOLL.Traces.On);
570570
-- Trace to activate the support for incremental text changes.
571571

572572
CLI_Config_Path : constant VSS.Strings.Virtual_String :=
@@ -584,7 +584,7 @@ begin
584584
begin
585585
Ada_Handler.Initialize
586586
(Incremental_Text_Changes => Allow_Incremental_Text_Changes.Is_Active,
587-
CLI_Config_File => CLI_Config_File);
587+
CLI_Config_File => CLI_Config_File);
588588
end;
589589

590590
Server.Initialize (Stream'Unchecked_Access);

source/ada/lsp-ada_handlers-project_diagnostics.adb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
2424
-- repeat the information every time diagnostics are published for every
2525
-- file.
2626

27-
--------------------
28-
-- Get_Diagnostic --
29-
--------------------
27+
---------------------
28+
-- Get_Diagnostics --
29+
---------------------
3030

31-
overriding procedure Get_Diagnostic
32-
(Self : in out Diagnostic_Source;
33-
Context : LSP.Ada_Contexts.Context;
34-
Errors : out LSP.Structures.Diagnostic_Vector) is
31+
overriding
32+
procedure Get_Diagnostics
33+
(Self : in out Diagnostic_Source;
34+
Diagnostics : out LSP.Structures.Diagnostic_Vector) is
3535
begin
3636
if Self.Handler.Configuration.Project_Diagnostics_Enabled then
3737
Self.Last_Status := Self.Handler.Project_Status;
@@ -42,21 +42,18 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
4242
-- diagnostics only if there is an issue to solve or a potential
4343
-- enhancement.
4444

45-
Errors.Append_Vector
45+
Diagnostics.Append_Vector
4646
(LSP.Ada_Project_Loading.Get_Diagnostics (Self.Last_Status));
4747
end if;
48-
end Get_Diagnostic;
48+
end Get_Diagnostics;
4949

5050
------------------------
5151
-- Has_New_Diagnostic --
5252
------------------------
5353

5454
overriding function Has_New_Diagnostic
55-
(Self : in out Diagnostic_Source;
56-
Context : LSP.Ada_Contexts.Context)
57-
return Boolean
58-
is
59-
pragma Unreferenced (Context);
55+
(Self : in out Diagnostic_Source)
56+
return Boolean is
6057
begin
6158
if Self.Handler.Configuration.Project_Diagnostics_Enabled then
6259
return LSP.Ada_Project_Loading.Has_New_Diagnostics

source/ada/lsp-ada_handlers-project_diagnostics.ads

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,29 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with LSP.Ada_Contexts;
1918
with LSP.Ada_Project_Loading;
2019
with LSP.Diagnostic_Sources;
2120

2221
package LSP.Ada_Handlers.Project_Diagnostics is
2322

2423
type Diagnostic_Source
25-
(Handler : not null access LSP.Ada_Handlers.Message_Handler)
26-
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with private;
24+
(Handler : not null access LSP.Ada_Handlers.Message_Handler'Class)
25+
is limited new LSP.Diagnostic_Sources.Workspace_Diagnostic_Source with private;
2726

28-
overriding procedure Get_Diagnostic
29-
(Self : in out Diagnostic_Source;
30-
Context : LSP.Ada_Contexts.Context;
31-
Errors : out LSP.Structures.Diagnostic_Vector);
27+
overriding
28+
procedure Get_Diagnostics
29+
(Self : in out Diagnostic_Source;
30+
Diagnostics : out LSP.Structures.Diagnostic_Vector);
3231
-- Fill diagnostics for given document.
3332

3433
overriding function Has_New_Diagnostic
35-
(Self : in out Diagnostic_Source;
36-
Context : LSP.Ada_Contexts.Context) return Boolean;
34+
(Self : in out Diagnostic_Source) return Boolean;
3735

3836
private
3937

4038
type Diagnostic_Source
41-
(Handler : not null access LSP.Ada_Handlers.Message_Handler)
42-
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with record
39+
(Handler : not null access LSP.Ada_Handlers.Message_Handler'Class)
40+
is limited new LSP.Diagnostic_Sources.Workspace_Diagnostic_Source with record
4341
Last_Status : LSP.Ada_Project_Loading.Project_Status_Type;
4442
end record;
4543

source/ada/lsp-ada_handlers-project_loading.adb

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,26 @@ package body LSP.Ada_Handlers.Project_Loading is
168168
Tracer.Trace_Text ("Found ada.projectFile = " & Project_File);
169169

170170
if Project_File.Starts_With ("file://") then
171-
Project_File := VSS.Strings.Conversions.To_Virtual_String
172-
(URIs.Conversions.To_File
173-
(VSS.Strings.Conversions.To_UTF_8_String (Project_File), True));
171+
Project_File :=
172+
VSS.Strings.Conversions.To_Virtual_String
173+
(URIs.Conversions.To_File
174+
(VSS.Strings.Conversions.To_UTF_8_String (Project_File),
175+
True));
174176
end if;
175177

176178
-- Report how we found the project
177-
Self.Project_Status.Set_Project_Type (LSP.Ada_Project_Loading.Configured_Project);
179+
Self.Project_Status.Set_Project_Type
180+
(LSP.Ada_Project_Loading.Configured_Project);
178181

179182
elsif Is_Alire_Crate then
180183
Tracer.Trace ("Workspace is an Alire crate");
181184
Tracer.Trace ("Determining project from 'alr show' output");
182185

183186
LSP.Alire.Determine_Alire_Project
184-
(Root => Self.Client.Root_Directory.Display_Full_Name,
185-
Has_Alire => Has_Alire,
186-
Error => Alire_Errors,
187-
Project => Project_File);
187+
(Root => Self.Client.Root_Directory.Display_Full_Name,
188+
Has_Alire => Has_Alire,
189+
Error => Alire_Errors,
190+
Project => Project_File);
188191

189192
if not Has_Alire then
190193
Tracer.Trace
@@ -196,7 +199,8 @@ package body LSP.Ada_Handlers.Project_Loading is
196199
Tracer.Trace_Text ("Encountered errors: " & Alire_Errors);
197200
else
198201
-- Report how we found the project
199-
Self.Project_Status.Set_Project_Type (LSP.Ada_Project_Loading.Alire_Project);
202+
Self.Project_Status.Set_Project_Type
203+
(LSP.Ada_Project_Loading.Alire_Project);
200204
end if;
201205
end if;
202206

@@ -205,7 +209,7 @@ package body LSP.Ada_Handlers.Project_Loading is
205209
Tracer.Trace ("Looking for a unique project at the root");
206210
declare
207211
Files : GNATCOLL.VFS.File_Array_Access :=
208-
Self.Client.Root_Directory.Read_Dir (GNATCOLL.VFS.Files_Only);
212+
Self.Client.Root_Directory.Read_Dir (GNATCOLL.VFS.Files_Only);
209213
Found : GNATCOLL.VFS.Virtual_File;
210214
begin
211215
for X of Files.all loop
@@ -222,24 +226,32 @@ package body LSP.Ada_Handlers.Project_Loading is
222226
Project_File := LSP.Utils.To_Virtual_String (Found);
223227

224228
-- Report how we found the project
225-
Self.Project_Status.Set_Project_Type (LSP.Ada_Project_Loading.Single_Project_Found);
229+
Self.Project_Status.Set_Project_Type
230+
(LSP.Ada_Project_Loading.Single_Project_Found);
226231

227232
Tracer.Trace_Text ("Found unique project: " & Project_File);
228233
else
229-
Tracer.Trace ("Found " & GPRs_Found'Image & " projects at the root");
234+
Tracer.Trace
235+
("Found " & GPRs_Found'Image & " projects at the root");
230236
end if;
231237
end;
232238
end if;
233239

234240
-- At this stage we tried everything to find a project file. Now let's try to load.
235241
if not Project_File.Is_Empty then
236242
declare
237-
Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment;
243+
Environment : GPR2.Environment.Object :=
244+
GPR2.Environment.Process_Environment;
238245

239246
Charset : constant VSS.Strings.Virtual_String :=
240-
(if not Self.Configuration.Charset.Is_Empty then Self.Configuration.Charset
241-
elsif Is_Alire_Crate then VSS.Strings.Virtual_String'("utf-8") -- Alire projects tend to prefer utf-8
242-
else "iso-8859-1");
247+
(if not Self.Configuration.Charset.Is_Empty
248+
then Self.Configuration.Charset
249+
elsif Is_Alire_Crate
250+
then
251+
VSS.Strings.Virtual_String'
252+
("utf-8") -- Alire projects tend to prefer utf-8
253+
else
254+
"iso-8859-1");
243255

244256
Errors : VSS.Strings.Virtual_String;
245257
begin
@@ -248,16 +260,19 @@ package body LSP.Ada_Handlers.Project_Loading is
248260
Tracer.Trace ("Setting environment from 'alr printenv'");
249261

250262
LSP.Alire.Setup_Alire_Env
251-
(Root => Self.Client.Root_Directory.Display_Full_Name,
263+
(Root =>
264+
Self.Client.Root_Directory.Display_Full_Name,
252265
Has_Alire => Has_Alire,
253266
Error => Errors,
254267
Environment => Environment);
255268

256269
if not Errors.Is_Empty then
257-
Tracer.Trace_Text ("Encountered errors with Alire:" & LF & Errors);
270+
Tracer.Trace_Text
271+
("Encountered errors with Alire:" & LF & Errors);
258272
end if;
259273
else
260-
Tracer.Trace ("Alire environment is already set up. Not calling 'alr printenv'.");
274+
Tracer.Trace
275+
("Alire environment is already set up. Not calling 'alr printenv'.");
261276
end if;
262277
end if;
263278

@@ -277,14 +292,19 @@ package body LSP.Ada_Handlers.Project_Loading is
277292
Load_Implicit_Project
278293
(Self,
279294
(if GPRs_Found = 0 then LSP.Ada_Project_Loading.No_Project
280-
elsif GPRs_Found > 1 then LSP.Ada_Project_Loading.Multiple_Projects
295+
elsif GPRs_Found > 1
296+
then LSP.Ada_Project_Loading.Multiple_Projects
281297
else LSP.Ada_Project_Loading.Project_Not_Found));
282298
end if;
283299

284300
-- By this point we must have a context: either a project was
285301
-- successfully loaded, or project loading failed and we created a dummy
286302
-- context to avoid retrying.
287303
pragma Assert (not Self.Contexts.Is_Empty);
304+
305+
-- Publish workspace diagnostics every time a project might have
306+
-- been loaded/reloaded.
307+
Self.Publish_Diagnostics (Force => True);
288308
end Ensure_Project_Loaded;
289309

290310
---------------------

0 commit comments

Comments
 (0)