Skip to content

Commit 88e23c7

Browse files
author
Philippe Gil
committed
Merge branch 'topic/1225-gpr-declaration-implementation' into 'master'
testDocument/declaration support See merge request eng/ide/ada_language_server!1531
2 parents 48922d6 + 76e3c05 commit 88e23c7

File tree

8 files changed

+995
-0
lines changed

8 files changed

+995
-0
lines changed

source/gpr/lsp-gpr_handlers.adb

+50
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ package body LSP.GPR_Handlers is
341341

342342
Capabilities.hoverProvider := LSP.Constants.True;
343343
Capabilities.definitionProvider := LSP.Constants.True;
344+
Capabilities.declarationProvider := LSP.Constants.True;
344345
Capabilities.completionProvider :=
345346
(Is_Set => True,
346347
Value => (triggerCharacters => [" "],
@@ -431,6 +432,55 @@ package body LSP.GPR_Handlers is
431432
Self.Sender.On_Completion_Resolve_Response (Id, Response);
432433
end On_Completion_Resolve_Request;
433434

435+
----------------------------
436+
-- On_Declaration_Request --
437+
----------------------------
438+
439+
overriding procedure On_Declaration_Request
440+
(Self : in out Message_Handler;
441+
Id : LSP.Structures.Integer_Or_Virtual_String;
442+
Value : LSP.Structures.DeclarationParams)
443+
is
444+
procedure Fill_Declaration;
445+
-- Utility function, appends to Vector the definition if any.
446+
447+
Response : LSP.Structures.Declaration_Result (LSP.Structures.Variant_1);
448+
449+
----------------------
450+
-- Fill_Declaration --
451+
----------------------
452+
453+
procedure Fill_Declaration is
454+
File : constant LSP.GPR_Files.File_Access :=
455+
LSP.GPR_Files.Parse
456+
(File_Provider => Self'Unchecked_Access,
457+
Path => Self.To_File
458+
(Value.textDocument.uri));
459+
460+
Reference : constant Gpr_Parser.Common.Token_Reference :=
461+
LSP.GPR_Files.References.Token_Reference
462+
(File, Value.position);
463+
464+
Location : LSP.Structures.Location;
465+
466+
use type Gpr_Parser.Common.Token_Reference;
467+
468+
begin
469+
if Reference /= Gpr_Parser.Common.No_Token then
470+
Location.uri :=
471+
LSP.GPR_File_Readers.To_URI (Reference.Origin_Filename);
472+
Location.a_range := To_Range (Self'Unchecked_Access, Reference);
473+
Response.Variant_1.Append (Location);
474+
end if;
475+
476+
end Fill_Declaration;
477+
478+
begin
479+
Fill_Declaration;
480+
481+
Self.Sender.On_Declaration_Response (Id, Response);
482+
end On_Declaration_Request;
483+
434484
---------------------------
435485
-- On_Definition_Request --
436486
---------------------------

source/gpr/lsp-gpr_handlers.ads

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ private
167167
Id : LSP.Structures.Integer_Or_Virtual_String;
168168
Value : LSP.Structures.DefinitionParams);
169169

170+
overriding procedure On_Declaration_Request
171+
(Self : in out Message_Handler;
172+
Id : LSP.Structures.Integer_Or_Virtual_String;
173+
Value : LSP.Structures.DeclarationParams);
174+
170175
-----------------------------------------
171176
-- LSP.GPR_Documents.Document_Provider --
172177
-----------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
aggregate project GPS_Aggregated is
2+
3+
for Project_Files use
4+
("ignored.gpr", "navigation.gpr");
5+
for Object_Dir use "obj";
6+
7+
end GPS_Aggregated;
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
abstract project Imported is
2+
type T is ("0", "1");
3+
V := "0";
4+
for Exec_Dir use "exe";
5+
package Compiler is
6+
V := "0";
7+
for Switches ("Ada") use ();
8+
end Compiler;
9+
package Builder is
10+
end Builder;
11+
package Binder is
12+
end Binder;
13+
end Imported;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
with "ignored", "imported";
2+
project Navigation is
3+
4+
type T is ("0", "1");
5+
V : T := "0";
6+
for Source_Dirs use ("src");
7+
package Compiler is
8+
V := ();
9+
for Switches ("Ada") use V;
10+
V1 := Navigation.Compiler'Switches ("Ada");
11+
V2 := Compiler'Switches ("Ada");
12+
V3 := Compiler.V;
13+
V4 : Imported.T := Imported.V;
14+
V5 := Imported'Exec_Dir;
15+
V6 := Imported.Compiler'Switches ("Ada");
16+
V7 := Imported.Compiler.V;
17+
end Compiler;
18+
package Builder renames Imported.Builder;
19+
package Binder extends Imported.Binder is
20+
end Binder;
21+
V8 := V;
22+
23+
end Navigation;

testsuite/gpr_lsp/declaration/prj.gpr

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
aggregate project GPS_Aggregated is
2+
3+
for Project_Files use
4+
("ignored.gpr", "navigation.gpr");
5+
for Object_Dir use "obj";
6+
7+
end GPS_Aggregated;

0 commit comments

Comments
 (0)