@@ -85,6 +85,7 @@ with LSP.Ada_Handlers.Refactor.Suppress_Seperate;
85
85
with LSP.Ada_Handlers.Renaming ;
86
86
with LSP.Ada_Handlers.Symbols ;
87
87
with LSP.Ada_Commands ;
88
+ with LSP.Client_Side_File_Monitors ;
88
89
with LSP.Constants ;
89
90
with LSP.Diagnostic_Sources ;
90
91
with LSP.Enumerations ;
@@ -95,6 +96,7 @@ with LSP.GNATCOLL_Tracers.Handle;
95
96
with LSP.Search ;
96
97
with LSP.Server_Notifications.DidChange ;
97
98
with LSP.Servers ;
99
+ with LSP.Servers.FS_Watch ;
98
100
with LSP.Structures.LSPAny_Vectors ;
99
101
with LSP.Utils ;
100
102
@@ -110,15 +112,6 @@ package body LSP.Ada_Handlers is
110
112
function Is_Child return AlsReferenceKind_Array is
111
113
([LSP.Enumerations.child => True, others => False]);
112
114
113
- function Contexts_For_URI
114
- (Self : access Message_Handler;
115
- URI : LSP.Structures.DocumentUri)
116
- return LSP.Ada_Context_Sets.Context_Lists.List;
117
- -- Return a list of contexts that are suitable for the given File/URI:
118
- -- a list of all contexts where the file is known to be part of the
119
- -- project tree, or is a runtime file for this project. If the file
120
- -- is not known to any project, return an empty list.
121
-
122
115
procedure Clean_Diagnostics
123
116
(Self : in out Message_Handler'Class;
124
117
Document : not null LSP.Ada_Documents.Document_Access);
@@ -392,7 +385,7 @@ package body LSP.Ada_Handlers is
392
385
-- --------------
393
386
394
387
procedure Initialize
395
- (Self : in out Message_Handler'Class;
388
+ (Self : access Message_Handler'Class;
396
389
Incremental_Text_Changes : Boolean;
397
390
Config_File : VSS.Strings.Virtual_String)
398
391
is
@@ -416,11 +409,13 @@ package body LSP.Ada_Handlers is
416
409
417
410
begin
418
411
Self.Incremental_Text_Changes := Incremental_Text_Changes;
412
+ Self.File_Monitor :=
413
+ new LSP.Servers.FS_Watch.FS_Watch_Monitor (Self.Server);
419
414
420
415
if not Config_File.Is_Empty then
421
416
Self.Configuration.Read_File (Config_File);
422
417
Self.Client.Set_Root_If_Empty (Directory (Config_File));
423
- LSP.Ada_Handlers.Project_Loading.Reload_Project (Self);
418
+ LSP.Ada_Handlers.Project_Loading.Reload_Project (Self. all );
424
419
end if ;
425
420
end Initialize ;
426
421
@@ -2238,6 +2233,130 @@ package body LSP.Ada_Handlers is
2238
2233
end if ;
2239
2234
end On_DidChangeConfiguration_Notification ;
2240
2235
2236
+ -- -----------------------------------------
2237
+ -- On_DidChangeWatchedFiles_Notification --
2238
+ -- -----------------------------------------
2239
+
2240
+ overriding procedure On_DidChangeWatchedFiles_Notification
2241
+ (Self : in out Message_Handler;
2242
+ Value : LSP.Structures.DidChangeWatchedFilesParams)
2243
+ is
2244
+ use type LSP.Ada_Documents.Document_Access;
2245
+
2246
+ URI : LSP.Structures.DocumentUri;
2247
+ File : GNATCOLL.VFS.Virtual_File;
2248
+
2249
+ procedure Process_Created_File ;
2250
+ -- Processes a created file
2251
+
2252
+ procedure Process_Deleted_File ;
2253
+ -- Processes a deleted file
2254
+
2255
+ procedure Process_Changed_File ;
2256
+ -- Processes a changed file
2257
+
2258
+ -- ------------------------
2259
+ -- Process_Changed_File --
2260
+ -- ------------------------
2261
+
2262
+ procedure Process_Changed_File is
2263
+ begin
2264
+ if Self.Get_Open_Document (URI) = null then
2265
+ -- If there is no document, reindex the file for each
2266
+ -- context where it is relevant.
2267
+ File := Self.To_File (URI);
2268
+
2269
+ for C of Self.Contexts_For_File (File) loop
2270
+ C.Index_File (File);
2271
+ end loop ;
2272
+ end if ;
2273
+ end Process_Changed_File ;
2274
+
2275
+ -- ------------------------
2276
+ -- Process_Created_File --
2277
+ -- ------------------------
2278
+
2279
+ procedure Process_Created_File
2280
+ is
2281
+ use VSS.Strings.Conversions;
2282
+
2283
+ Contexts : constant LSP.Ada_Context_Sets.Context_Lists.List :=
2284
+ Self.Contexts_For_File (File);
2285
+
2286
+ function Has_Dir
2287
+ (Context : LSP.Ada_Contexts.Context)
2288
+ return Boolean
2289
+ is (Context.List_Source_Directories.Contains (File.Dir));
2290
+ -- Return True if File is in a source directory of the project held
2291
+ -- by Context.
2292
+
2293
+ begin
2294
+ -- If the file was created by the client, then the DidCreateFiles
2295
+ -- notification might have been received from it. In that case,
2296
+ -- Contexts wont be empty, and all we need to do is check if
2297
+ -- there's an open document. If there is, it takes precedence over
2298
+ -- the filesystem.
2299
+ -- If Contexts is empty, then we need to check if is a new source
2300
+ -- that needs to be added. For instance, a source that was moved
2301
+ -- to the the project source directories.
2302
+
2303
+ if Contexts.Is_Empty then
2304
+ for Context of Self.Contexts.Each_Context
2305
+ (Has_Dir'Unrestricted_Access)
2306
+ loop
2307
+ Context.Include_File (File);
2308
+ Context.Index_File (File);
2309
+
2310
+ Self.Tracer.Trace
2311
+ (" Included " & File.Display_Base_Name
2312
+ & " in context " & To_UTF_8_String (Context.Id));
2313
+ end loop ;
2314
+
2315
+ else
2316
+ if Self.Get_Open_Document (URI) = null then
2317
+ for Context of Contexts loop
2318
+ Context.Index_File (File);
2319
+ end loop ;
2320
+ end if ;
2321
+ end if ;
2322
+ end Process_Created_File ;
2323
+
2324
+ -- -------------------------
2325
+ -- Process_Deleted_Files --
2326
+ -- -------------------------
2327
+
2328
+ procedure Process_Deleted_File is
2329
+ begin
2330
+ if Self.Get_Open_Document (URI) = null then
2331
+ -- If there is no document, remove from the sources list
2332
+ -- and reindex the file for each context where it is
2333
+ -- relevant.
2334
+ File := Self.To_File (URI);
2335
+
2336
+ for C of Self.Contexts_For_File (File) loop
2337
+ C.Exclude_File (File);
2338
+ C.Index_File (File);
2339
+ end loop ;
2340
+ end if ;
2341
+ end Process_Deleted_File ;
2342
+
2343
+ begin
2344
+ -- Look through each change, filtering non Ada source files
2345
+ for Change of Value.changes loop
2346
+ URI := Change.uri;
2347
+ File := Self.To_File (URI);
2348
+
2349
+ case Change.a_type is
2350
+ when LSP.Enumerations.Created =>
2351
+ Process_Created_File;
2352
+ when LSP.Enumerations.Deleted =>
2353
+ Process_Deleted_File;
2354
+ when LSP.Enumerations.Changed =>
2355
+ Process_Changed_File;
2356
+ end case ;
2357
+ end loop ;
2358
+ end On_DidChangeWatchedFiles_Notification ;
2359
+
2241
2360
-- ---------------------------------------------
2242
2361
-- On_DidChangeWorkspaceFolders_Notification --
2243
2362
-- ---------------------------------------------
@@ -3253,6 +3372,10 @@ package body LSP.Ada_Handlers is
3253
3372
Id : LSP.Structures.Integer_Or_Virtual_String;
3254
3373
Value : LSP.Structures.InitializeParams)
3255
3374
is
3375
+ procedure Free is new Ada.Unchecked_Deallocation
3376
+ (LSP.File_Monitors.File_Monitor'Class,
3377
+ LSP.File_Monitors.File_Monitor_Access);
3378
+
3256
3379
Response : LSP.Structures.InitializeResult;
3257
3380
Token_Types : LSP.Structures.Virtual_String_Vector;
3258
3381
Token_Motifiers : LSP.Structures.Virtual_String_Vector;
@@ -3268,6 +3391,14 @@ package body LSP.Ada_Handlers is
3268
3391
Token_Types,
3269
3392
Token_Motifiers);
3270
3393
3394
+ if Self.Client.didChangeWatchedFiles_dynamicRegistration then
3395
+ Free (Self.File_Monitor);
3396
+
3397
+ Self.File_Monitor :=
3398
+ new LSP.Client_Side_File_Monitors.File_Monitor
3399
+ (Self'Unchecked_Access);
3400
+ end if ;
3401
+
3271
3402
Self.Sender.On_Initialize_Response (Id, Response);
3272
3403
end On_Initialize_Request ;
3273
3404
0 commit comments