Skip to content

Commit b4a99ff

Browse files
committed
Merge branch 'mr/1583-fix-extending-nav' into 'master'
Fix the navigation / find all refs in extending projects Closes #1583 See merge request eng/ide/ada_language_server!1889
2 parents 8d10ce1 + 8f542a4 commit b4a99ff

File tree

12 files changed

+189
-38
lines changed

12 files changed

+189
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ section below it for the last release. -->
88
* Fix the reporting of test results in the Testing view when the test tree is not expanded
99
* Fix sluggish completion while editing GPR files
1010
* Provide a task `ada: Build GNATtest test harness project` allowing to customize the build step of test execution in `tasks.json`
11+
* Fix cross-references (navigation, call hierarchy, finding all references) when the project is an Extending project.
1112

1213
## 26.0.202412190
1314

source/ada/lsp-ada_contexts.adb

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ with GPR2.Containers;
2727
with GPR2.Path_Name;
2828
with GPR2.Project.Attribute;
2929
with GPR2.Project.Attribute_Index;
30-
with GPR2.Project.View.Set;
3130
with GPR2.Build.Source;
3231
with GPR2.Build.Source.Sets;
3332

@@ -607,61 +606,105 @@ package body LSP.Ada_Contexts is
607606

608607
procedure Update_Source_Files is
609608

609+
procedure Process_Closure
610+
(Root : GPR2.Project.View.Object;
611+
Callback : not null access procedure
612+
(View : GPR2.Project.View.Object));
613+
-- Process the closure of Root with the given callback.
614+
-- Similar to GPR2.Project.View.Closure, but, in addition,
615+
-- when encountering an extending project, consider the
616+
-- project it is extending to be part of the closure.
617+
618+
procedure Add_Sources_From_View (View : GPR2.Project.View.Object);
619+
-- Add the sources from the given view to the context
620+
621+
procedure Add_Dirs_From_View (View : GPR2.Project.View.Object);
622+
-- Add the source directories from the given view to the context
623+
610624
procedure Insert_Source (Source : GPR2.Build.Source.Object);
611625
-- Insert Source in Self.Source_Files
612626

613627
-------------------
614628
-- Insert_Source --
615629
-------------------
616630

617-
procedure Insert_Source (Source : GPR2.Build.Source.Object) is
618-
Path : constant Virtual_File := Source.Path_Name.Virtual_File;
631+
procedure Insert_Source (Source : GPR2.Build.Source.Object)
632+
is
633+
Path : constant Virtual_File :=
634+
Source.Path_Name.Virtual_File;
619635
begin
620636
if not Self.Source_Files.Contains (Path) then
621637
Self.Source_Files.Include (Path);
622638
end if;
623639
end Insert_Source;
624640

625-
begin
626-
Self.Source_Files.Clear;
641+
---------------------
642+
-- Process_Closure --
643+
---------------------
627644

628-
for View of Root.Closure (Include_Self => True)
629-
when not View.Is_Runtime
630-
loop
631-
declare
632-
Sources : constant GPR2.Build.Source.Sets.Object
633-
:= View.Sources;
634-
use type GPR2.Language_Id;
635-
begin
636-
for Source of Sources loop
637-
if Source.Language = GPR2.Ada_Language then
638-
Insert_Source (Source);
639-
end if;
645+
procedure Process_Closure
646+
(Root : GPR2.Project.View.Object;
647+
Callback : not null access procedure
648+
(View : GPR2.Project.View.Object))
649+
is
650+
begin
651+
-- First process the closure of the view
652+
for View of Root.Closure
653+
(Include_Self => True) when not View.Is_Runtime
654+
loop
655+
Callback (View);
656+
end loop;
657+
658+
-- If we're looking at an extending view, now
659+
-- process the closure of the extended views.
660+
if Root.Is_Extending then
661+
for V of Root.Extended loop
662+
Process_Closure (V, Callback);
640663
end loop;
641-
end;
642-
end loop;
664+
end if;
665+
end Process_Closure;
643666

644-
Self.Source_Dirs.Clear;
645-
Self.External_Source_Dirs.Clear;
667+
---------------------------
668+
-- Add_Sources_From_View --
669+
---------------------------
646670

