|
| 1 | +------------------------------------------------------------------------------ |
| 2 | +-- Language Server Protocol -- |
| 3 | +-- -- |
| 4 | +-- Copyright (C) 2024, AdaCore -- |
| 5 | +-- -- |
| 6 | +-- This is free software; you can redistribute it and/or modify it under -- |
| 7 | +-- terms of the GNU General Public License as published by the Free Soft- -- |
| 8 | +-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 9 | +-- sion. This software is distributed in the hope that it will be useful, -- |
| 10 | +-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- |
| 11 | +-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -- |
| 12 | +-- License for more details. You should have received a copy of the GNU -- |
| 13 | +-- General Public License distributed with this software; see file -- |
| 14 | +-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- |
| 15 | +-- of the license. -- |
| 16 | +------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +with LSP.Ada_Configurations; |
| 19 | +with LSP.Client_Message_Receivers; |
| 20 | +with LSP.Server_Notifications.DidChangeConfiguration; |
| 21 | + |
| 22 | +package body LSP.Ada_Did_Change_Configurations is |
| 23 | + |
| 24 | + type Apply_Config_Job |
| 25 | + (Parent : not null access constant Ada_Did_Change_Handler) |
| 26 | + is limited new LSP.Server_Jobs.Server_Job with record |
| 27 | + Message : LSP.Server_Messages.Server_Message_Access; |
| 28 | + Configuration : LSP.Ada_Configurations.Configuration; |
| 29 | + Reload : Boolean; |
| 30 | + Is_Done : Boolean := False; |
| 31 | + end record; |
| 32 | + |
| 33 | + type Apply_Config_Job_Access is access all Apply_Config_Job; |
| 34 | + |
| 35 | + overriding function Priority |
| 36 | + (Self : Apply_Config_Job) return LSP.Server_Jobs.Job_Priority is |
| 37 | + (LSP.Server_Jobs.Fence); |
| 38 | + |
| 39 | + overriding function Is_Done (Self : Apply_Config_Job) return Boolean is |
| 40 | + (Self.Is_Done); |
| 41 | + |
| 42 | + overriding procedure Execute |
| 43 | + (Self : in out Apply_Config_Job; |
| 44 | + Client : |
| 45 | + in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class); |
| 46 | + |
| 47 | + overriding function Message (Self : Apply_Config_Job) |
| 48 | + return LSP.Server_Messages.Server_Message_Access is (Self.Message); |
| 49 | + |
| 50 | + ------------- |
| 51 | + -- Execute -- |
| 52 | + ------------- |
| 53 | + |
| 54 | + overriding procedure Execute |
| 55 | + (Self : in out Apply_Config_Job; |
| 56 | + Client : |
| 57 | + in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class) is |
| 58 | + begin |
| 59 | + Self.Parent.Context.Set_Configuration (Self.Configuration); |
| 60 | + |
| 61 | + if Self.Reload then |
| 62 | + Self.Parent.Context.Reload_Project; |
| 63 | + end if; |
| 64 | + |
| 65 | + Self.Is_Done := True; |
| 66 | + end Execute; |
| 67 | + |
| 68 | + ---------------- |
| 69 | + -- Create_Job -- |
| 70 | + ---------------- |
| 71 | + |
| 72 | + overriding function Create_Job |
| 73 | + (Self : Ada_Did_Change_Handler; |
| 74 | + Message : LSP.Server_Messages.Server_Message_Access) |
| 75 | + return LSP.Server_Jobs.Server_Job_Access |
| 76 | + is |
| 77 | + Value : LSP.Server_Notifications.DidChangeConfiguration.Notification |
| 78 | + renames LSP.Server_Notifications.DidChangeConfiguration.Notification |
| 79 | + (Message.all); |
| 80 | + |
| 81 | + Result : constant Apply_Config_Job_Access := |
| 82 | + new Apply_Config_Job (Self'Unchecked_Access); |
| 83 | + |
| 84 | + Reload : Boolean renames Result.Reload; |
| 85 | + begin |
| 86 | + Result.Configuration := Self.Context.Get_Configuration.all; |
| 87 | + Result.Configuration.Read_JSON (Value.Params.settings, Reload); |
| 88 | + |
| 89 | + -- Always reload project if Project_Tree isn't ready |
| 90 | + Reload := Reload or not Self.Context.Project_Tree_Is_Defined; |
| 91 | + |
| 92 | + if Reload then |
| 93 | + -- Stop indexing by changing project stamp |
| 94 | + Self.Context.Increment_Project_Timestamp; |
| 95 | + end if; |
| 96 | + |
| 97 | + return LSP.Server_Jobs.Server_Job_Access (Result); |
| 98 | + end Create_Job; |
| 99 | + |
| 100 | +end LSP.Ada_Did_Change_Configurations; |
0 commit comments