Skip to content

Commit 9791e0f

Browse files
committed
Merge branch 'topic/fix' into 'master'
Add more custom commands for vscode extension Closes #1182 See merge request eng/ide/ada_language_server!1400
2 parents 9d3250c + 6db1d76 commit 9791e0f

13 files changed

+510
-48
lines changed

doc/executables.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This implements a functionality to query the mains and the executables for a multi targets project.
66

7-
## Capabilities
7+
## Capabilities
88

99
We provide the Build and Run tasks for specific targets in a GPR Projects.
1010

@@ -14,26 +14,22 @@ To check these tasks :
1414

1515
## Change description
1616

17-
We introduce two requests, the first one:
17+
We introduce two commands, the first one:
1818

19-
method: `glsMains`
19+
command: `als-mains`
2020

2121
Which provides the mains for the project, with a response type:
2222

2323
```typesript
24-
type GlsMainResult = {
25-
mains: string[];
26-
};
24+
type GlsMainResult = string[];
2725
```
2826

2927
The second one is:
3028

31-
method: `glsExecutables`
29+
command: `als-executables`
3230

3331
Which provides the executables for the project, with a response type:
3432

3533
```typesript
36-
type GlsExecutableResult = {
37-
executables: string[];
38-
};
34+
type GlsExecutableResult = string[];
3935
```

doc/object_dir.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22

33
## Short introduction
44

5-
This is a custom request used by the VS Code extension to retrieve the Object Directory from the GPR project file, allowing us to get the path to the object directory currently in use.
5+
This is a custom command used by the VS Code extension to retrieve the Object Directory from the GPR project file, allowing us to get the path to the object directory currently in use.
66

77
## Change description
88

99
We introduce a new type to represent the request results:
1010

1111
```typescript
1212

13-
type ObjDirResponse = {
14-
Value : string;
15-
};
13+
type ObjDirResponse = string;
1614

1715
```
1816

19-
And a new request:
17+
And a new command with out arguments:
2018

21-
method: `$/glsObjectDir`
22-
params: null
19+
method: `als-object-dir`
2320

2421
Returning the project file of the loaded project like this:
2522

doc/project_file.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22

33
## Short introduction
44

5-
This is a custom request used by the VS Code extension to retrieve the GPR project file uploaded by the ALS, allowing us to get the path to the project file currently in use.
5+
This is a custom command used by the VS Code extension to retrieve the GPR project file uploaded by the ALS, allowing us to get the path to the project file currently in use.
66

77
## Change description
88

99
We introduce a new type to represent the request results:
1010

1111
```typescript
1212

13-
export type ProjectFileResponse = {
14-
Value : string; // The Path to the GPR project file
15-
};
13+
export type ProjectFileResponse = string; // The Path to the GPR project file
1614
```
1715

18-
And a new request:
16+
And a new command with out arguments:
1917

20-
method: `$/glsProjectFile`
21-
params: null
18+
command: `als-project-file`
2219

2320
Returning the project file of the loaded project like this:
2421

integration/vscode/ada/src/helpers.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { platform } from 'os';
1818
import * as path from 'path';
1919
import * as vscode from 'vscode';
20-
import { LanguageClient } from 'vscode-languageclient/node';
20+
import { ExecuteCommandRequest, LanguageClient } from 'vscode-languageclient/node';
2121

2222
/**
2323
* Substitue any variable reference present in the given string. VS Code
@@ -181,21 +181,6 @@ export function logErrorAndThrow(msg: string, channel: vscode.OutputChannel) {
181181
/*
182182
GPR extensions helper functions
183183
*/
184-
type ProjectFileResponse = {
185-
projectFile: string;
186-
};
187-
188-
type ObjDirResponse = {
189-
objectDir: string;
190-
};
191-
192-
type MainsResponse = {
193-
mains: string[];
194-
};
195-
196-
type ExecutablesResponse = {
197-
executables: string[];
198-
};
199184

200185
/**
201186
* Get the project file from the workspace configuration if available, or from
@@ -205,8 +190,10 @@ type ExecutablesResponse = {
205190
* @returns a string contains the path of the project file
206191
*/
207192
export async function getProjectFile(client: LanguageClient): Promise<string> {
208-
const result: ProjectFileResponse = await client.sendRequest('$/glsProjectFile');
209-
return result.projectFile;
193+
const result: string = (await client.sendRequest(ExecuteCommandRequest.type, {
194+
command: 'als-project-file',
195+
})) as string;
196+
return result;
210197
}
211198

212199
/**
@@ -215,8 +202,10 @@ export async function getProjectFile(client: LanguageClient): Promise<string> {
215202
* @returns a string path
216203
*/
217204
export async function getObjectDir(client: LanguageClient): Promise<string> {
218-
const result: ObjDirResponse = await client.sendRequest('$/glsObjectDir');
219-
return result.objectDir;
205+
const result: string = (await client.sendRequest(ExecuteCommandRequest.type, {
206+
command: 'als-object-dir',
207+
})) as string;
208+
return result;
220209
}
221210

222211
/**
@@ -225,8 +214,10 @@ export async function getObjectDir(client: LanguageClient): Promise<string> {
225214
* @returns a vector of string paths
226215
*/
227216
export async function getMains(client: LanguageClient): Promise<string[]> {
228-
const result: MainsResponse = await client.sendRequest('$/glsMains');
229-
return result.mains;
217+
const result: string[] = (await client.sendRequest(ExecuteCommandRequest.type, {
218+
command: 'als-mains',
219+
})) as string[];
220+
return result;
230221
}
231222

