Skip to content

Commit 52569e7

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 580556b + 9d03f61 commit 52569e7

15 files changed

+758
-7
lines changed

.gitlab-ci.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,34 @@ stages:
99
# Build and test with ANOD
1010
# TODO: add a build and test based on Alire in parallel to this.
1111
build_and_test:
12+
rules:
13+
# Let's do the job only for merge request events: that's
14+
# when we know whether the target branch is 'edge'.
15+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
1216
services:
1317
- image:sandbox
1418
- cpu:8
1519
- mem:16
1620
stage: build_and_test
21+
interruptible: true
1722
script:
1823
- . ~/.aws_container_credentials
1924
- export PATH=/it/e3/bin:$PATH
2025

26+
# Check whether we're in an MR targeting 'edge' and setup some
27+
# variables if so.
28+
- TARGET_BRANCH="master"
29+
- if [ "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" = "edge" ]; then
30+
echo "Targeting the edge branch." ;
31+
REPO_SUFFIX="-edge" ;
32+
BUILD_SPACE_SUFFIX="_edge" ;
33+
QUALIFIER="edge" ;
34+
TARGET_BRANCH="edge" ;
35+
fi
36+
2137
# Setup the 'anod vcs' for this repo
2238
- cd /it/wave
23-
- anod vcs --add-repo ada_language_server $CI_PROJECT_DIR
39+
- anod vcs --add-repo ada_language_server${REPO_SUFFIX} $CI_PROJECT_DIR
2440

2541
# Figure out if we're on a sync branch
2642
- BRANCH=master
@@ -32,29 +48,32 @@ build_and_test:
3248

3349
# Setup the 'anod vcs' for the other repos, if we're on
3450
# a "sync" branch.
35-
- if [ $BRANCH != master ]; then
36-
for subproject in vss spawn gnatdoc ; do
51+
- for subproject in vss spawn gnatdoc ; do
52+
echo "for subproject $subproject ..." ;
3753
cd /tmp ;
3854
git clone $GIT_CLONE_BASE/eng/ide/$subproject ;
3955
cd $subproject ;
4056
if `git show-ref $BRANCH > /dev/null` ; then
57+
echo "... checking out $BRANCH"
4158
git checkout $BRANCH ;
4259
cd /it/wave ;
4360
anod vcs --add-repo $subproject /tmp/$subproject ;
61+
else
62+
echo "... checking out $TARGET_BRANCH"
63+
git checkout $TARGET_BRANCH ;
4464
fi ;
4565
done ;
46-
fi
4766

4867
# Build & test using anod
4968
- cd /it/wave
50-
- anod build als --minimal
51-
- anod test als --minimal
69+
- anod build als --qualifier=$QUALIFIER --minimal
70+
- anod test als --qualifier=$QUALIFIER --minimal
5271

5372
# Process the report
5473
- e3-testsuite-report
5574
--failure-exit-code 1
5675
--xunit-output $CI_PROJECT_DIR/xunit_output.xml
57-
x86_64-linux/als-test/results/new/ || FAILED=true
76+
x86_64-linux/als${BUILD_SPACE_SUFFIX}-test/results/new/ || FAILED=true
5877

5978
- if [ ! -z ${FAILED+x} ]; then echo "There was at least one testcase failure" && exit 1; fi
6079

