diff --git a/source/ada/lsp-ada_client_capabilities.adb b/source/ada/lsp-ada_client_capabilities.adb index 6d5fa2367..872a91241 100644 --- a/source/ada/lsp-ada_client_capabilities.adb +++ b/source/ada/lsp-ada_client_capabilities.adb @@ -17,6 +17,8 @@ pragma Ada_2022; +with URIs; + with VSS.Characters.Latin; with VSS.JSON.Streams; with VSS.String_Vectors; @@ -25,6 +27,7 @@ with VSS.Strings.Conversions; with LSP.Ada_Configurations; with LSP.Constants; with LSP.Enumerations; +with LSP.GPR_Files; with LSP.Structures.Unwrap; with LSP.Structures.LSPAny_Vectors; @@ -205,6 +208,9 @@ package body LSP.Ada_Client_Capabilities is end if; Self.Parse_Experimental; + + LSP.GPR_Files.Set_Environment (Client_Capability (Self)); + end Initialize; ------------------------ @@ -593,4 +599,21 @@ package body LSP.Ada_Client_Capabilities is return (if Result.Is_Set then Result.Value else False); end Versioned_Documents; + -------------------- + -- Root_Directory -- + -------------------- + + function Root_Directory (Client : Client_Capability'Class) + return GNATCOLL.VFS.Virtual_File + is + Value : constant VSS.Strings.Virtual_String := Client.Root; + Root : constant String := + VSS.Strings.Conversions.To_UTF_8_String (Value); + begin + return GNATCOLL.VFS.Create_From_UTF8 + (if Value.Starts_With ("file://") + then URIs.Conversions.To_File (Root, True) + else Root); + end Root_Directory; + end LSP.Ada_Client_Capabilities; diff --git a/source/ada/lsp-ada_client_capabilities.ads b/source/ada/lsp-ada_client_capabilities.ads index 9d22b3f03..1ad855f53 100644 --- a/source/ada/lsp-ada_client_capabilities.ads +++ b/source/ada/lsp-ada_client_capabilities.ads @@ -15,6 +15,8 @@ -- of the license. -- ------------------------------------------------------------------------------ +with GNATCOLL.VFS; + with VSS.Strings; with LSP.Structures; @@ -46,6 +48,10 @@ package LSP.Ada_Client_Capabilities is -- if not rootUri/rootPath is provided, then it means no folder is open. -- Return an empty string in this case. + function Root_Directory + (Client : Client_Capability'Class) return GNATCOLL.VFS.Virtual_File; + -- Return the root directory of the client workspace + procedure Set_Root_If_Empty (Self : in out Client_Capability'Class; Value : VSS.Strings.Virtual_String); diff --git a/source/ada/lsp-ada_handlers-project_loading.adb b/source/ada/lsp-ada_handlers-project_loading.adb index 3be60215a..21a227075 100644 --- a/source/ada/lsp-ada_handlers-project_loading.adb +++ b/source/ada/lsp-ada_handlers-project_loading.adb @@ -29,11 +29,9 @@ with Libadalang.Preprocessing; with VSS.Strings.Conversions; -with Spawn.Environments; - with LSP.Ada_Contexts; with LSP.Ada_Context_Sets; -with LSP.Ada_Handlers.Alire; +with LSP.Alire; with LSP.Ada_Handlers.File_Readers; with LSP.Ada_Indexing; with LSP.Enumerations; @@ -85,10 +83,6 @@ package body LSP.Ada_Handlers.Project_Loading is -- Mark all sources in all projects for indexing. This factorizes code -- between Load_Project and Load_Implicit_Project. - function Root - (Self : Message_Handler'Class) return GNATCOLL.VFS.Virtual_File; - -- Return the root directory of the client workspace - --------------------------- -- Ensure_Project_Loaded -- --------------------------- @@ -125,7 +119,7 @@ package body LSP.Ada_Handlers.Project_Loading is if not Self.Client.Root.Is_Empty then declare Files : GNATCOLL.VFS.File_Array_Access := - Root (Self).Read_Dir (GNATCOLL.VFS.Files_Only); + Self.Client.Root_Directory.Read_Dir (GNATCOLL.VFS.Files_Only); begin for X of Files.all loop if X.Has_Suffix (".gpr") then @@ -203,7 +197,7 @@ package body LSP.Ada_Handlers.Project_Loading is -- root directory in the workspace. if not Self.Client.Root.Is_Empty then - Self.Project_Dirs_Loaded.Include (Root (Self)); + Self.Project_Dirs_Loaded.Include (Self.Client.Root_Directory); end if; Reload_Implicit_Project_Dirs (Self); @@ -313,8 +307,11 @@ package body LSP.Ada_Handlers.Project_Loading is -- relative path; if so, we're assuming it's relative -- to Self.Root. - if not Project_File.Is_Absolute_Path and then not Self.Client.Root.Is_Empty then - Project_File := GNATCOLL.VFS.Join (Root (Self), Project_File); + if not Project_File.Is_Absolute_Path + and then not Self.Client.Root.Is_Empty + then + Project_File := GNATCOLL.VFS.Join (Self.Client.Root_Directory, + Project_File); end if; -- Unload the project tree and the project environment @@ -424,21 +421,15 @@ package body LSP.Ada_Handlers.Project_Loading is Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment; - Alire_TOML : constant GNATCOLL.VFS.Virtual_File := - (if Self.Client.Root.Is_Empty then GNATCOLL.VFS.No_File - else Root (Self).Create_From_Dir ("alire.toml")); - begin - if Alire_TOML.Is_Regular_File - and Spawn.Environments.System_Environment.Value ("ALIRE") /= "True" - then + if LSP.Alire.Alire_Active (Self.Client) then Self.Tracer.Trace ("Check alire:"); if Project.Is_Empty then - LSP.Ada_Handlers.Alire.Determine_Alire_Project - (Root => Root (Self).Display_Full_Name, + LSP.Alire.Determine_Alire_Project + (Root => Self.Client.Root_Directory.Display_Full_Name, Has_Alire => Has_Alire, Error => Errors, Project => Project); @@ -446,8 +437,8 @@ package body LSP.Ada_Handlers.Project_Loading is Status := Alire_Project; end if; - LSP.Ada_Handlers.Alire.Setup_Alire_Env - (Root => Root (Self).Display_Full_Name, + LSP.Alire.Setup_Alire_Env + (Root => Self.Client.Root_Directory.Display_Full_Name, Has_Alire => Has_Alire, Error => Errors, Environment => Environment); @@ -628,23 +619,6 @@ package body LSP.Ada_Handlers.Project_Loading is end if; end Reload_Project; - ---------- - -- Root -- - ---------- - - function Root - (Self : Message_Handler'Class) return GNATCOLL.VFS.Virtual_File - is - Value : constant VSS.Strings.Virtual_String := Self.Client.Root; - Root : constant String := - VSS.Strings.Conversions.To_UTF_8_String (Value); - begin - return GNATCOLL.VFS.Create_From_UTF8 - (if Value.Starts_With ("file://") - then URIs.Conversions.To_File (Root, True) - else Root); - end Root; - --------------------------------------- -- Update_Project_Predefined_Sources -- --------------------------------------- diff --git a/source/ada/lsp-ada_handlers-alire.adb b/source/ada/lsp-alire.adb similarity index 94% rename from source/ada/lsp-ada_handlers-alire.adb rename to source/ada/lsp-alire.adb index f42a12c40..a96c3ae9a 100644 --- a/source/ada/lsp-ada_handlers-alire.adb +++ b/source/ada/lsp-alire.adb @@ -17,6 +17,7 @@ with Ada.Streams; with GNAT.OS_Lib; +with GNATCOLL.VFS; with VSS.Stream_Element_Vectors; with VSS.Strings.Conversions; @@ -25,12 +26,13 @@ with VSS.String_Vectors; with VSS.Characters.Latin; with VSS.Regular_Expressions; +with Spawn.Environments; with Spawn.Processes; with Spawn.Processes.Monitor_Loop; with Spawn.Process_Listeners; with Spawn.String_Vectors; -package body LSP.Ada_Handlers.Alire is +package body LSP.Alire is type Process_Listener is limited new Spawn.Process_Listeners.Process_Listener with record @@ -347,4 +349,20 @@ package body LSP.Ada_Handlers.Alire is end loop; end Standard_Output_Available; -end LSP.Ada_Handlers.Alire; + ------------------ + -- Alire_Active -- + ------------------ + + function Alire_Active + (Client : LSP.Ada_Client_Capabilities.Client_Capability) return Boolean is + Alire_TOML : constant GNATCOLL.VFS.Virtual_File := + (if Client.Root.Is_Empty then GNATCOLL.VFS.No_File + else Client.Root_Directory.Create_From_Dir + ("alire.toml")); + + begin + return Alire_TOML.Is_Regular_File + and Spawn.Environments.System_Environment.Value ("ALIRE") /= "True"; + end Alire_Active; + +end LSP.Alire; diff --git a/source/ada/lsp-ada_handlers-alire.ads b/source/ada/lsp-alire.ads similarity index 88% rename from source/ada/lsp-ada_handlers-alire.ads rename to source/ada/lsp-alire.ads index a4455cc10..ef942a59e 100644 --- a/source/ada/lsp-ada_handlers-alire.ads +++ b/source/ada/lsp-alire.ads @@ -19,10 +19,16 @@ with GPR2.Environment; +with LSP.Ada_Client_Capabilities; + with VSS.Strings; private -package LSP.Ada_Handlers.Alire is +package LSP.Alire is + + function Alire_Active + (Client : LSP.Ada_Client_Capabilities.Client_Capability) return Boolean; + -- True if 'alire.toml' exists at 'Client' root & $ALIRE variable is True procedure Determine_Alire_Project (Root : String; @@ -39,4 +45,4 @@ package LSP.Ada_Handlers.Alire is Environment : in out GPR2.Environment.Object); -- Run `alr printenv` and set up the obtained environment variables -end LSP.Ada_Handlers.Alire; +end LSP.Alire; diff --git a/source/ada/lsp-utils.ads b/source/ada/lsp-utils.ads index cf4653e14..436d28b22 100644 --- a/source/ada/lsp-utils.ads +++ b/source/ada/lsp-utils.ads @@ -131,4 +131,9 @@ package LSP.Utils is (VSS.Strings.Conversions.To_Virtual_String (Value.Display_Full_Name)); -- Cast Virtual_File to Virtual_String + function To_Virtual_String + (Path : GPR2.Path_Name.Object) return VSS.Strings.Virtual_String is + (VSS.Strings.Conversions.To_Virtual_String (Path.Value)); + -- Cast GPR2.Path_Name.Object to Virtual_String + end LSP.Utils; diff --git a/source/gpr/lsp-gpr_client_capabilities.adb b/source/gpr/lsp-gpr_client_capabilities.adb deleted file mode 100644 index fe05349af..000000000 --- a/source/gpr/lsp-gpr_client_capabilities.adb +++ /dev/null @@ -1,55 +0,0 @@ ------------------------------------------------------------------------------- --- Language Server Protocol -- --- -- --- Copyright (C) 2023, AdaCore -- --- -- --- This is free software; you can redistribute it and/or modify it under -- --- terms of the GNU General Public License as published by the Free Soft- -- --- ware Foundation; either version 3, or (at your option) any later ver- -- --- sion. This software is distributed in the hope that it will be useful, -- --- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- --- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -- --- License for more details. You should have received a copy of the GNU -- --- General Public License distributed with this software; see file -- --- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- --- of the license. -- ------------------------------------------------------------------------------- - -pragma Ada_2022; - -with VSS.String_Vectors; - -with LSP.Structures.Unwrap; - -package body LSP.GPR_Client_Capabilities is - - ---------------- - -- Initialize -- - ---------------- - - procedure Initialize - (Self : in out Client_Capability'Class; - Value : LSP.Structures.InitializeParams) is - begin - Self.Value := Value; - end Initialize; - - -------------------- - -- Resolve_Lazily -- - -------------------- - - function Resolve_Lazily (Self : Client_Capability'Class) return Boolean is - use LSP.Structures.Unwrap; - - List : constant VSS.String_Vectors.Virtual_String_Vector := - properties - (resolveSupport - (completionItem - (completion - (Self.Value.capabilities.textDocument)))); - - begin - return List.Contains ("detail") and then List.Contains ("documentation"); - end Resolve_Lazily; - -end LSP.GPR_Client_Capabilities; diff --git a/source/gpr/lsp-gpr_client_capabilities.ads b/source/gpr/lsp-gpr_client_capabilities.ads deleted file mode 100644 index df28e6dfa..000000000 --- a/source/gpr/lsp-gpr_client_capabilities.ads +++ /dev/null @@ -1,40 +0,0 @@ ------------------------------------------------------------------------------- --- Language Server Protocol -- --- -- --- Copyright (C) 2023, AdaCore -- --- -- --- This is free software; you can redistribute it and/or modify it under -- --- terms of the GNU General Public License as published by the Free Soft- -- --- ware Foundation; either version 3, or (at your option) any later ver- -- --- sion. This software is distributed in the hope that it will be useful, -- --- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- --- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -- --- License for more details. You should have received a copy of the GNU -- --- General Public License distributed with this software; see file -- --- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- --- of the license. -- ------------------------------------------------------------------------------- - -with LSP.Structures; - -package LSP.GPR_Client_Capabilities is - - type Client_Capability is tagged limited private; - -- This type holds client initialization response and provides handy - -- queries on the client capabilities - - procedure Initialize - (Self : in out Client_Capability'Class; - Value : LSP.Structures.InitializeParams); - -- Save initialize parameters - - function Resolve_Lazily (Self : Client_Capability'Class) return Boolean; - -- Returns True when resolve contains `documentation` and `details` - -private - - type Client_Capability is tagged limited record - Value : LSP.Structures.InitializeParams; - end record; - -end LSP.GPR_Client_Capabilities; diff --git a/source/gpr/lsp-gpr_did_change_document.adb b/source/gpr/lsp-gpr_did_change_document.adb index f74741e6c..7ef1d1afe 100644 --- a/source/gpr/lsp-gpr_did_change_document.adb +++ b/source/gpr/lsp-gpr_did_change_document.adb @@ -104,7 +104,9 @@ package body LSP.GPR_Did_Change_Document is -- Load gpr tree & prepare diagnostics - Self.Document.Load (Self.Parent.Context.Get_Configuration); + Self.Document.Load + (Client => Self.Parent.Context.Get_Client.all, + Configuration => Self.Parent.Context.Get_Configuration); -- Build GPR file for LSP needs. diff --git a/source/gpr/lsp-gpr_documents.adb b/source/gpr/lsp-gpr_documents.adb index eb4b6c3f4..d5458c0e1 100644 --- a/source/gpr/lsp-gpr_documents.adb +++ b/source/gpr/lsp-gpr_documents.adb @@ -150,6 +150,7 @@ package body LSP.GPR_Documents is procedure Load (Self : in out Document; + Client : LSP.Ada_Client_Capabilities.Client_Capability; Configuration : LSP.Ada_Configurations.Configuration) is procedure Update_Diagnostics; @@ -186,7 +187,7 @@ package body LSP.GPR_Documents is Context => Configuration.Context, Build_Path => Configuration.Build_Path (Self.File), File_Reader => Self.File_Provider.Get_File_Reader, - Environment => Self.Environment); + Environment => LSP.GPR_Files.Environment); Update_Diagnostics; diff --git a/source/gpr/lsp-gpr_documents.ads b/source/gpr/lsp-gpr_documents.ads index cdb7b0893..efc249856 100644 --- a/source/gpr/lsp-gpr_documents.ads +++ b/source/gpr/lsp-gpr_documents.ads @@ -25,7 +25,6 @@ with Langkit_Support.Slocs; with GNATCOLL.VFS; -with GPR2.Environment; with GPR2.Log; with GPR2.Path_Name; with GPR2.Path_Name.Set; @@ -34,6 +33,7 @@ with GPR2.Project.Typ; with GPR2.Project.Attribute; with GPR2.Project.Variable; +with LSP.Ada_Client_Capabilities; with LSP.Ada_Configurations; with LSP.Text_Documents; with LSP.GPR_Files; @@ -75,6 +75,7 @@ package LSP.GPR_Documents is procedure Load (Self : in out Document; + Client : LSP.Ada_Client_Capabilities.Client_Capability; Configuration : LSP.Ada_Configurations.Configuration); -- Load associated GPR tree. @@ -189,9 +190,6 @@ private File_Provider : LSP.GPR_Files.File_Provider_Access; -- Reader used by GPR2 to access opened documents contents - Environment : GPR2.Environment.Object; - -- Environment used by GPR2 extending ALS process environment - Messages : GPR2.Log.Object; -- Latest Tree's log diff --git a/source/gpr/lsp-gpr_files.adb b/source/gpr/lsp-gpr_files.adb index 7d3f4a951..146d9121f 100644 --- a/source/gpr/lsp-gpr_files.adb +++ b/source/gpr/lsp-gpr_files.adb @@ -21,6 +21,8 @@ with Ada.Characters.Handling; with GNATCOLL.Utils; +with LSP.Alire; + with VSS.Strings.Conversions; with VSS.Strings.Formatters.Generic_Integers; with VSS.Transformers.Casing; @@ -1295,7 +1297,8 @@ package body LSP.GPR_Files is -- Reset project kind to default value. File.Kind := GPR2.K_Standard; - File.Search_Paths.Prepend (File.Path.Containing_Directory); + File.Prepended.Append (File.Path.Containing_Directory); + File.Name := +To_String (Project_Name); Load; @@ -1669,4 +1672,43 @@ package body LSP.GPR_Files is return No_Index; end Index; + ------------------ + -- Search_Paths -- + ------------------ + + function Search_Paths (Self : File) return GPR2.Path_Name.Set.Object is + Result : GPR2.Path_Name.Set.Object; + begin + Result := GPR2.Project.Default_Search_Paths (False, Environment); + for Path of Self.Prepended loop + Result.Prepend (Path); + end loop; + return Result; + end Search_Paths; + + --------------------- + -- Set_Environment -- + --------------------- + + procedure Set_Environment + (Client : LSP.Ada_Client_Capabilities.Client_Capability) + is + begin + Env := GPR2.Environment.Process_Environment; + + if LSP.Alire.Alire_Active (Client) then + declare + Has_Alire : Boolean; + Error : VSS.Strings.Virtual_String; + begin + -- set Environment from Alire + LSP.Alire.Setup_Alire_Env + (Root => Client.Root_Directory.Display_Full_Name, + Has_Alire => Has_Alire, + Error => Error, + Environment => Env); + end; + end if; + end Set_Environment; + end LSP.GPR_Files; diff --git a/source/gpr/lsp-gpr_files.ads b/source/gpr/lsp-gpr_files.ads index 29a049aa4..91775c199 100644 --- a/source/gpr/lsp-gpr_files.ads +++ b/source/gpr/lsp-gpr_files.ads @@ -44,6 +44,7 @@ with Gpr_Parser_Support.Token_Data_Handlers; with Langkit_Support.Slocs; +with LSP.Ada_Client_Capabilities; with LSP.Text_Documents.Langkit_Documents; with VSS.Strings; @@ -183,6 +184,9 @@ package LSP.GPR_Files is (Get_Line (Self, Integer (Line_Number))); -- Get the 'Self' file line at 'Line_Number' + function Search_Paths (Self : File) return GPR2.Path_Name.Set.Object; + -- Search paths to be used to locate imported & extended projects. + ------------------------------------------------- -- GPR Parser / LSP Slocs-Position conversions -- ------------------------------------------------- @@ -271,6 +275,13 @@ package LSP.GPR_Files is function Image (Id : Type_Id) return VSS.Strings.Virtual_String; -- Type_Id/String conversions + procedure Set_Environment + (Client : LSP.Ada_Client_Capabilities.Client_Capability); + -- Set environment to be used when parsing GPR files + + function Environment return GPR2.Environment.Object; + -- The environment used when parsing project + private type Source_Position is record @@ -569,7 +580,7 @@ private Path : GPR2.Path_Name.Object; -- project path of this gpr file - Search_Paths : GPR2.Path_Name.Set.Object := + Prepended : GPR2.Path_Name.Set.Object := GPR2.Project.Default_Search_Paths (False, GPR2.Environment.Process_Environment); @@ -729,4 +740,9 @@ private (Self : LSP.GPR_Files.File) return GPR2.Path_Name.Object is (Self.Path); + Env : GPR2.Environment.Object := GPR2.Environment.Process_Environment; + -- Environment used when parsing GPR projects + + function Environment return GPR2.Environment.Object is (Env); + end LSP.GPR_Files; diff --git a/source/gpr/lsp-gpr_handlers.adb b/source/gpr/lsp-gpr_handlers.adb index a2e8b2c8f..05eb9c1b3 100644 --- a/source/gpr/lsp-gpr_handlers.adb +++ b/source/gpr/lsp-gpr_handlers.adb @@ -222,7 +222,9 @@ package body LSP.GPR_Handlers is -- Load gpr tree & prepare diagnostics begin - Object.Load (Self.Get_Configuration); + Object.Load + (Client => Self.Client, + Configuration => Self.Get_Configuration); exception when E : others => Self.Tracer.Trace_Exception (E, "On_DidOpen_Notification"); @@ -661,7 +663,7 @@ package body LSP.GPR_Handlers is for Document of Self.Open_Documents loop begin -- reload gpr tree - Document.Load (Self.Configuration); + Document.Load (Self.Client, Self.Configuration); exception when E : others => diff --git a/source/gpr/lsp-gpr_handlers.ads b/source/gpr/lsp-gpr_handlers.ads index 13762b2de..22029e51b 100644 --- a/source/gpr/lsp-gpr_handlers.ads +++ b/source/gpr/lsp-gpr_handlers.ads @@ -25,9 +25,9 @@ private with GNATCOLL.VFS; private with GPR2.File_Readers; private with GPR2.Path_Name; +with LSP.Ada_Client_Capabilities; with LSP.Ada_Configurations; with LSP.Client_Message_Receivers; -with LSP.GPR_Client_Capabilities; with LSP.GPR_Documents; with LSP.GPR_Files; with LSP.GPR_Job_Contexts; @@ -94,7 +94,8 @@ private and LSP.GPR_Files.File_Provider and LSP.GPR_Job_Contexts.GPR_Job_Context with record - Client : LSP.GPR_Client_Capabilities.Client_Capability; + Client : aliased LSP.Ada_Client_Capabilities.Client_Capability; + -- Client capabilities provided at On_Initialize_Request Open_Documents : Document_Maps.Map; -- The documents that are currently open @@ -212,6 +213,10 @@ private (Self : in out Message_Handler; Value : LSP.Ada_Configurations.Configuration); + overriding function Get_Client (Self : Message_Handler) return + access constant LSP.Ada_Client_Capabilities.Client_Capability + is (Self.Client'Unchecked_Access); + --------------------------------- -- LSP.GPR_Files.File_Provider -- --------------------------------- diff --git a/source/gpr/lsp-gpr_job_contexts.ads b/source/gpr/lsp-gpr_job_contexts.ads index b52d468be..850ca44e9 100644 --- a/source/gpr/lsp-gpr_job_contexts.ads +++ b/source/gpr/lsp-gpr_job_contexts.ads @@ -22,6 +22,7 @@ with Ada.Exceptions; with VSS.Strings; +with LSP.Ada_Client_Capabilities; with LSP.Ada_Configurations; with LSP.GPR_Documents; with LSP.GPR_Files; @@ -55,4 +56,7 @@ package LSP.GPR_Job_Contexts is (Self : in out GPR_Job_Context; Value : LSP.Ada_Configurations.Configuration) is abstract; + function Get_Client (Self : GPR_Job_Context) return + access constant LSP.Ada_Client_Capabilities.Client_Capability is abstract; + end LSP.GPR_Job_Contexts; diff --git a/testsuite/gpr_lsp/project_config.alire/.alr_printenv b/testsuite/gpr_lsp/project_config.alire/.alr_printenv new file mode 100644 index 000000000..783f19b69 --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/.alr_printenv @@ -0,0 +1,7 @@ +export ALIRE="True" +export GNAT_NATIVE_ALIRE_PREFIX="/home/max/.config/alire/cache/dependencies/gnat_native_12.2.1_11f3b811" +export GPRBUILD_ALIRE_PREFIX="/home/max/.config/alire/cache/dependencies/gprbuild_22.0.1_24dfc1b5" +export GPR_PROJECT_PATH="${DIR}:${DIR}/alire/cache/dependencies/libhello_1.0.1_3c15bc7f" +export HELLO_ALIRE_PREFIX="${DIR}" +export LIBHELLO_ALIRE_PREFIX="${DIR}/alire/cache/dependencies/libhello_1.0.1_3c15bc7f" +export PATH="${GNAT}:/usr/sbin:/usr/bin:/sbin:/bin" diff --git a/testsuite/gpr_lsp/project_config.alire/.alr_show b/testsuite/gpr_lsp/project_config.alire/.alr_show new file mode 100644 index 000000000..ca4c68b2e --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/.alr_show @@ -0,0 +1,16 @@ +hello=1.0.2: 'Hello, world!' demonstration project +Origin: path /tmp/hello_1.0.2_5715870b +Properties: + Author: Alejandro R. Mosteo + Description: 'Hello, world!' demonstration project + Executable: hello + License: MIT + Maintainer: Alejandro R. Mosteo <alejandro@mosteo.com> + Maintainers_Logins: mosteo + Name: hello + Tag: hello + Tag: demo + Version: 1.0.2 + Website: https://github.com/alire-project/hello +Dependencies (direct): + libhello^1.0 diff --git a/testsuite/gpr_lsp/project_config.alire/alire.toml b/testsuite/gpr_lsp/project_config.alire/alire.toml new file mode 100644 index 000000000..2819537d7 --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/alire.toml @@ -0,0 +1,24 @@ +authors = [ +"Alejandro R. Mosteo", +] +description = "'Hello, world!' demonstration project" +executables = [ +"hello", +] +licenses = "MIT" +maintainers = [ +"Alejandro R. Mosteo <alejandro@mosteo.com>", +] +maintainers-logins = [ +"mosteo", +] +name = "hello" +tags = [ +"hello", +"demo", +] +version = "1.0.2" +website = "https://github.com/alire-project/hello" +[[depends-on]] +libhello = "^1.0" + diff --git a/testsuite/gpr_lsp/project_config.alire/alire/alire.lock b/testsuite/gpr_lsp/project_config.alire/alire/alire.lock new file mode 100644 index 000000000..e337c17eb --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/alire/alire.lock @@ -0,0 +1,35 @@ +# THIS FILE IS GENERATED. DO NOT EDIT. + +[solution] +[solution.context] +solved = true +[[solution.state]] +crate = "libhello" +fulfilment = "solved" +pinned = false +transitivity = "direct" +versions = "^1.0" +[solution.state.release] +authors = [ +"Alejandro R. Mosteo", +] +description = "Basic library demonstration project" +licenses = "MIT" +maintainers = [ +"Alejandro R. Mosteo <alejandro@mosteo.com>", +] +maintainers-logins = [ +"mosteo", +] +name = "libhello" +tags = [ +"hello", +"demo", +"library", +] +version = "1.0.1" +website = "https://github.com/alire-project/libhello" +[solution.state.release.origin] +commit = "3c15bc7f3df22298077c9e96f178adc2829feb42" +url = "git+https://github.com/alire-project/libhello.git" + diff --git a/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/config/libhello_config.gpr b/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/config/libhello_config.gpr new file mode 100644 index 000000000..eae9fb04c --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/config/libhello_config.gpr @@ -0,0 +1,23 @@ +-- Configuration for libhello generated by Alire +abstract project Libhello_Config is + Crate_Version := "1.0.1"; + Crate_Name := "libhello"; + + Alire_Host_OS := "linux"; + + Alire_Host_Arch := "x86_64"; + + Alire_Host_Distro := "ubuntu"; + Ada_Compiler_Switches := External_As_List ("ADAFLAGS", " "); + Ada_Compiler_Switches := Ada_Compiler_Switches & + ( + "-O3" -- Optimize for performance + ,"-gnatn" -- Enable inlining + ,"-ffunction-sections" -- Separate ELF section for each function + ,"-fdata-sections" -- Separate ELF section for each variable + ); + + type Build_Profile_Kind is ("release", "validation", "development"); + Build_Profile : Build_Profile_Kind := "release"; + +end Libhello_Config; diff --git a/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/libhello.gpr b/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/libhello.gpr new file mode 100644 index 000000000..ee83f4cf2 --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/libhello.gpr @@ -0,0 +1,29 @@ +with "config/libhello_config.gpr"; +project Libhello is + + for Library_Name use "Libhello"; + for Library_Version use Project'Library_Name & ".so." & Libhello_Config.Crate_Version; + + for Source_Dirs use ("src/", "config/"); + for Object_Dir use "obj/" & Libhello_Config.Build_Profile; + for Create_Missing_Dirs use "True"; + for Library_Dir use "lib"; + + type Library_Type_Type is ("relocatable", "static", "static-pic"); + Library_Type : Library_Type_Type := + external ("LIBHELLO_LIBRARY_TYPE", external ("LIBRARY_TYPE", "static")); + for Library_Kind use Library_Type; + + package Compiler is + for Default_Switches ("Ada") use Libhello_Config.Ada_Compiler_Switches; + end Compiler; + + package Binder is + for Switches ("Ada") use ("-Es"); -- Symbolic traceback + end Binder; + + package Install is + for Artifacts (".") use ("share"); + end Install; + +end Libhello; diff --git a/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/src/libhello.adb b/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/src/libhello.adb new file mode 100644 index 000000000..75ebac2f9 --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/src/libhello.adb @@ -0,0 +1,15 @@ +with Ada.Text_IO; + +package body Libhello is + + ----------------- + -- Hello_World -- + ----------------- + + procedure Hello_World is + use Ada.Text_IO; + begin + Put_Line ("Hello, world!"); + end Hello_World; + +end Libhello; diff --git a/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/src/libhello.ads b/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/src/libhello.ads new file mode 100644 index 000000000..1637507ae --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/alire/cache/dependencies/libhello_1.0.1_3c15bc7f/src/libhello.ads @@ -0,0 +1,5 @@ +package Libhello is + + procedure Hello_World; + +end Libhello; diff --git a/testsuite/gpr_lsp/project_config.alire/alr b/testsuite/gpr_lsp/project_config.alire/alr new file mode 100755 index 000000000..1930dac7c --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/alr @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +# A dummy Alire replacement for testing purposes +while [ $# -gt 1 ] ; do shift ; done +DIR=`cd $(dirname $0); pwd` +GNAT=$(dirname `which gnat`) +sed -e "s#\${DIR}#${DIR}#g" -e "s#\${GNAT}#${GNAT}#g" ${DIR}/.alr_$1 diff --git a/testsuite/gpr_lsp/project_config.alire/config/hello_config.gpr b/testsuite/gpr_lsp/project_config.alire/config/hello_config.gpr new file mode 100644 index 000000000..043163c0f --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/config/hello_config.gpr @@ -0,0 +1,50 @@ +-- Configuration for hello generated by Alire +with "libhello.gpr"; +abstract project Hello_Config is + Crate_Version := "1.0.2"; + Crate_Name := "hello"; + + Alire_Host_OS := "linux"; + + Alire_Host_Arch := "x86_64"; + + Alire_Host_Distro := "ubuntu"; + Ada_Compiler_Switches := External_As_List ("ADAFLAGS", " "); + Ada_Compiler_Switches := Ada_Compiler_Switches & + ( + "-Og" -- Optimize for debug + ,"-ffunction-sections" -- Separate ELF section for each function + ,"-fdata-sections" -- Separate ELF section for each variable + ,"-g" -- Generate debug info + ,"-gnatwa" -- Enable all warnings + ,"-gnatw.X" -- Disable warnings for No_Exception_Propagation + ,"-gnatVa" -- All validity checks + ,"-gnaty3" -- Specify indentation level of 3 + ,"-gnatya" -- Check attribute casing + ,"-gnatyA" -- Use of array index numbers in array attributes + ,"-gnatyB" -- Check Boolean operators + ,"-gnatyb" -- Blanks not allowed at statement end + ,"-gnatyc" -- Check comments + ,"-gnaty-d" -- Disable check no DOS line terminators present + ,"-gnatye" -- Check end/exit labels + ,"-gnatyf" -- No form feeds or vertical tabs + ,"-gnatyh" -- No horizontal tabs + ,"-gnatyi" -- Check if-then layout + ,"-gnatyI" -- check mode IN keywords + ,"-gnatyk" -- Check keyword casing + ,"-gnatyl" -- Check layout + ,"-gnatym" -- Check maximum line length + ,"-gnatyn" -- Check casing of entities in Standard + ,"-gnatyO" -- Check that overriding subprograms are explicitly marked as such + ,"-gnatyp" -- Check pragma casing + ,"-gnatyr" -- Check identifier references casing + ,"-gnatyS" -- Check no statements after THEN/ELSE + ,"-gnatyt" -- Check token spacing + ,"-gnatyu" -- Check unnecessary blank lines + ,"-gnatyx" -- Check extra parentheses + ); + + type Build_Profile_Kind is ("release", "validation", "development"); + Build_Profile : Build_Profile_Kind := "development"; + +end Hello_Config; diff --git a/testsuite/gpr_lsp/project_config.alire/hello.gpr b/testsuite/gpr_lsp/project_config.alire/hello.gpr new file mode 100644 index 000000000..3ff5dae46 --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/hello.gpr @@ -0,0 +1 @@ +with "config/hello_config.gpr";project Hello is end Hello; diff --git a/testsuite/gpr_lsp/project_config.alire/src/hello.adb b/testsuite/gpr_lsp/project_config.alire/src/hello.adb new file mode 100644 index 000000000..6236aa7e1 --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/src/hello.adb @@ -0,0 +1,7 @@ +with Libhello; + +procedure Hello is + +begin + Libhello.Hello_World; +end Hello; diff --git a/testsuite/gpr_lsp/project_config.alire/test.json b/testsuite/gpr_lsp/project_config.alire/test.json new file mode 100644 index 000000000..b481abb7c --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/test.json @@ -0,0 +1,185 @@ +[ + { + "comment": [ + "This test check language server is able to handle a project file", + "using alr and alire.toml." + ] + }, + { + "prepend_to_env": { + "PATH": "${DIR}" + } + }, + { + "start": { + "cmd": [ + "${ALS}", + "--language-gpr" + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 0, + "method": "initialize", + "params": { + "processId": 1, + "rootUri": "$URI{.}", + "capabilities": {} + } + }, + "wait": [ + { + "id": 0, + "result": { + "capabilities": { + "textDocumentSync": { + "openClose": true, + "change": 1 + }, + "completionProvider": { + "triggerCharacters": [ + " " + ], + "resolveProvider": true + }, + "hoverProvider": true, + "declarationProvider": true, + "definitionProvider": true, + "documentSymbolProvider": {} + } + } + } + ] + } + }, + { + "send": { + "request": { + "params": { + "textDocument": { + "text": "with \"config/hello_config.gpr\";project Hello is end Hello;", + "version": 0, + "uri": "$URI{hello.gpr}", + "languageId": "Gpr" + } + }, + "jsonrpc": "2.0", + "method": "textDocument/didOpen" + }, + "wait": [{ + "method": "textDocument/publishDiagnostics", + "params": { + "uri": "$URI{hello.gpr}", + "diagnostics": [ + ] + } + }] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": "defname-1", + "method": "textDocument/definition", + "params": { + "textDocument": { + "uri": "$URI{hello.gpr}" + }, + "position": { + "line": 0, + "character": 20 + } + } + }, + "wait": [ + { + "jsonrpc": "2.0", + "id": "defname-1", + "result": { + "uri": "$URI{config/hello_config.gpr}", + "range": { + "start": { + "line": 2, + "character": 17 + }, + "end": { + "line": 2, + "character": 29 + } + } + } + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": "defname-2", + "method": "textDocument/definition", + "params": { + "textDocument": { + "uri": "$URI{config/hello_config.gpr}" + }, + "position": { + "line": 1, + "character": 10 + } + } + }, + "wait": [ + { + "id": "defname-2", + "result": { + "uri": "$URI{alire/cache/dependencies/libhello_1.0.1_3c15bc7f/libhello.gpr}", + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 16 + } + } + } + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": "shutdown", + "method": "shutdown", + "params": null + }, + "wait": [ + { + "id": "shutdown", + "result": null + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "method": "exit" + }, + "wait": [] + } + }, + { + "stop": { + "exit_code": 0 + } + } +] \ No newline at end of file diff --git a/testsuite/gpr_lsp/project_config.alire/test.yaml b/testsuite/gpr_lsp/project_config.alire/test.yaml new file mode 100644 index 000000000..ee5a7106f --- /dev/null +++ b/testsuite/gpr_lsp/project_config.alire/test.yaml @@ -0,0 +1,3 @@ +title: 'project_config.alire' +skip: + - ['SKIP', 'env.build.os.name == "windows"']