232223
/**
@@ -235,6 +226,8 @@ export async function getMains(client: LanguageClient): Promise<string[]> {
235226
* @returns a vector of string paths
236227
*/
237228
export async function getExecutables(client: LanguageClient): Promise<string[]> {
238-
const result: ExecutablesResponse = await client.sendRequest('$/glsExecutables');
239-
return result.executables;
229+
const result: string[] = (await client.sendRequest(ExecuteCommandRequest.type, {
230+
command: 'als-executables',
231+
})) as string[];
232+
return result;
240233
}

source/ada/lsp-ada_driver.adb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ with GNATCOLL.Utils;
3939

4040
with LSP.Ada_Commands;
4141
with LSP.Ada_Handlers;
42+
with LSP.Ada_Handlers.Executables_Commands;
43+
with LSP.Ada_Handlers.Mains_Commands;
4244
with LSP.Ada_Handlers.Named_Parameters_Commands;
45+
with LSP.Ada_Handlers.Object_Dir_Commands;
4346
with LSP.Ada_Handlers.Other_File_Commands;
47+
with LSP.Ada_Handlers.Project_File_Commands;
4448
with LSP.Ada_Handlers.Project_Reload_Commands;
4549
with LSP.Ada_Handlers.Refactor.Add_Parameter;
4650
with LSP.Ada_Handlers.Refactor.Change_Parameter_Mode;
@@ -91,6 +95,14 @@ procedure LSP.Ada_Driver is
9195
(LSP.Ada_Handlers.Project_Reload_Commands.Command'Tag);
9296
LSP.Ada_Commands.Register
9397
(LSP.Ada_Handlers.Show_Dependencies_Commands.Command'Tag);
98+
LSP.Ada_Commands.Register
99+
(LSP.Ada_Handlers.Executables_Commands.Command'Tag);
100+
LSP.Ada_Commands.Register
101+
(LSP.Ada_Handlers.Mains_Commands.Command'Tag);
102+
LSP.Ada_Commands.Register
103+
(LSP.Ada_Handlers.Project_File_Commands.Command'Tag);
104+
LSP.Ada_Commands.Register
105+
(LSP.Ada_Handlers.Object_Dir_Commands.Command'Tag);
94106
LSP.Ada_Commands.Register
95107
(LSP.Ada_Handlers.Named_Parameters_Commands.Command'Tag);
96108
LSP.Ada_Commands.Register
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2020-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 GPR2.Project.View;
19+
20+
with VSS.JSON.Streams;
21+
22+
package body LSP.Ada_Handlers.Executables_Commands is
23+
24+
------------
25+
-- Create --
26+
------------
27+
28+
overriding function Create
29+
(Any : not null access LSP.Structures.LSPAny_Vector)
30+
return Command is
31+
begin
32+
-- We have no arguments for this command
33+
return V : Command;
34+
end Create;
35+
36+
-------------
37+
-- Execute --
38+
-------------
39+
40+
overriding procedure Execute
41+
(Self : Command;
42+
Handler : not null access LSP.Ada_Handlers.Message_Handler'Class;
43+
Response : in out LSP.Structures.LSPAny_Or_Null;
44+
Error : in out LSP.Errors.ResponseError_Optional)
45+
is
46+
procedure Append (Item : VSS.JSON.Streams.JSON_Stream_Element);
47+
48+
------------
49+
-- Append --
50+
------------
51+
52+
procedure Append (Item : VSS.JSON.Streams.JSON_Stream_Element) is
53+
begin
54+
Response.Value.Append (Item);
55+
end Append;
56+
57+
Value : VSS.Strings.Virtual_String;
58+
Element : GPR2.Project.View.Object;
59+
begin
60+
Response := (Is_Null => False, Value => <>);
61+
Append ((Kind => VSS.JSON.Streams.Start_Array));
62+
63+
if Handler.Project_Tree.Is_Defined then
64+
Element := Handler.Project_Tree.Root_Project;
65+
66+
for Exec of Element.Executables loop
67+
Value := VSS.Strings.Conversions.To_Virtual_String (Exec.Value);
68+
Append ((VSS.JSON.Streams.String_Value, Value));
69+
end loop;
70+
end if;
71+
72+
Append ((Kind => VSS.JSON.Streams.End_Array));
73+
end Execute;
74+
75+
end LSP.Ada_Handlers.Executables_Commands;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2020-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+
-- Implementation of the command to get list of executables for the project.
19+
20+
with LSP.Ada_Commands;
21+
with LSP.Errors;
22+
23+
package LSP.Ada_Handlers.Executables_Commands is
24+
25+
type Command is new LSP.Ada_Commands.Command with private;
26+
27+
private
28+
29+
type Command is new LSP.Ada_Commands.Command with null record;
30+
31+
overriding function Create
32+
(Any : not null access LSP.Structures.LSPAny_Vector)
33+
return Command;
34+
35+
overriding procedure Execute
36+
(Self : Command;
37+
Handler : not null access LSP.Ada_Handlers.Message_Handler'Class;
38+
Response : in out LSP.Structures.LSPAny_Or_Null;
39+
Error : in out LSP.Errors.ResponseError_Optional);
40+
41+
for Command'External_Tag use "als-executables";
42+
43+
end LSP.Ada_Handlers.Executables_Commands;

0 commit comments

Comments
 (0)