Skip to content

Commit da211da

Browse files
committed
VB25-013 Add command to reload project
1 parent a06806a commit da211da

File tree

7 files changed

+324
-115
lines changed

7 files changed

+324
-115
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension at
4141
- [Getting started](#getting-started)
4242
- [Auto-detected tasks](#auto-detected-tasks)
4343
- [Short demo](#short-demo)
44-
- [Go to other Ada file](#go-to-other-ada-file)
44+
- [Commands and shortcuts](#commands-and-shortcuts)
4545
- [Launch the extension to debug it](#launch-the-extension-to-debug-it)
4646
- [Configuration](#configuration)
4747
- [Integration with Coc.NVim](#integration-with-cocnvim)
@@ -170,12 +170,25 @@ You can bind keyboard shortcuts to them by adding to the `keybindings.json` file
170170

171171
[A demo for auto-detected tasks](https://github.com/AdaCore/ada_language_server/wiki/auto_detected_tasks.mp4)
172172

173-
### Go to other Ada file
173+
### Commands and shortcuts
174174

175-
The extension contributes a command and a corresponding key binding to
176-
switch between specification and implementation Ada files.
175+
The extension contributes a few commands and corresponding key bindings.
176+
177+
#### Ada: Go to other file
178+
179+
This command switches between specification and implementation Ada files.
177180
The default shortcut is `Alt+O`.
178181

182+
#### Ada: Add subprogram box
183+
184+
This command inserts a comment box before the current subprogram body.
185+
The default shortcut is `Alt+Shift+B`.
186+
187+
#### Ada: Reload project
188+
189+
This command reloads the current project.
190+
The default shortcut is `None`.
191+
179192
### Launch the extension to debug it
180193

181194
For the moment, this repository includes a vscode extension that is used as the

integration/vscode/ada/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@
423423
"command": "ada.otherFile",
424424
"title": "Ada: Go to other file"
425425
},
426+
{
427+
"command": "als-reload-project",
428+
"title": "Ada: Reload project"
429+
},
426430
{
427431
"command": "ada.subprogramBox",
428432
"title": "Ada: Add subprogram box"

source/ada/lsp-ada_driver.adb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ with GNATCOLL.VFS; use GNATCOLL.VFS;
4040
with LSP.Ada_Handlers;
4141
with LSP.Ada_Handlers.Named_Parameters_Commands;
4242
with LSP.Ada_Handlers.Other_File_Commands;
43+
with LSP.Ada_Handlers.Project_Reload_Commands;
4344
with LSP.Ada_Handlers.Refactor_Imports_Commands;
4445
with LSP.Ada_Handlers.Refactor_Add_Parameter;
4546
with LSP.Ada_Handlers.Refactor_Remove_Parameter;
@@ -132,6 +133,8 @@ procedure LSP.Ada_Driver is
132133
begin
133134
LSP.Commands.Register
134135
(LSP.Ada_Handlers.Other_File_Commands.Command'Tag);
136+
LSP.Commands.Register
137+
(LSP.Ada_Handlers.Project_Reload_Commands.Command'Tag);
135138
LSP.Commands.Register
136139
(LSP.Ada_Handlers.Named_Parameters_Commands.Command'Tag);
137140
LSP.Commands.Register
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2022, 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+
package body LSP.Ada_Handlers.Project_Reload_Commands is
19+
20+
------------
21+
-- Create --
22+
------------
23+
24+
overriding function Create
25+
(JS : not null access LSP.JSON_Streams.JSON_Stream'Class) return Command
26+
is
27+
pragma Unreferenced (JS);
28+
begin
29+
return (LSP.Commands.Command with null record);
30+
end Create;
31+
32+
-------------
33+
-- Execute --
34+
-------------
35+
36+
overriding procedure Execute
37+
(Self : Command;
38+
Handler : not null access LSP.Server_Notification_Receivers
39+
.Server_Notification_Receiver'Class;
40+
Client : not null access LSP.Client_Message_Receivers
41+
.Client_Message_Receiver'Class;
42+
Error : in out LSP.Errors.Optional_ResponseError)
43+
is
44+
Message_Handler : LSP.Ada_Handlers.Message_Handler renames
45+
LSP.Ada_Handlers.Message_Handler (Handler.all);
46+
47+
begin
48+
Message_Handler.Reload_Project;
49+
end Execute;
50+
51+
-------------------
52+
-- Write_Command --
53+
-------------------
54+
55+
procedure Write_Command
56+
(S : access Ada.Streams.Root_Stream_Type'Class;
57+
V : Command)
58+
is
59+
JS : LSP.JSON_Streams.JSON_Stream'Class renames
60+
LSP.JSON_Streams.JSON_Stream'Class (S.all);
61+
begin
62+
JS.Start_Object;
63+
-- no command arguments!
64+
JS.End_Object;
65+
end Write_Command;
66+
67+
end LSP.Ada_Handlers.Project_Reload_Commands;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2022, 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+
-- Implementation of the command to reload current project.
19+
20+
with Ada.Streams;
21+
22+
with LSP.Client_Message_Receivers;
23+
with LSP.Commands;
24+
with LSP.Errors;
25+
with LSP.JSON_Streams;
26+
27+
package LSP.Ada_Handlers.Project_Reload_Commands is
28+
29+
type Command is new LSP.Commands.Command with private;
30+
31+
private
32+
33+
type Command is new LSP.Commands.Command with null record;
34+
35+
overriding function Create
36+
(JS : not null access LSP.JSON_Streams.JSON_Stream'Class)
37+
return Command;
38+
39+
overriding procedure Execute
40+
(Self : Command;
41+
Handler : not null access
42+
LSP.Server_Notification_Receivers.Server_Notification_Receiver'Class;
43+
Client : not null access
44+
LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
45+
Error : in out LSP.Errors.Optional_ResponseError);
46+
47+
procedure Write_Command
48+
(S : access Ada.Streams.Root_Stream_Type'Class;
49+
V : Command);
50+
51+
for Command'Write use Write_Command;
52+
for Command'External_Tag use "als-reload-project";
53+
54+
end LSP.Ada_Handlers.Project_Reload_Commands;

0 commit comments

Comments
 (0)