@@ -178,16 +178,6 @@ package body LSP.Ada_Handlers is
178178 (Self : in out Message_Handler; Context : LSP.Ada_Contexts.Context)
179179 return Libadalang.Analysis.Analysis_Unit_Array;
180180
181- procedure Get_Workspace_Diagnostics
182- (Self : in out Message_Handler'Class;
183- Changed : out Boolean;
184- Errors : out LSP.Structures.Diagnostic_Vector;
185- Force : Boolean := False);
186- -- Get all the worskpace-specific diagnostics, using the handler's workspace
187- -- diagnostics' sources.
188- -- When Force is True, any existing diagnostic will be retrieved, no matter
189- -- if they have changed or not since the last query.
190-
191181 -- ---------------------------
192182 -- Allocate_Progress_Token --
193183 -- ---------------------------
@@ -391,27 +381,6 @@ package body LSP.Ada_Handlers is
391381 end if ;
392382 end Get_Open_Document_Version ;
393383
394- -- -----------------------------
395- -- Get_Workspace_Diagnostics --
396- -- -----------------------------
397-
398- procedure Get_Workspace_Diagnostics
399- (Self : in out Message_Handler'Class;
400- Changed : out Boolean;
401- Errors : out LSP.Structures.Diagnostic_Vector;
402- Force : Boolean := False) is
403- begin
404- Errors.Clear;
405- Changed := (for some Source of Self.Diagnostic_Sources =>
406- Source.Has_New_Diagnostic);
407-
408- if Changed or else Force then
409- for Source of Self.Diagnostic_Sources loop
410- Source.Get_Diagnostics (Errors);
411- end loop ;
412- end if ;
413- end Get_Workspace_Diagnostics ;
414-
415384 -- --------------------------
416385 -- Imprecise_Resolve_Name --
417386 -- --------------------------
@@ -454,13 +423,12 @@ package body LSP.Ada_Handlers is
454423 (Self : in out Message_Handler;
455424 Incremental_Text_Changes : Boolean;
456425 CLI_Config_File : GNATCOLL.VFS.Virtual_File :=
457- GNATCOLL.VFS.No_File)
458- is
426+ GNATCOLL.VFS.No_File) is
459427 begin
460428 Self.Incremental_Text_Changes := Incremental_Text_Changes;
461429 Self.File_Monitor :=
462430 new LSP.Servers.FS_Watch.FS_Watch_Monitor (Self.Server);
463- Self.Diagnostic_Sources :=
431+ Self.Workspace_Diagnostic_Sources :=
464432 [new LSP.Ada_Handlers.Project_Diagnostics.Diagnostic_Source
465433 (Self'Unchecked_Access)];
466434
@@ -3739,32 +3707,55 @@ package body LSP.Ada_Handlers is
37393707 -- -----------------------
37403708
37413709 procedure Publish_Diagnostics
3742- (Self : in out Message_Handler;
3743- Other_Diagnostics : LSP.Structures.Diagnostic_Vector :=
3744- LSP.Structures.Empty;
3745- Force : Boolean := False)
3710+ (Self : in out Message_Handler; Force : Boolean := False)
37463711 is
3747- Diag : LSP.Structures.PublishDiagnosticsParams;
3748- Changed : Boolean;
3712+ use GNATCOLL.VFS;
37493713
3714+ Diag : LSP.Structures.PublishDiagnosticsParams;
3715+ Changed : Boolean;
3716+ Target_File : Virtual_File;
37503717 begin
37513718 -- Retrieve all the workspace diagnostics and publish them.
37523719
37533720 if Self.Configuration.Diagnostics_Enabled then
3754- Diag.diagnostics.Append_Vector (Other_Diagnostics);
3721+ Changed :=
3722+ (for some Source of Self.Workspace_Diagnostic_Sources
3723+ => Source.Has_New_Diagnostic);
3724+
3725+ if Changed or else Force then
3726+ -- First clear any currently published workspace diagnostics
3727+ for File of Self.Workspace_Diagnostic_Files loop
3728+ Self.Sender.On_PublishDiagnostics_Notification
3729+ (LSP.Structures.PublishDiagnosticsParams'
3730+ (uri =>
3731+ (VSS.Strings.Conversions.To_Virtual_String
3732+ (URIs.Conversions.From_File (File.Display_Full_Name))
3733+ with null record ),
3734+ others => <>));
3735+ end loop ;
37553736
3756- Self.Get_Workspace_Diagnostics
3757- (Changed => Changed,
3758- Errors => Diag.diagnostics,
3759- Force => Force);
3737+ Self.Workspace_Diagnostic_Files.Clear;
37603738
3761- if Changed or else not Other_Diagnostics.Is_Empty then
3762- Diag.uri :=
3763- (VSS.Strings.Conversions.To_Virtual_String
3764- (URIs.Conversions.From_File
3765- (Self.Client.Root_Directory.Display_Full_Name))
3766- with null record );
3767- Self.Sender.On_PublishDiagnostics_Notification (Diag);
3739+ -- Query all the workspace diagnostic sources, and publish
3740+ -- diagnostics on their target file, if any
3741+ for Source of Self.Workspace_Diagnostic_Sources loop
3742+ Source.Get_Diagnostics
3743+ (Diagnostics => Diag.diagnostics, Target_File => Target_File);
3744+
3745+ -- We have some diagnostics: publish them
3746+ if not Diag.diagnostics.Is_Empty then
3747+ Self.Workspace_Diagnostic_Files.Include (Target_File);
3748+
3749+ Diag.uri :=
3750+ (VSS.Strings.Conversions.To_Virtual_String
3751+ (URIs.Conversions.From_File
3752+ (Target_File.Display_Full_Name))
3753+ with null record );
3754+ Self.Sender.On_PublishDiagnostics_Notification (Diag);
3755+
3756+ Diag.diagnostics.Clear;
3757+ end if ;
3758+ end loop ;
37683759 end if ;
37693760 end if ;
37703761 end Publish_Diagnostics ;
0 commit comments