647-
declare
648-
Views : constant GPR2.Project.View.Set.Object :=
649-
Root.Closure (Include_Self => True);
671+
procedure Add_Sources_From_View (View : GPR2.Project.View.Object) is
672+
Sources : constant GPR2.Build.Source.Sets.Object := View.Sources;
673+
use type GPR2.Language_Id;
650674
begin
651-
for View of Views
652-
when not View.Is_Runtime
653-
loop
654-
if View.Is_Externally_Built then
655-
for Dir of View.Source_Directories loop
656-
Self.External_Source_Dirs.Include (Dir.Virtual_File);
657-
end loop;
658-
else
659-
for Dir of View.Source_Directories loop
660-
Self.Source_Dirs.Include (Dir.Virtual_File);
661-
end loop;
675+
for Source of Sources loop
676+
if Source.Language = GPR2.Ada_Language then
677+
Insert_Source (Source);
662678
end if;
663679
end loop;
664-
end;
680+
end Add_Sources_From_View;
681+
682+
------------------------
683+
-- Add_Dirs_From_View --
684+
------------------------
685+
686+
procedure Add_Dirs_From_View (View : GPR2.Project.View.Object) is
687+
begin
688+
if View.Is_Externally_Built then
689+
for Dir of View.Source_Directories loop
690+
Self.External_Source_Dirs.Include (Dir.Virtual_File);
691+
end loop;
692+
else
693+
for Dir of View.Source_Directories loop
694+
Self.Source_Dirs.Include (Dir.Virtual_File);
695+
end loop;
696+
end if;
697+
end Add_Dirs_From_View;
698+
699+
begin
700+
Self.Source_Files.Clear;
701+
702+
Process_Closure (Root, Add_Sources_From_View'Access);
703+
704+
Self.Source_Dirs.Clear;
705+
Self.External_Source_Dirs.Clear;
706+
707+
Process_Closure (Root, Add_Dirs_From_View'Access);
665708

666709
Self.Extension_Set.Clear;
667710

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
with Ada.Text_IO;
2+
3+
package body Common is
4+
5+
procedure Put (Item : Enum := Hello) is
6+
begin
7+
case Item is
8+
when Hello => null;
9+
when Goodbye => null;
10+
end case;
11+
end Put;
12+
13+
end Common;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package Common is
2+
3+
type Enum is (Hello, Goodbye);
4+
5+
procedure Put (Item : Enum := Hello);
6+
7+
end Common;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project Common is
2+
3+
for Source_Dirs use (".");
4+
for Source_Files use ("common.ads");
5+
6+
end Common;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project Extending extends "program/program.gpr" is
2+
3+
for Main use ("extending.adb");
4+
for Source_Dirs use ("extending");
5+
6+
end Extending;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
with Program;
2+
with Common;
3+
4+
procedure Extending is
5+
X : Common.Enum := Common.Hello;
6+
begin
7+
Program;
8+
end Extending;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
with Common;
2+
3+
procedure Program is
4+
begin
5+
6+
Common.Put (Common.Hello);
7+
Common.Put (Common.Goodbye);
8+
9+
end Program;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
with "../common/common.gpr";
2+
3+
project Program is
4+
5+
for Main use ("program.adb");
6+
for Source_Dirs use (".");
7+
8+
end Program;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""test that a references call finds all references to an enumeration
2+
literal in the context of extending projects."""
3+
4+
from drivers.pylsp import ALSLanguageClient, test
5+
6+
7+
@test()
8+
async def test_called_by(lsp: ALSLanguageClient) -> None:
9+
# Send a didChangeConfiguration notification to load the extending project
10+
lsp.didChangeConfig({"projectFile": "extending.gpr"})
11+
12+
# Send a didOpen for main.adb
13+
common_ads = lsp.didOpenFile("common/common.ads")
14+
15+
# Send a textDocument/prepareCallHierarchy request and verify the result
16+
res1 = await lsp.references(common_ads, 3, 21)
17+
lsp.assertLocationsList(
18+
res1,
19+
[
20+
("common.ads", 3),
21+
("common.ads", 5),
22+
("extending.adb", 5),
23+
("program.adb", 6),
24+
],
25+
)
26+
27+
# Now load the non-extending project
28+
lsp.didChangeConfig({"projectFile": "program/program.gpr"})
29+
30+
# And verify the result
31+
res1 = await lsp.references(common_ads, 3, 21)
32+
lsp.assertLocationsList(
33+
res1,
34+
[
35+
("common.ads", 3),
36+
("common.ads", 5),
37+
("program.adb", 6),
38+
],
39+
)

0 commit comments

Comments
 (0)