Skip to content

Commit

Permalink
Merge branch 'topic/1225-gpr-declaration-implementation' into 'master'
Browse files Browse the repository at this point in the history
testDocument/declaration support

See merge request eng/ide/ada_language_server!1531
  • Loading branch information
Philippe Gil committed Apr 10, 2024
2 parents 48922d6 + 76e3c05 commit 88e23c7
Show file tree
Hide file tree
Showing 8 changed files with 995 additions and 0 deletions.
50 changes: 50 additions & 0 deletions source/gpr/lsp-gpr_handlers.adb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ package body LSP.GPR_Handlers is

Capabilities.hoverProvider := LSP.Constants.True;
Capabilities.definitionProvider := LSP.Constants.True;
Capabilities.declarationProvider := LSP.Constants.True;
Capabilities.completionProvider :=
(Is_Set => True,
Value => (triggerCharacters => [" "],
Expand Down Expand Up @@ -431,6 +432,55 @@ package body LSP.GPR_Handlers is
Self.Sender.On_Completion_Resolve_Response (Id, Response);
end On_Completion_Resolve_Request;

----------------------------
-- On_Declaration_Request --
----------------------------

overriding procedure On_Declaration_Request
(Self : in out Message_Handler;
Id : LSP.Structures.Integer_Or_Virtual_String;
Value : LSP.Structures.DeclarationParams)
is
procedure Fill_Declaration;
-- Utility function, appends to Vector the definition if any.

Response : LSP.Structures.Declaration_Result (LSP.Structures.Variant_1);

----------------------
-- Fill_Declaration --
----------------------

procedure Fill_Declaration is
File : constant LSP.GPR_Files.File_Access :=
LSP.GPR_Files.Parse
(File_Provider => Self'Unchecked_Access,
Path => Self.To_File
(Value.textDocument.uri));

Reference : constant Gpr_Parser.Common.Token_Reference :=
LSP.GPR_Files.References.Token_Reference
(File, Value.position);

Location : LSP.Structures.Location;

use type Gpr_Parser.Common.Token_Reference;

begin
if Reference /= Gpr_Parser.Common.No_Token then
Location.uri :=
LSP.GPR_File_Readers.To_URI (Reference.Origin_Filename);
Location.a_range := To_Range (Self'Unchecked_Access, Reference);
Response.Variant_1.Append (Location);
end if;

end Fill_Declaration;

begin
Fill_Declaration;

Self.Sender.On_Declaration_Response (Id, Response);
end On_Declaration_Request;

---------------------------
-- On_Definition_Request --
---------------------------
Expand Down
5 changes: 5 additions & 0 deletions source/gpr/lsp-gpr_handlers.ads
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ private
Id : LSP.Structures.Integer_Or_Virtual_String;
Value : LSP.Structures.DefinitionParams);

overriding procedure On_Declaration_Request
(Self : in out Message_Handler;
Id : LSP.Structures.Integer_Or_Virtual_String;
Value : LSP.Structures.DeclarationParams);

-----------------------------------------
-- LSP.GPR_Documents.Document_Provider --
-----------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions testsuite/gpr_lsp/declaration/aggregating.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
aggregate project GPS_Aggregated is

for Project_Files use
("ignored.gpr", "navigation.gpr");
for Object_Dir use "obj";

end GPS_Aggregated;
13 changes: 13 additions & 0 deletions testsuite/gpr_lsp/declaration/imported.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract project Imported is
type T is ("0", "1");
V := "0";
for Exec_Dir use "exe";
package Compiler is
V := "0";
for Switches ("Ada") use ();
end Compiler;
package Builder is
end Builder;
package Binder is
end Binder;
end Imported;
23 changes: 23 additions & 0 deletions testsuite/gpr_lsp/declaration/navigation.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
with "ignored", "imported";
project Navigation is

type T is ("0", "1");
V : T := "0";
for Source_Dirs use ("src");
package Compiler is
V := ();
for Switches ("Ada") use V;
V1 := Navigation.Compiler'Switches ("Ada");
V2 := Compiler'Switches ("Ada");
V3 := Compiler.V;
V4 : Imported.T := Imported.V;
V5 := Imported'Exec_Dir;
V6 := Imported.Compiler'Switches ("Ada");
V7 := Imported.Compiler.V;
end Compiler;
package Builder renames Imported.Builder;
package Binder extends Imported.Binder is
end Binder;
V8 := V;

end Navigation;
7 changes: 7 additions & 0 deletions testsuite/gpr_lsp/declaration/prj.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
aggregate project GPS_Aggregated is

for Project_Files use
("ignored.gpr", "navigation.gpr");
for Object_Dir use "obj";

end GPS_Aggregated;
Loading

0 comments on commit 88e23c7

Please sign in to comment.