Skip to content

Commit

Permalink
Merge branch 'topic/merge_fix' into 'edge'
Browse files Browse the repository at this point in the history
Rewrite project status data

See merge request eng/ide/ada_language_server!1657
  • Loading branch information
reznikmm committed Aug 13, 2024
2 parents 7bdced7 + 107f564 commit 679968f
Show file tree
Hide file tree
Showing 24 changed files with 1,058 additions and 495 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,24 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get GNAT toolchain with alire (AArch64)
if: ${{ matrix.os == 'macos-14' }}
- name: Get GNAT toolchain with alire
shell: bash
run: |
# alire-project/setup-alire doesn't work for ARM64 Mac OS X for now.
# https://github.com/alire-project/setup-alire/pull/74
curl -L -O https://github.com/alire-project/alire/releases/download/nightly/alr-nightly-bin-aarch64-macos.zip
unzip alr-nightly-bin-aarch64-macos.zip
# Also it depends on `engineerd/configurator@v0.0.10` not approved by IT.
# https://github.com/alire-project/setup-alire/issues/75
# So we fetch Alire with curl then toolchain with Alire.
if [[ "$RUNNER_ARCH" == ARM64 ]] ; then
ZIP=nightly/alr-nightly-bin-aarch64-macos.zip
else
ZIP=v2.0.1/alr-2.0.1-bin-x86_64-${RUNNER_OS}.zip
fi
curl -L -O https://github.com/alire-project/alire/releases/download/$ZIP
unzip $(basename $ZIP)
bin/alr index --reset-community
bin/alr toolchain --select gnat_native^14 gprbuild
echo $PWD/bin >> $GITHUB_PATH
- name: Get GNAT toolchain with alire (x86_64)
if: ${{ matrix.os != 'macos-14' }}
uses: alire-project/setup-alire@v3
with:
toolchain: gnat_native^14 gprbuild
- name: Build
shell: bash
run: |
Expand Down
1 change: 1 addition & 0 deletions alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ libgpr2 = "^24.0.0"
vss = "^24.0.0"
libadalang_tools = "^24.0.0"
lal_refactor = "25.0.0-20240625"
gnatformat = "25.0.0-20240625"
gnatdoc = "^24.0.0"
spawn = "^24.0.0"

1 change: 1 addition & 0 deletions gnat/lsp_server.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ project LSP_Server is

for Object_Dir use "../.obj/server";
for Main use ("lsp-ada_driver.adb");
-- Need C++ to use a linker compatible with libfswatch
for Languages use ("Ada", "C++");

package Naming is
Expand Down
29 changes: 29 additions & 0 deletions index/gn/gnatformat/gnatformat-25.0.0-20240625.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name = "gnatformat"
description = "An opinionated code formatter for the Ada language."
version = "25.0.0-20240625"

authors = ["AdaCore"]
maintainers = ["João Azevedo <azevedo@adacore.com>"]
maintainers-logins = ["joaopsazevedo"]
licenses = "Apache-2.0 WITH LLVM-exception"
website = "https://github.com/AdaCore/gnatformat"

project-files = ["gnat/gnatformat.gpr"]

[environment.'case(os)'.macos.DYLD_LIBRARY_PATH]
append = "${CRATE_ROOT}/.libs/relocatable"

[environment.'case(os)'.windows.PATH]
append = "${CRATE_ROOT}/.libs/relocatable"

[configuration]
disabled = true

[[depends-on]]
libadalang = "^24"
prettier_ada = "25.0.0-20240625"

[origin]
url = "git+https://github.com/AdaCore/gnatformat"
commit = "b418fcc894877777ecf4102410ba4eeee279e219"

4 changes: 3 additions & 1 deletion scripts/build_als.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PINS="
adasat
gnatcoll
gnatdoc
gnatformat
lal_refactor
langkit_support
libadalang
Expand Down Expand Up @@ -45,6 +46,7 @@ repo_vss=VSS

branch_gnatdoc=edge
branch_lal_refactor=edge
branch_gnatformat=edge
branch_libgpr2=next
branch_prettier_ada=main

Expand All @@ -53,7 +55,7 @@ SETENV=$PWD/subprojects/libadalang/setenv.sh

