Skip to content

Commit 165a085

Browse files
committed
Merge branch 'topic/on_error' into 'master'
Add `--on-hang-script` option to `tester-run` See merge request eng/ide/ada_language_server!1120
2 parents 9d03f61 + 5ce5e86 commit 165a085

File tree

7 files changed

+298
-191
lines changed

7 files changed

+298
-191
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Current features:
1515
* [GNAT project files](https://docs.adacore.com/gprbuild-docs/html/gprbuild_ug/gnat_project_manager.html) support.
1616
* Code completion for names, keywords, aggregates, etc.
1717
* Code navigation, such as Go to Definition/Declaration, Find All References, Call Hierarchies, etc.
18-
* Code refactoring like insert named associations, auto-add `with`-clauses.
18+
* [Code refactoring](#refactoring-tools) like insert named associations, auto-add `with`-clauses, etc.
1919
* Document/Workspace symbol search.
2020
* Code folding and formatting.
2121

@@ -97,7 +97,8 @@ You can turn some debugging and experimental features trought
9797
[the traces file](doc/traces.md).
9898

9999
The server also gets configuration via `workspace/didChangeConfiguration`
100-
notification. See more [details here](doc/settings.md). Each LSP
100+
notification and `initializationOptions` of `initialize` request.
101+
See more [details here](doc/settings.md). Each LSP
101102
client provides its-own way to set such settings.
102103

103104
## Supported LSP Server Requests

source/client/lsp-raw_clients.adb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2021, AdaCore --
4+
-- Copyright (C) 2018-2023, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -133,6 +133,15 @@ package body LSP.Raw_Clients is
133133
end if;
134134
end Send_Message;
135135

136+
----------------
137+
-- Server_PID --
138+
----------------
139+
140+
function Server_PID (Self : Raw_Client'Class) return String is
141+
begin
142+
return Self.Server.Identifier;
143+
end Server_PID;
144+
136145
-------------------
137146
-- Set_Arguments --
138147
-------------------

source/client/lsp-raw_clients.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ package LSP.Raw_Clients is
114114
-- Return True when server's process is running and send queue is empty,
115115
-- thus send operation can start immidiately.
116116

117+
function Server_PID (Self : Raw_Client'Class) return String;
118+
-- Return server process id (pid) if the server has been started.
119+
117120
private
118121
type Listener (Client : access Raw_Client'Class) is limited
119122
new Spawn.Processes.Process_Listener with null record;

source/tester/tester-run.adb

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2019, AdaCore --
4+
-- Copyright (C) 2018-2023, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -21,35 +21,72 @@ with Ada.Strings.Unbounded;
2121
with Ada.Text_IO;
2222
with GNATCOLL.JSON;
2323

24-
with Tester.Macros;
25-
with Tester.Tests;
24+
with VSS.Command_Line;
25+
with VSS.Strings;
26+
with VSS.Strings.Conversions;
27+
with VSS.String_Vectors;
2628

2729
with Spawn.Environments;
2830

31+
with Tester.Macros;
32+
with Tester.Tests;
33+
2934
procedure Tester.Run is
35+
36+
package Options is
37+
-- Command line options and arguments
38+
39+
Debug : constant VSS.Command_Line.Binary_Option :=
40+
(Short_Name => "d",
41+
Long_Name => "debug",
42+
Description => "disable timeouts then pause after server start");
43+
44+
On_Hang : constant VSS.Command_Line.Value_Option :=
45+
(Short_Name => "",
46+
Long_Name => "on-hang-script",
47+
Value_Name => "command_and_args",
48+
Description => "the command to launch if the test hangs");
49+
50+
File : constant VSS.Command_Line.Positional_Option :=
51+
(Name => "test.json",
52+
Description => "JSON test script");
53+
end Options;
54+
3055
Env : constant Spawn.Environments.Process_Environment :=
3156
Spawn.Environments.System_Environment;
3257

3358
JSON : GNATCOLL.JSON.JSON_Value;
3459
begin
35-
if not (Ada.Command_Line.Argument_Count = 1
36-
or else (Ada.Command_Line.Argument_Count = 2
37-
and then Ada.Command_Line.Argument (1) = "--debug"))
38-
then
39-
Ada.Text_IO.Put_Line ("Usage:");
40-
Ada.Text_IO.Put_Line
41-
(" " & Ada.Command_Line.Command_Name & " [options] test.json");
42-
Ada.Text_IO.New_Line;
43-
Ada.Text_IO.Put_Line ("Options are:");
44-
Ada.Text_IO.Put_Line
45-
(" --debug disable timeouts and pause after server start");
46-
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
47-
return;
60+
VSS.Command_Line.Add_Option (Options.Debug);
61+
VSS.Command_Line.Add_Option (Options.On_Hang);
62+
VSS.Command_Line.Add_Option (Options.File);
63+
VSS.Command_Line.Process; -- This terminates process on option's error
64+
65+
if not Options.File.Is_Specified then
66+
declare
67+
use type VSS.Strings.Virtual_String;
68+
Usage : VSS.String_Vectors.Virtual_String_Vector;
69+
begin
70+
Usage.Append ("Usage:");
71+
Usage.Append
72+
(" tester-run [options] " & Options.File.Name);
73+
Usage.Append ("");
74+
Usage.Append ("Options are:");
75+
Usage.Append
76+
(" --" & Options.Debug.Long_Name
77+
& " (-" & Options.Debug.Short_Name & ")"
78+
& " " & Options.Debug.Description);
79+
Usage.Append
80+
(" --" & Options.On_Hang.Long_Name
81+
& "=" & Options.On_Hang.Value_Name
82+
& " " & Options.On_Hang.Description);
83+
VSS.Command_Line.Report_Error (Usage.Join_Lines (VSS.Strings.LF));
84+
end;
4885
end if;
4986

5087
declare
51-
File : constant String := Ada.Command_Line.Argument
52-
(Ada.Command_Line.Argument_Count);
88+
File : constant String := VSS.Strings.Conversions.To_UTF_8_String
89+
(Options.File.Value);
5390
Input : Ada.Text_IO.File_Type;
5491
Text : Ada.Strings.Unbounded.Unbounded_String;
5592
begin
@@ -73,7 +110,10 @@ begin
73110
declare
74111
Test : Tester.Tests.Test;
75112
begin
76-
Test.Run (JSON.Get, Debug => Ada.Command_Line.Argument_Count = 2);
113+
Test.Run
114+
(JSON.Get,
115+
On_Hang => Options.On_Hang.Value,
116+
Debug => Options.Debug.Is_Specified);
77117
end;
78118
end;
79119
end Tester.Run;

0 commit comments

Comments
 (0)