Skip to content

Commit e47a97d

Browse files
Merge branch 'topic/eng/ide/ada_language_server#1576' into 'master'
Call Update_Sources only when GPR files are saved See merge request eng/ide/ada_language_server!1883
2 parents aa4e3a1 + dc3c497 commit e47a97d

File tree

10 files changed

+308
-27
lines changed

10 files changed

+308
-27
lines changed

source/gpr/lsp-gpr_did_change_document.adb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ package body LSP.GPR_Did_Change_Document is
102102
(Message.Params.textDocument.version, Changes);
103103
end if;
104104

105-
-- Load gpr tree & prepare diagnostics
105+
-- Load gpr tree & prepare diagnostics.
106+
-- Do not update the tree's sources because it's too slow: we only want
107+
-- to publish syntactic and semantic diagnostics here.
106108

107109
Self.Document.Load
108-
(Client => Self.Parent.Context.Get_Client.all,
109-
Configuration => Self.Parent.Context.Get_Configuration);
110+
(Client => Self.Parent.Context.Get_Client.all,
111+
Configuration => Self.Parent.Context.Get_Configuration,
112+
Update_Sources => False);
110113

111114
-- Build GPR file for LSP needs.
112115

source/gpr/lsp-gpr_documents.adb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ package body LSP.GPR_Documents is
176176
----------
177177

178178
procedure Load
179-
(Self : in out Document;
180-
Client : LSP.Ada_Client_Capabilities.Client_Capability;
181-
Configuration : LSP.Ada_Configurations.Configuration) is
179+
(Self : in out Document;
180+
Client : LSP.Ada_Client_Capabilities.Client_Capability;
181+
Configuration : LSP.Ada_Configurations.Configuration;
182+
Update_Sources : Boolean := False) is
182183

183184
procedure Update_Diagnostics;
184185
-- Update Self.Messages, Self.Errors_Changed, Self.Has_Diagnostics
@@ -216,15 +217,14 @@ package body LSP.GPR_Documents is
216217
Opts.Add_Switch (GPR2.Options.P, String (Self.File.Value));
217218
Opts.Add_Context (Configuration.Context);
218219

219-
Success := Self.Tree.Load
220-
(Opts,
221-
Reporter => Reporter,
222-
With_Runtime => True,
223-
Absent_Dir_Error => GPR2.No_Error,
224-
File_Reader => Self.File_Provider.Get_File_Reader,
225-
Environment => LSP.GPR_Files.Environment);
220+
Success :=
221+
Self.Tree.Load
222+
(Opts, Reporter => Reporter, With_Runtime => True,
223+
Absent_Dir_Error => GPR2.No_Error,
224+
File_Reader => Self.File_Provider.Get_File_Reader,
225+
Environment => LSP.GPR_Files.Environment);
226226

227-
if Success then
227+
if Update_Sources and then Success then
228228
Self.Tree.Update_Sources;
229229
end if;
230230

source/gpr/lsp-gpr_documents.ads

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ package LSP.GPR_Documents is
7474
-- project status diagnostic source.
7575

7676
procedure Load
77-
(Self : in out Document;
78-
Client : LSP.Ada_Client_Capabilities.Client_Capability;
79-
Configuration : LSP.Ada_Configurations.Configuration);
77+
(Self : in out Document;
78+
Client : LSP.Ada_Client_Capabilities.Client_Capability;
79+
Configuration : LSP.Ada_Configurations.Configuration;
80+
Update_Sources : Boolean := False);
8081
-- Load associated GPR tree.
82+
-- If Update_Sources is True, the tree's sources will be updated after
83+
-- loading it successfully, allowing to retrieve GPR2 warnings/errors
84+
-- related to source files and directories later on.
8185

8286
procedure Cleanup (Self : in out Document);
8387
-- Free all the data associated to this document.

source/gpr/lsp-gpr_handlers.adb

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =>

source/gpr/lsp-gpr_handlers.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ private
153153
(Self : in out Message_Handler;
154154
Value : LSP.Structures.DidOpenTextDocumentParams);
155155

156+
overriding procedure On_DidSave_Notification
157+
(Self : in out Message_Handler;
158+
Value : LSP.Structures.DidSaveTextDocumentParams);
159+
156160
overriding procedure On_Hover_Request
157161
(Self : in out Message_Handler;
158162
Id : LSP.Structures.Integer_Or_Virtual_String;

testsuite/.als/gpr_ls_traces.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
>gpr_ls_log.$T.log:buffer_size=0:buffer_size=0
22
ALS.MAIN=yes
3-
ALS.IN=no
4-
ALS.OUT=no
3+
ALS.IN=yes
4+
ALS.OUT=yes
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project Default is
2+
for Main use ("main.adb");
3+
for Source_Dirs use ("src");
4+
end Default;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Main is
2+
begin
3+
null;
4+
end Main;

0 commit comments

Comments
 (0)