|
| 1 | +------------------------------------------------------------------------------ |
| 2 | +-- Language Server Protocol -- |
| 3 | +-- -- |
| 4 | +-- Copyright (C) 2021, 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 Ada.Strings.UTF_Encoding; |
| 19 | + |
| 20 | +with LSP.Messages.Client_Requests; |
| 21 | + |
| 22 | +with VSS.Strings.Conversions; |
| 23 | + |
| 24 | +package body LSP.Ada_Handlers.Other_File_Commands is |
| 25 | + |
| 26 | + ------------ |
| 27 | + -- Create -- |
| 28 | + ------------ |
| 29 | + |
| 30 | + overriding function Create |
| 31 | + (JS : not null access LSP.JSON_Streams.JSON_Stream'Class) return Command |
| 32 | + is |
| 33 | + begin |
| 34 | + return V : Command do |
| 35 | + pragma Assert (JS.R.Is_Start_Object); |
| 36 | + JS.R.Read_Next; |
| 37 | + |
| 38 | + while not JS.R.Is_End_Object loop |
| 39 | + pragma Assert (JS.R.Is_Key_Name); |
| 40 | + declare |
| 41 | + Key : constant Ada.Strings.UTF_Encoding.UTF_8_String := |
| 42 | + VSS.Strings.Conversions.To_UTF_8_String (JS.R.Key_Name); |
| 43 | + begin |
| 44 | + JS.R.Read_Next; |
| 45 | + |
| 46 | + if Key = "uri" then |
| 47 | + LSP.Types.Read (JS, V.URI); |
| 48 | + else |
| 49 | + JS.Skip_Value; |
| 50 | + end if; |
| 51 | + end; |
| 52 | + end loop; |
| 53 | + JS.R.Read_Next; |
| 54 | + end return; |
| 55 | + end Create; |
| 56 | + |
| 57 | + ------------- |
| 58 | + -- Execute -- |
| 59 | + ------------- |
| 60 | + |
| 61 | + overriding procedure Execute |
| 62 | + (Self : Command; |
| 63 | + Handler : not null access LSP.Server_Notification_Receivers |
| 64 | + .Server_Notification_Receiver' |
| 65 | + Class; |
| 66 | + Client : not null access LSP.Client_Message_Receivers |
| 67 | + .Client_Message_Receiver' |
| 68 | + Class; |
| 69 | + Error : in out LSP.Errors.Optional_ResponseError) |
| 70 | + is |
| 71 | + Message_Handler : LSP.Ada_Handlers.Message_Handler renames |
| 72 | + LSP.Ada_Handlers.Message_Handler (Handler.all); |
| 73 | + |
| 74 | + Context : LSP.Ada_Contexts.Context renames |
| 75 | + Message_Handler.Contexts.Get_Best_Context (Self.URI).all; |
| 76 | + |
| 77 | + File : constant GNATCOLL.VFS.Virtual_File := Context.To_File (Self.URI); |
| 78 | + |
| 79 | + Other_File : constant GNATCOLL.VFS.Virtual_File := |
| 80 | + Message_Handler.Project_Tree.Other_File (File); |
| 81 | + |
| 82 | + URI : constant LSP.Messages.DocumentUri := |
| 83 | + LSP.Ada_Contexts.File_To_URI |
| 84 | + (LSP.Types.To_LSP_String (Other_File.Display_Full_Name)); |
| 85 | + |
| 86 | + Message : constant LSP.Messages.Client_Requests.ShowDocument_Request := |
| 87 | + (params => |
| 88 | + (uri => URI, |
| 89 | + takeFocus => LSP.Types.True, |
| 90 | + others => <>), |
| 91 | + others => <>); |
| 92 | + begin |
| 93 | + Client.On_ShowDocument_Request (Message); |
| 94 | + end Execute; |
| 95 | + |
| 96 | + ---------------- |
| 97 | + -- Initialize -- |
| 98 | + ---------------- |
| 99 | + |
| 100 | + procedure Initialize |
| 101 | + (Self : in out Command'Class; URI : LSP.Messages.DocumentUri) |
| 102 | + is |
| 103 | + begin |
| 104 | + Self.URI := URI; |
| 105 | + end Initialize; |
| 106 | + |
| 107 | + ------------------- |
| 108 | + -- Write_Command -- |
| 109 | + ------------------- |
| 110 | + |
| 111 | + procedure Write_Command |
| 112 | + (S : access Ada.Streams.Root_Stream_Type'Class; V : Command) |
| 113 | + is |
| 114 | + JS : LSP.JSON_Streams.JSON_Stream'Class renames |
| 115 | + LSP.JSON_Streams.JSON_Stream'Class (S.all); |
| 116 | + begin |
| 117 | + JS.Start_Object; |
| 118 | + JS.Key ("uri"); |
| 119 | + LSP.Types.Write (S, V.URI); |
| 120 | + JS.End_Object; |
| 121 | + end Write_Command; |
| 122 | + |
| 123 | +end LSP.Ada_Handlers.Other_File_Commands; |
0 commit comments