source/ada/lsp-ada_driver.adb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ with LSP.Ada_Handlers.Refactor_Extract_Subprogram;
5353
with LSP.Ada_Handlers.Refactor_Introduce_Parameter;
5454
with LSP.Ada_Handlers.Refactor_Pull_Up_Declaration;
5555
with LSP.Ada_Handlers.Refactor_Replace_Type;
56+
with LSP.Ada_Handlers.Refactor_Sort_Dependencies;
5657
with LSP.Commands;
5758
with LSP.Error_Decorators;
5859
with LSP.Fuzz_Decorators;
@@ -150,6 +151,8 @@ procedure LSP.Ada_Driver is
150151
(LSP.Ada_Handlers.Refactor_Pull_Up_Declaration.Command'Tag);
151152
LSP.Commands.Register
152153
(LSP.Ada_Handlers.Refactor_Replace_Type.Command'Tag);
154+
LSP.Commands.Register
155+
(LSP.Ada_Handlers.Refactor_Sort_Dependencies.Command'Tag);
153156

154157
-- Refactoring - Change Subprogram Signature Commands
155158
LSP.Commands.Register
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2023, 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 Langkit_Support.Slocs;
21+
22+
with Libadalang.Analysis;
23+
24+
with Laltools.Refactor.Sort_Dependencies;
25+
26+
with LSP.Common;
27+
with LSP.Messages.Client_Requests;
28+
with LSP.Lal_Utils;
29+
30+
with VSS.Strings.Conversions;
31+
32+
package body LSP.Ada_Handlers.Refactor_Sort_Dependencies is
33+
34+
------------------------
35+
-- Append_Code_Action --
36+
------------------------
37+
38+
procedure Append_Code_Action
39+
(Self : in out Command;
40+
Context : Context_Access;
41+
Commands_Vector : in out LSP.Messages.CodeAction_Vector;
42+
Where : LSP.Messages.Location)
43+
is
44+
Pointer : LSP.Commands.Command_Pointer;
45+
Code_Action : LSP.Messages.CodeAction;
46+
47+
begin
48+
Self.Initialize
49+
(Context => Context.all,
50+
Where => Where);
51+
52+
Pointer.Set (Self);
53+
54+
Code_Action :=
55+
(title => "Sort Dependencies",
56+
kind =>
57+
(Is_Set => True,
58+
Value => LSP.Messages.Refactor),
59+
diagnostics => (Is_Set => False),
60+
edit => (Is_Set => False),
61+
isPreferred => (Is_Set => False),
62+
disabled => (Is_Set => False),
63+
command =>
64+
(Is_Set => True,
65+
Value =>
66+
(Is_Unknown => False,
67+
title => <>,
68+
Custom => Pointer)));
69+
70+
Commands_Vector.Append (Code_Action);
71+
end Append_Code_Action;
72+
73+
------------
74+
-- Create --
75+
------------
76+
77+
overriding
78+
function Create
79+
(JS : not null access LSP.JSON_Streams.JSON_Stream'Class)
80+
return Command
81+
is
82+
use Ada.Strings.UTF_Encoding;
83+
use LSP.Messages;
84+
use LSP.Types;
85+
use VSS.Strings.Conversions;
86+
87+
begin
88+
return C : Command do
89+
pragma Assert (JS.R.Is_Start_Object);
90+
91+
JS.R.Read_Next;
92+
93+
while not JS.R.Is_End_Object loop
94+
pragma Assert (JS.R.Is_Key_Name);
95+
96+
declare
97+
Key : constant UTF_8_String := To_UTF_8_String (JS.R.Key_Name);
98+
99+
begin
100+
JS.R.Read_Next;
101+
102+
if Key = "context" then
103+
Read_String (JS, C.Context);
104+
105+
elsif Key = "where" then
106+
Location'Read (JS, C.Where);
107+
108+
else
109+
JS.Skip_Value;
110+
end if;
111+
end;
112+
end loop;
113+
114+
JS.R.Read_Next;
115+
end return;
116+
end Create;
117+
118+
-------------
119+
-- Execute --
120+
-------------
121+
122+
overriding
123+
procedure Execute
124+
(Self : Command;
125+
Handler : not null access LSP.Server_Notification_Receivers.
126+
Server_Notification_Receiver'Class;
127+
Client : not null access LSP.Client_Message_Receivers.
128+
Client_Message_Receiver'Class;
129+
Error : in out LSP.Errors.Optional_ResponseError)
130+
is
131+
use Langkit_Support.Slocs;
132+
use Libadalang.Analysis;
133+
use Laltools.Refactor;
134+
use Laltools.Refactor.Sort_Dependencies;
135+
use LSP.Messages;
136+
use LSP.Types;
137+
use VSS.Strings.Conversions;
138+
139+
Message_Handler : LSP.Ada_Handlers.Message_Handler renames
140+
LSP.Ada_Handlers.Message_Handler (Handler.all);
141+
Context : LSP.Ada_Contexts.Context renames
142+
Message_Handler.Contexts.Get (Self.Context).all;
143+
144+
Apply : Client_Requests.Workspace_Apply_Edit_Request;
145+
Workspace_Edits : WorkspaceEdit renames Apply.params.edit;
146+
Label : Optional_Virtual_String renames Apply.params.label;
147+
148+
Analysis_Unit : constant Libadalang.Analysis.Analysis_Unit :=
149+
Context.LAL_Context.Get_From_File
150+
(Context.URI_To_File (Self.Where.uri));
151+
Sloc : constant Source_Location :=
152+
(Langkit_Support.Slocs.Line_Number (Self.Where.span.first.line) + 1,
153+
Langkit_Support.Slocs.Column_Number (Self.Where.span.first.character)
154+
+ 1);
155+
Compilation_Unit : constant Libadalang.Analysis.Compilation_Unit :=
156+
Analysis_Unit.Root.Lookup (Sloc).P_Enclosing_Compilation_Unit;
157+
158+
Sorter : constant Dependencies_Sorter :=
159+
Create_Dependencies_Sorter (Compilation_Unit);
160+
Edits : constant Refactoring_Edits := Sorter.Refactor (null);
161+
162+
begin
163+
if Edits = No_Refactoring_Edits then
164+
Error :=
165+
(Is_Set => True,
166+
Value =>
167+
(code => LSP.Errors.UnknownErrorCode,
168+
message => VSS.Strings.Conversions.To_Virtual_String
169+
("Failed to execute the Sort Dependencies refactoring"),
170+
data => <>));
171+
172+
else
173+
Workspace_Edits :=
174+
LSP.Lal_Utils.To_Workspace_Edit
175+
(Edits => Edits,
176+
Resource_Operations => Message_Handler.Resource_Operations,
177+
Versioned_Documents => Message_Handler.Versioned_Documents,
178+
Document_Provider => Message_Handler'Access);
179+
Label :=
180+
(Is_Set => True,
181+
Value => To_Virtual_String (Command'External_Tag));
182+
183+
Client.On_Workspace_Apply_Edit_Request (Apply);
184+
end if;
185+
186+
exception
187+
when E : others =>
188+
LSP.Common.Log (Message_Handler.Trace, E);
189+
Error :=
190+
(Is_Set => True,
191+
Value =>
192+
(code => LSP.Errors.UnknownErrorCode,
193+
message => VSS.Strings.Conversions.To_Virtual_String
194+
("Failed to execute the Sort Dependencies refactoring"),
195+
data => <>));
196+
end Execute;
197+
198+
----------------
199+
-- Initialize --
200+
----------------
201+
202+
procedure Initialize
203+
(Self : in out Command'Class;
204+
Context : LSP.Ada_Contexts.Context;
205+
Where : LSP.Messages.Location) is
206+
begin
207+
Self.Context := Context.Id;
208+
Self.Where := Where;
209+
end Initialize;
210+
211+
-------------------
212+
-- Write_Command --
213+
-------------------
214+
215+
procedure Write_Command
216+
(S : access Ada.Streams.Root_Stream_Type'Class;
217+
C : Command)
218+
is
219+
use LSP.Messages;
220+
use LSP.Types;
221+
222+
JS : LSP.JSON_Streams.JSON_Stream'Class renames
223+
LSP.JSON_Streams.JSON_Stream'Class (S.all);
224+
225+
begin
226+
JS.Start_Object;
227+
JS.Key ("context");
228+
Write_String (S, C.Context);
229+
JS.Key ("where");
230+
Location'Write (S, C.Where);
231+
JS.End_Object;
232+
end Write_Command;
233+
234+
end LSP.Ada_Handlers.Refactor_Sort_Dependencies;

0 commit comments

Comments
 (0)