@@ -200,7 +200,7 @@ package body LSP.GPR_Handlers is
200200 (Self : in out Message_Handler;
201201 Value : LSP.Structures.DidOpenTextDocumentParams)
202202 is
203- URI : constant LSP.Structures.DocumentUri := Value.textDocument.uri;
203+ URI : constant LSP.Structures.DocumentUri := Value.textDocument.uri;
204204 File : constant GNATCOLL.VFS.Virtual_File := Self.To_File (URI);
205205 Object : constant Internal_Document_Access :=
206206 new LSP.GPR_Documents.Document (Self.Tracer);
@@ -212,19 +212,18 @@ package body LSP.GPR_Handlers is
212212
213213 -- We have received a document: add it to the documents container
214214 Object.Initialize
215- (URI,
216- GPR2.Path_Name.Create (Self.To_File (URI)),
217- Value.textDocument.text,
218- Self'Unchecked_Access);
215+ (URI, GPR2.Path_Name.Create (Self.To_File (URI)),
216+ Value.textDocument.text, Self'Unchecked_Access);
219217
220218 Self.Open_Documents.Include (File, Object);
221219
222220 -- Load gpr tree & prepare diagnostics
223221
224222 begin
225223 Object.Load
226- (Client => Self.Client,
227- Configuration => Self.Get_Configuration);
224+ (Client => Self.Client,
225+ Configuration => Self.Get_Configuration,
226+ Update_Sources => True);
228227 exception
229228 when E : others =>
230229 Self.Tracer.Trace_Exception (E, " On_DidOpen_Notification" );
@@ -243,6 +242,36 @@ package body LSP.GPR_Handlers is
243242 Self.Tracer.Trace (" Finished Text_Document_Did_Open" );
244243 end On_DidOpen_Notification ;
245244
245+ -- ---------------------------
246+ -- On_DidSave_Notification --
247+ -- ---------------------------
248+
249+ overriding procedure On_DidSave_Notification
250+ (Self : in out Message_Handler;
251+ Value : LSP.Structures.DidSaveTextDocumentParams)
252+ is
253+ URI : LSP.Structures.DocumentUri renames Value.textDocument.uri;
254+
255+ Document : constant LSP.GPR_Documents.Document_Access :=
256+ Self.Get_Open_Document (URI);
257+ begin
258+ -- Reload the project tree on saving, and update its sources
259+ -- to get GPR2 diagnostics related to source files/directories.
260+ Document.Load
261+ (Client => Self.Get_Client.all ,
262+ Configuration => Self.Get_Configuration,
263+ Update_Sources => True);
264+
265+ -- Build GPR file for LSP needs.
266+
267+ LSP.GPR_Files.Parse_Modified_Document
268+ (File_Provider => Self'Unrestricted_Access,
269+ Path => Self.To_File (URI));
270+
271+ -- Emit diagnostics
272+ Self.Publish_Diagnostics (Document);
273+ end On_DidSave_Notification ;
274+
246275 -- -----------------------------
247276 -- On_DocumentSymbol_Request --
248277 -- -----------------------------
@@ -393,6 +422,8 @@ package body LSP.GPR_Handlers is
393422 (openClose => (Is_Set => True, Value => True),
394423 change =>
395424 (Is_Set => True, Value => LSP.Enumerations.Full),
425+ save =>
426+ (Is_Set => True, Value => (True, True)),
396427 others => <>)));
397428
398429 Response.capabilities.documentSymbolProvider :=
@@ -658,7 +689,10 @@ package body LSP.GPR_Handlers is
658689 for Document of Self.Open_Documents loop
659690 begin
660691 -- reload gpr tree
661- Document.Load (Self.Client, Self.Configuration);
692+ Document.Load
693+ (Client => Self.Client,
694+ Configuration => Self.Configuration,
695+ Update_Sources => True);
662696
663697 exception
664698 when E : others =>
0 commit comments