Skip to content

Commit c5e87be

Browse files
committed
Merge branch 'topic/fb_context2' into 'master'
Reapply "Merge branch 'topic/fb_context' into 'master'" See merge request eng/ide/ada_language_server!2015
2 parents 8bf3374 + 9c6b908 commit c5e87be

File tree

10 files changed

+305
-53
lines changed

10 files changed

+305
-53
lines changed

source/ada/lsp-ada_context_sets.adb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ package body LSP.Ada_Context_Sets is
7575
return Context_Access is
7676
begin
7777
for Context of Self.Contexts loop
78-
if Context.Is_Part_Of_Project (URI) then
78+
if not Context.Is_Fallback_Context
79+
and then Context.Is_Part_Of_Project (URI)
80+
then
7981
return Context;
8082
end if;
8183
end loop;

source/ada/lsp-ada_handlers-project_loading.adb

Lines changed: 113 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ package body LSP.Ada_Handlers.Project_Loading is
104104
-- Reload as project source dirs the directories in
105105
-- Self.Project_Dirs_Loaded.
106106

107+
procedure Create_In_Memory_Project
108+
(Name : GPR2.Name_Type;
109+
Dirs : File_Sets.Set;
110+
Project_Tree : in out GPR2.Project.Tree.Object;
111+
Success : out Boolean);
112+
-- Unload Project_Tree then construct a new project in memory with given
113+
-- Name and source Dirs. Return Success=True and resulting Project_Tree
114+
-- if everything is fine. Return Success=False otherwise.
115+
107116
procedure Update_Project_Predefined_Sources
108117
(Self : in out Message_Handler'Class);
109118
-- Fill Self.Project_Predefined_Sources with loaded project tree runtime
@@ -113,6 +122,68 @@ package body LSP.Ada_Handlers.Project_Loading is
113122
-- This also indexes immediately any already opened document, creating
114123
-- the handler's fallback context before for that purpose.
115124

125+
procedure Create_Fallback_Context (Self : in out Message_Handler'Class);
126+
-- Create a fallback context for the given handler's contexts' set.
127+
128+
-----------------------------
129+
-- Create_Fallback_Context --
130+
-----------------------------
131+
132+
procedure Create_Fallback_Context (Self : in out Message_Handler'Class) is
133+
use LSP.Ada_Context_Sets;
134+
use LSP.Ada_Contexts;
135+
use type GNATCOLL.VFS.Virtual_File;
136+
137+
C : constant Context_Access := new Context (Self.Tracer);
138+
139+
Reader : LSP.Ada_Handlers.File_Readers.LSP_File_Reader
140+
(Self'Unchecked_Access);
141+
142+
Dirs : File_Sets.Set;
143+
144+
Project_Tree : GPR2.Project.Tree.Object;
145+
146+
Success : Boolean;
147+
begin
148+
Self.Tracer.Trace_Text ("Creating fallback context");
149+
150+
C.Initialize
151+
(File_Reader => Reader,
152+
Follow_Symlinks => Self.Configuration.Follow_Symlinks,
153+
Style => Self.Configuration.Documentation_Style,
154+
As_Fallback_Context => True);
155+
156+
if Self.Client.Root_Directory /= GNATCOLL.VFS.No_File then
157+
Dirs.Insert (Self.Client.Root_Directory);
158+
end if;
159+
160+
Create_In_Memory_Project
161+
("fallback_context", Dirs, Project_Tree, Success);
162+
163+
pragma Assert
164+
(Success, "Can't create an empty project for the fallback context");
165+
166+
-- Create a basic GPR2_Provider_And_Projects containing only the
167+
-- implicit project and load it.
168+
declare
169+
Provider : Libadalang.Project_Provider.GPR2_Provider_And_Projects :=
170+
(Provider =>
171+
Libadalang.Project_Provider.Create_Project_Unit_Provider
172+
(Tree => Project_Tree,
173+
Project => Project_Tree.Root_Project),
174+
Projects => <>);
175+
begin
176+
Provider.Projects.Append (Project_Tree.Root_Project);
177+
178+
C.Load_Project
179+
(Provider => Provider,
180+
Tree => Project_Tree,
181+
Charset => "iso-8859-1");
182+
end;
183+
184+
Self.Contexts.Prepend (C);
185+
end Create_Fallback_Context;
186+
116187
---------------------------
117188
-- Ensure_Project_Loaded --
118189
---------------------------
@@ -684,35 +755,6 @@ package body LSP.Ada_Handlers.Project_Loading is
684755
--------------------------
685756

686757
procedure Enqueue_Indexing_Job (Self : in out Message_Handler'Class) is
687-
procedure Create_Fallback_Context (Self : in out Message_Handler'Class);
688-
-- Create a fallback context for the given handler's contexts' set.
689-
690-
-----------------------------
691-
-- Create_Fallback_Context --
692-
-----------------------------
693-
694-
procedure Create_Fallback_Context (Self : in out Message_Handler'Class)
695-
is
696-
use LSP.Ada_Context_Sets;
697-
use LSP.Ada_Contexts;
698-
begin
699-
declare
700-
C : constant Context_Access := new Context (Self.Tracer);
701-
Reader :
702-
LSP.Ada_Handlers.File_Readers.LSP_File_Reader
703-
(Self'Unchecked_Access);
704-
begin
705-
Self.Tracer.Trace_Text ("Creating fallback context");
706-
707-
C.Initialize
708-
(File_Reader => Reader,
709-
Follow_Symlinks => Self.Configuration.Follow_Symlinks,
710-
Style => Self.Configuration.Documentation_Style,
711-
As_Fallback_Context => True);
712-
Self.Contexts.Prepend (C);
713-
end;
714-
end Create_Fallback_Context;
715-
716758
Files : LSP.Ada_Indexing.File_Sets.Set;
717759
begin
718760
-- Create a fallback context before indexing. This allows to
@@ -787,20 +829,44 @@ package body LSP.Ada_Handlers.Project_Loading is
787829

788830
procedure Reload_Implicit_Project_Dirs (Self : in out Message_Handler'Class)
789831
is
790-
Project : GPR2.Project.Tree.View_Builder.Object :=
791-
GPR2.Project.Tree.View_Builder.Create
792-
(Project_Dir => GPR2.Path_Name.Create_Directory ("."),
793-
Name => "default");
794-
Values : GPR2.Containers.Value_List;
795-
Opts : GPR2.Options.Object;
796832
Success : Boolean;
797833
begin
798834
Release_Contexts_And_Project_Info (Self);
799-
Self.Project_Tree.Unload;
800835

836+
Create_In_Memory_Project
837+
(Name => "default",
838+
Dirs => Self.Project_Dirs_Loaded,
839+
Project_Tree => Self.Project_Tree,
840+
Success => Success);
841+
842+
if not Success then
843+
LSP.Ada_Project_Loading.Set_Load_Status
844+
(Self.Project_Status, LSP.Ada_Project_Loading.Invalid_Project);
845+
end if;
846+
end Reload_Implicit_Project_Dirs;
847+
848+
------------------------------
849+
-- Create_In_Memory_Project --
850+
------------------------------
851+
852+
procedure Create_In_Memory_Project
853+
(Name : GPR2.Name_Type;
854+
Dirs : File_Sets.Set;
855+
Project_Tree : in out GPR2.Project.Tree.Object;
856+
Success : out Boolean)
857+
is
858+
Project : GPR2.Project.Tree.View_Builder.Object :=
859+
GPR2.Project.Tree.View_Builder.Create
860+
(Project_Dir => GPR2.Path_Name.Create_Directory ("."),
861+
Name => Name);
862+
Values : GPR2.Containers.Value_List;
863+
Opts : GPR2.Options.Object;
864+
Reporter : GPR2_Reporter;
865+
begin
866+
Project_Tree.Unload;
801867
-- Load all the dirs
802868

803-
for Dir of Self.Project_Dirs_Loaded loop
869+
for Dir of Dirs loop
804870
Values.Append (Dir.Display_Full_Name);
805871
end loop;
806872

@@ -809,28 +875,26 @@ package body LSP.Ada_Handlers.Project_Loading is
809875

810876
-- First we load the fallback project
811877
Success :=
812-
Self.Project_Tree.Load_Virtual_View
878+
Project_Tree.Load_Virtual_View
813879
(Project,
814880
Opts,
815881
With_Runtime => True,
816-
Absent_Dir_Error => GPR2.No_Error);
882+
Absent_Dir_Error => GPR2.No_Error,
883+
Reporter => Reporter);
817884

818-
if not Success then
819-
for C in Self.Project_Tree.Log_Messages.Iterate loop
885+
if Success then
886+
Project_Tree.Update_Sources;
887+
else
888+
for C in Project_Tree.Log_Messages.Iterate loop
820889
Tracer.Trace (C.Element.Format);
821890
end loop;
822-
LSP.Ada_Project_Loading.Set_Load_Status
823-
(Self.Project_Status, LSP.Ada_Project_Loading.Invalid_Project);
824891
end if;
825892

826-
Self.Project_Tree.Update_Sources;
827-
828893
exception
829894
when E : others =>
830-
Tracer.Trace_Exception (E, "Reload_Implicit_Project_Dirs");
831-
LSP.Ada_Project_Loading.Set_Load_Status
832-
(Self.Project_Status, LSP.Ada_Project_Loading.Invalid_Project);
833-
end Reload_Implicit_Project_Dirs;
895+
Tracer.Trace_Exception (E, "Create_In_Memory_Project");
896+
Success := False;
897+
end Create_In_Memory_Project;
834898

835899
--------------------
836900
-- Reload_Project --

source/ada/lsp-ada_handlers-project_loading.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ package LSP.Ada_Handlers.Project_Loading is
3333
-- 4. else if there are multiple projects at the root, warn about it and
3434
-- load the implicit project
3535
-- 5. else load the implicit project
36+
--
37+
-- Initially this function guaranteed that the Message_Handler would have
38+
-- the project loaded on return, but this is no longer the case.
3639

3740
procedure Reload_Project (Self : in out Message_Handler'CLass);
3841
-- Clear the current project context and call Ensure_Project_Loaded to

source/ada/lsp-ada_handlers.adb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ package body LSP.Ada_Handlers is
254254
-- Check if the given file belongs to the runtime.
255255

256256
function Is_A_Source (Self : LSP.Ada_Contexts.Context) return Boolean is
257-
((Is_Runtime_File and then not Self.Is_Fallback_Context)
258-
or else Self.Is_Part_Of_Project (File));
257+
(not Self.Is_Fallback_Context and then
258+
(Is_Runtime_File or else Self.Is_Part_Of_Project (File)));
259259
-- Return True if File is a source of the project held by Context
260-
-- Avoid considering runtime files as sources for the fallback context,
260+
-- Avoid considering runtime files as sources and the fallback context,
261261
-- if there is no context available for this file then we will still
262262
-- use the fallback later.
263263

testsuite/ada_lsp/Did_Rename_Files.context_corruption/test.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,20 @@
684684
}
685685
},
686686
"alsKind": ["reference"]
687+
},
688+
{
689+
"uri": "$URI{main.adb}",
690+
"range": {
691+
"start": {
692+
"line": 4,
693+
"character": 12
694+
},
695+
"end": {
696+
"line": 4,
697+
"character": 13
698+
}
699+
},
700+
"alsKind": ["call"]
687701
}
688702
]
689703
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Default is
2+
for Source_Dirs use ("src");
3+
end Default;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Proc is
2+
begin
3+
Proc;
4+
end Proc;

0 commit comments

Comments
 (0)