# Set `prod` build mode
########################
# for adasat,lal,langkit,lal_refactor,laltools,markdown,spawn
# for adasat,gnatformat,lal,langkit,lal_refactor,laltools,markdown,spawn
export BUILD_MODE=prod
# for others
export GNATCOLL_BUILD_MODE=PROD
Expand Down
2 changes: 1 addition & 1 deletion source/ada/lsp-ada_configurations.adb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ package body LSP.Ada_Configurations is
Self.Context.Clear;
for J in 1 .. Variables_Names.Length loop
Self.Context.Insert
(GPR2.Optional_Name_Type
(GPR2.External_Name_Type
(VSS.Strings.Conversions.To_UTF_8_String
(Variables_Names (J))),
VSS.Strings.Conversions.To_UTF_8_String
Expand Down
178 changes: 8 additions & 170 deletions source/ada/lsp-ada_handlers-project_diagnostics.adb
Original file line number Diff line number Diff line change
Expand Up @@ -15,188 +15,26 @@
-- of the license. --
------------------------------------------------------------------------------

with GPR2.Source_Reference;
with GPR2.Message;
with GPR2.Path_Name;

with VSS.Strings;

with LSP.Enumerations;
with LSP.Utils;

package body LSP.Ada_Handlers.Project_Diagnostics is

Project_Loading_Status_Messages : constant array (Load_Project_Status)
of VSS.Strings.Virtual_String :=
(Single_Project_Found =>
VSS.Strings.To_Virtual_String
("Unique project in root directory was found and "
& "loaded, but it wasn't explicitly configured."),
No_Runtime_Found =>
VSS.Strings.To_Virtual_String
("The project was loaded, but no Ada runtime found. "
& "Please check the installation of the Ada compiler."),
No_Project_Found =>
VSS.Strings.To_Virtual_String
("No project found in root directory. "
& "Please create a project file and add it to the "
& "configuration."),
Multiple_Projects_Found =>
VSS.Strings.To_Virtual_String
("No project was loaded, because more than one "
& "project file has been found in the root directory. "
& "Please change configuration to point a correct project "
& "file."),
Invalid_Project_Configured =>
VSS.Strings.To_Virtual_String
("Project file has errors and can't be loaded."),
others => VSS.Strings.Empty_Virtual_String);
-- The diagnostics' messages depending on the project loading status.

Project_Loading_Status_Severities : constant array (Load_Project_Status)
of LSP.Enumerations.DiagnosticSeverity :=
(Valid_Project_Configured => LSP.Enumerations.Hint,
Alire_Project => LSP.Enumerations.Hint,
Single_Project_Found => LSP.Enumerations.Hint,
No_Runtime_Found => LSP.Enumerations.Warning,
Multiple_Projects_Found => LSP.Enumerations.Error,
No_Project_Found => LSP.Enumerations.Error,
Invalid_Project_Configured => LSP.Enumerations.Error);
-- The diagnostics' severities depending on the project loading status.

--------------------
-- Get_Diagnostic --
--------------------

overriding procedure Get_Diagnostic
(Self : in out Diagnostic_Source;
Context : LSP.Ada_Contexts.Context;
Errors : out LSP.Structures.Diagnostic_Vector)
is
use LSP.Structures;

Parent_Diagnostic : LSP.Structures.Diagnostic;
GPR2_Messages : GPR2.Log.Object renames
Self.Handler.Project_Status.GPR2_Messages;

procedure Create_Project_Loading_Diagnostic;
-- Create a parent diagnostic for the project loading status.

procedure Append_GPR2_Diagnostics;
-- Append the GPR2 messages to the given parent diagnostic, if any.

---------------------------------------
-- Create_Project_Loading_Diagnostic --
---------------------------------------

procedure Create_Project_Loading_Diagnostic is
Sloc : constant LSP.Structures.A_Range :=
(start => (0, 0),
an_end => (0, 0));
begin
-- Initialize the parent diagnostic.
Parent_Diagnostic.a_range := ((0, 0), (0, 0));
Parent_Diagnostic.source := "project";
Parent_Diagnostic.severity :=
(True, Project_Loading_Status_Severities (Self.Last_Status));

-- If we don't have any GPR2 messages, display the project loading
-- status message in the parent diagnostic directly.
-- Otherwise display a generic message in the parent amnd append it
-- to its children, along with the other GPR2 messages.
if GPR2_Messages.Is_Empty then
Parent_Diagnostic.message := Project_Loading_Status_Messages
(Self.Last_Status);
else
declare
Project_File : GNATCOLL.VFS.Virtual_File renames
Self.Handler.Project_Status.Project_File;
URI : constant LSP.Structures.DocumentUri :=
Self.Handler.To_URI
(Project_File.Display_Full_Name);
begin
Parent_Diagnostic.message := "Project Problems";
Parent_Diagnostic.relatedInformation.Append
(LSP.Structures.DiagnosticRelatedInformation'
(location =>
LSP.Structures.Location'
(uri => URI, a_range => Sloc,
others => <>),
message =>
Project_Loading_Status_Messages
(Self.Last_Status)));
end;
end if;
end Create_Project_Loading_Diagnostic;

-----------------------------
-- Append_GPR2_Diagnostics --
-----------------------------

procedure Append_GPR2_Diagnostics is
use GPR2.Message;
use LSP.Enumerations;
begin
for Msg of GPR2_Messages loop
if Msg.Level in GPR2.Message.Warning .. GPR2.Message.Error then
declare
Sloc : constant GPR2.Source_Reference.Object :=
GPR2.Message.Sloc (Msg);
File : constant GPR2.Path_Name.Object :=
(if Sloc.Is_Defined and then Sloc.Has_Source_Reference
then
GPR2.Path_Name.Create_File
(GPR2.Filename_Type (Sloc.Filename))
else
Self.Handler.Project_Tree.Root_Project.Path_Name);
begin
-- Display a diagnostic for GPR2 messages only if the file
-- attached to the message is defined.
if File.Is_Defined and then File.Has_Value then
Parent_Diagnostic.relatedInformation.Append
(LSP .Structures.DiagnosticRelatedInformation'
(location => LSP.Structures.Location'
(uri => LSP.Utils.To_URI (File),
a_range => LSP.Utils.To_Range (Sloc),
others => <>),
message =>
VSS.Strings.Conversions.To_Virtual_String
(Msg.Message)));
end if;
end;

-- If we have one error in the GPR2 messages, the parent
-- diagnostic's severity should be "error" too, otherwise
-- "warning".
if Msg.Level = GPR2.Message.Error then
Parent_Diagnostic.severity :=
(True, LSP.Enumerations.Error);
elsif Parent_Diagnostic.severity.Value /=
LSP.Enumerations.Error
then
Parent_Diagnostic.severity :=
(True, LSP.Enumerations.Warning);
end if;
end if;
end loop;
end Append_GPR2_Diagnostics;

Errors : out LSP.Structures.Diagnostic_Vector) is
begin
Self.Last_Status := Self.Handler.Project_Status.Load_Status;
Self.Last_Status := Self.Handler.Project_Status;

Self.Handler.Tracer.Trace ("Diag: " & Self.Last_Status'Image);
-- If we have a valid project return immediately: we want to display
-- diagnostics only if there is an issue to solve or a potential
-- enhancement.
if Self.Last_Status = Valid_Project_Configured
or else (Self.Last_Status = Alire_Project and then GPR2_Messages.Is_Empty)
then
return;
end if;

Create_Project_Loading_Diagnostic;
Append_GPR2_Diagnostics;

Errors.Append (Parent_Diagnostic);
Errors.Append_Vector
(LSP.Ada_Project_Loading.Get_Diagnostics (Self.Last_Status));
end Get_Diagnostic;

------------------------
Expand All @@ -210,9 +48,9 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
is
pragma Unreferenced (Context);
begin
return
(Self.Last_Status /= Self.Handler.Project_Status.Load_Status
or else not Self.Handler.Project_Status.GPR2_Messages.Is_Empty);
return LSP.Ada_Project_Loading.Has_New_Diagnostics
(Self.Last_Status,
Self.Handler.Project_Status);
end Has_New_Diagnostic;

end LSP.Ada_Handlers.Project_Diagnostics;
3 changes: 2 additions & 1 deletion source/ada/lsp-ada_handlers-project_diagnostics.ads
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
------------------------------------------------------------------------------

with LSP.Ada_Contexts;
with LSP.Ada_Project_Loading;
with LSP.Diagnostic_Sources;

package LSP.Ada_Handlers.Project_Diagnostics is
Expand All @@ -39,7 +40,7 @@ private
type Diagnostic_Source
(Handler : not null access LSP.Ada_Handlers.Message_Handler)
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with record
Last_Status : Load_Project_Status := No_Project_Found;
Last_Status : LSP.Ada_Project_Loading.Project_Status_Type;
end record;

end LSP.Ada_Handlers.Project_Diagnostics;
Loading

0 comments on commit 679968f

Please sign in to comment.