Skip to content

Commit e67757e

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 99222e0 + 17570ff commit e67757e

File tree

42 files changed

+533
-1041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+533
-1041
lines changed

source/ada/lsp-ada_contexts.adb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,26 @@ package body LSP.Ada_Contexts is
909909
Attribute : GPR2.Q_Attribute_Id;
910910
Index : String := "";
911911
Default : String := "";
912-
Use_Extended : Boolean := False) return String
913-
is
912+
Use_Extended : Boolean := False) return String is
913+
begin
914+
return Project_Attribute_Value
915+
(View => Self.Tree.Root_Project,
916+
Attribute => Attribute,
917+
Index => Index,
918+
Default => Default,
919+
Use_Extended => Use_Extended);
920+
end Project_Attribute_Value;
921+
922+
-----------------------------
923+
-- Project_Attribute_Value --
924+
-----------------------------
925+
926+
function Project_Attribute_Value
927+
(View : GPR2.Project.View.Object;
928+
Attribute : GPR2.Q_Attribute_Id;
929+
Index : String := "";
930+
Default : String := "";
931+
Use_Extended : Boolean := False) return String is
914932
Attribute_Index : constant GPR2.Project.Attribute_Index.Object :=
915933
(if Index = ""
916934
then GPR2.Project.Attribute_Index.Undefined
@@ -919,19 +937,19 @@ package body LSP.Ada_Contexts is
919937
Attribute_Value : GPR2.Project.Attribute.Object;
920938

921939
begin
922-
if Self.Tree.Root_Project.Check_Attribute
940+
if View.Check_Attribute
923941
(Name => Attribute,
924942
Index => Attribute_Index,
925943
Result => Attribute_Value)
926944
then
927945
return Attribute_Value.Value.Text;
928-
elsif Use_Extended and then Self.Tree.Root_Project.Is_Extending then
929-
-- Look at Extended project list as attribute not found in
930-
-- Root_Project and Use_Extended requested.
946+
elsif Use_Extended and then View.Is_Extending then
947+
-- Look at Extended project list as attribute not found in
948+
-- Root_Project and Use_Extended requested.
931949

932950
declare
933951
Extended_Root : GPR2.Project.View.Object :=
934-
Self.Tree.Root_Project.Extended_Root;
952+
View.Extended_Root;
935953
begin
936954
while Extended_Root.Is_Defined loop
937955
if Extended_Root.Check_Attribute

source/ada/lsp-ada_contexts.ads

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ package LSP.Ada_Contexts is
285285
-- itself, then the attribute is looked up in the project extended by
286286
-- Project (if any).
287287

288+
function Project_Attribute_Value
289+
(View : GPR2.Project.View.Object;
290+
Attribute : GPR2.Q_Attribute_Id;
291+
Index : String := "";
292+
Default : String := "";
293+
Use_Extended : Boolean := False) return String;
294+
-- Same as above, but computing the value from the given view instead
295+
-- of the context's root project.
296+
288297
private
289298

290299
type Context (Tracer : not null LSP.Tracers.Tracer_Access) is tagged limited

source/ada/lsp-ada_handlers-other_file_commands.adb

Lines changed: 143 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with GNATCOLL.Utils;
19+
with GPR2; use GPR2;
20+
with GPR2.Build.Source;
1821
with GPR2.Build.Unit_Info;
1922
with GPR2.Project.View;
2023
with VSS.JSON.Streams;
2124

22-
with GNATCOLL.VFS; use GNATCOLL.VFS;
25+
with GNATCOLL.VFS; use GNATCOLL.VFS;
2326

2427
with GPR2.Build.Compilation_Unit;
2528
with GPR2.Path_Name;
2629

2730
with LSP.Constants;
31+
with LSP.Enumerations;
2832
with LSP.Servers;
2933

3034
package body LSP.Ada_Handlers.Other_File_Commands is
@@ -85,13 +89,23 @@ package body LSP.Ada_Handlers.Other_File_Commands is
8589
File : constant GNATCOLL.VFS.Virtual_File :=
8690
Handler.To_File (Self.URI);
8791

88-
function Other_File return GNATCOLL.VFS.Virtual_File;
92+
function Get_Other_File
93+
(Success : out Boolean;
94+
Error_Msg : out VSS.Strings.Virtual_String)
95+
return GNATCOLL.VFS.Virtual_File;
96+
-- Return File's other file. If it does not exist,
97+
-- Success is set to False and it will return No_File,
98+
-- with an Error_Msg explaining why the other file could not be found.
8999

90-
----------------
91-
-- Other_File --
92-
----------------
100+
--------------------
101+
-- Get_Other_File --
102+
--------------------
93103

94-
function Other_File return GNATCOLL.VFS.Virtual_File is
104+
function Get_Other_File
105+
(Success : out Boolean;
106+
Error_Msg : out VSS.Strings.Virtual_String)
107+
return GNATCOLL.VFS.Virtual_File
108+
is
95109

96110
F : constant GPR2.Path_Name.Object := GPR2.Path_Name.Create (File);
97111

@@ -100,9 +114,12 @@ package body LSP.Ada_Handlers.Other_File_Commands is
100114
return GNATCOLL.VFS.Virtual_File;
101115
-- Return the other file, knowing that the original file was
102116
-- related to Unit.
117+
-- Return No_File if no other file has been found
118+
-- (e.g: when querying the other file of a package that has only a
119+
-- a specification file).
103120

104121
function Unit_For_File return GPR2.Build.Compilation_Unit.Object;
105-
-- File the Unit object corresponding to File.
122+
-- Return the Unit object corresponding to File
106123

107124
--------------------------
108125
-- Other_File_From_Unit --
@@ -115,8 +132,11 @@ package body LSP.Ada_Handlers.Other_File_Commands is
115132
Spec_File : Virtual_File;
116133
Body_File : Virtual_File;
117134
begin
118-
Spec_File := Unit.Spec.Source.Virtual_File;
119-
Body_File := Unit.Main_Body.Source.Virtual_File;
135+
Spec_File := (if Unit.Has_Part (S_Spec) then
136+
Unit.Spec.Source.Virtual_File else No_File);
137+
Body_File := (if Unit.Has_Part (S_Body) then
138+
Unit.Main_Body.Source.Virtual_File else No_File);
139+
120140
if File = Spec_File then
121141
return Body_File;
122142
else
@@ -128,48 +148,141 @@ package body LSP.Ada_Handlers.Other_File_Commands is
128148
-- Unit_For_File --
129149
-------------------
130150

131-
function Unit_For_File return GPR2.Build.Compilation_Unit.Object is
151+
function Unit_For_File
152+
return GPR2.Build.Compilation_Unit.Object is
132153
begin
133154
-- Check in the root project's closure for a visible source
134155
-- corresponding to this file.
135156
-- Not that the root's project closure includes the runtime.
136157
if Handler.Project_Tree.Is_Defined then
137158
declare
138-
View : constant GPR2.Project.View.Object :=
159+
View : constant GPR2.Project.View.Object :=
139160
Handler.Project_Tree.Root_Project;
140-
Unit_Info : constant GPR2.Build.Unit_Info.Object :=
141-
View.Visible_Source (F.Simple_Name).Unit;
142-
Unit : GPR2.Build.Compilation_Unit.Object :=
161+
Visible_Source : constant GPR2.Build.Source.Object :=
162+
View.Visible_Source (F.Simple_Name);
163+
Unit : GPR2.Build.Compilation_Unit.Object :=
143164
GPR2.Build.Compilation_Unit.Undefined;
144165
begin
145-
if Unit_Info.Is_Defined then
146-
Unit := View.Namespace_Roots.First_Element.Unit
147-
(Unit_Info.Name);
166+
-- The source is not visible from the root project (e.g:
167+
-- when querying the other file of an Ada file that
168+
-- does not belong to the loaded project).
169+
if not Visible_Source.Is_Defined then
170+
return GPR2.Build.Compilation_Unit.Undefined;
148171
end if;
149172

150-
return Unit;
173+
declare
174+
Unit_Info : constant GPR2.Build.Unit_Info.Object :=
175+
Visible_Source.Unit;
176+
begin
177+
if Unit_Info.Is_Defined then
178+
Unit :=
179+
View.Namespace_Roots.First_Element.Unit
180+
(Unit_Info.Name);
181+
end if;
182+
183+
return Unit;
184+
end;
151185
end;
152186
else
153187
return GPR2.Build.Compilation_Unit.Undefined;
154188
end if;
155189
end Unit_For_File;
156190

191+
Unit : constant GPR2.Build.Compilation_Unit.Object := Unit_For_File;
192+
Other_File : Virtual_File;
157193
begin
158-
return Other_File_From_Unit (Unit_For_File);
159-
end Other_File;
160-
161-
URI : constant LSP.Structures.DocumentUri :=
162-
Handler.To_URI (Other_File.Display_Full_Name);
194+
Success := True;
195+
196+
-- The unit is defined for the loaded project: fallback to a simple
197+
-- heuristic which tries to deduce the other file from the queried
198+
-- file, switching the specification/implementation extensions at
199+
-- the end of the filename.
200+
-- If the computed other file's URI does not exist, the client will
201+
-- simply not open it, which is ok.
202+
203+
if not Unit.Is_Defined then
204+
declare
205+
Impl_Suffix_Attr_Id : constant GPR2.Q_Optional_Attribute_Id :=
206+
((Pack => GPR2."+" ("Naming"),
207+
Attr => GPR2."+" ("Implementation_Suffix")));
208+
Spec_Suffix_Attr_Id : constant GPR2.Q_Optional_Attribute_Id :=
209+
((Pack => GPR2."+" ("Naming"),
210+
Attr => GPR2."+" ("Specification_Suffix")));
211+
Spec_Ext : constant String :=
212+
LSP.Ada_Contexts.Project_Attribute_Value
213+
(View => Handler.Project_Tree.Root_Project,
214+
Attribute => Spec_Suffix_Attr_Id,
215+
Index => "ada",
216+
Default => ".ads",
217+
Use_Extended => True);
218+
Impl_Ext : constant String :=
219+
LSP.Ada_Contexts.Project_Attribute_Value
220+
(View => Handler.Project_Tree.Root_Project,
221+
Attribute => Impl_Suffix_Attr_Id,
222+
Index => "ada",
223+
Default => ".adb",
224+
Use_Extended => True);
225+
begin
226+
if GNATCOLL.Utils.Ends_With
227+
(File.Display_Full_Name, Impl_Ext)
228+
then
229+
return GNATCOLL.VFS.Create
230+
(Full_Filename => +GNATCOLL.Utils.Replace
231+
(S => File.Display_Full_Name,
232+
Pattern => Impl_Ext,
233+
Replacement => Spec_Ext));
234+
else
235+
return GNATCOLL.VFS.Create
236+
(Full_Filename => +GNATCOLL.Utils.Replace
237+
(S => File.Display_Full_Name,
238+
Pattern => Spec_Ext,
239+
Replacement => Impl_Ext));
240+
end if;
241+
end;
242+
else
243+
Other_File := Other_File_From_Unit (Unit => Unit);
244+
245+
if Other_File = No_File then
246+
Success := False;
247+
Error_Msg :=
248+
VSS.Strings.Conversions.To_Virtual_String
249+
("Could not find other file for '"
250+
& File.Display_Base_Name
251+
& "': the unit has no other part.");
252+
end if;
163253

164-
Message : constant LSP.Structures.ShowDocumentParams :=
165-
(uri => (VSS.Strings.Virtual_String (URI) with null record),
166-
takeFocus => LSP.Constants.True,
167-
others => <>);
254+
return Other_File;
255+
end if;
256+
end Get_Other_File;
168257

169-
New_Id : constant LSP.Structures.Integer_Or_Virtual_String :=
170-
Handler.Server.Allocate_Request_Id;
258+
Success : Boolean;
259+
Error_Msg : VSS.Strings.Virtual_String;
260+
Other_File : constant Virtual_File :=
261+
Get_Other_File (Success, Error_Msg);
171262
begin
172-
Handler.Sender.On_ShowDocument_Request (New_Id, Message);
263+
if not Success then
264+
Error :=
265+
(Is_Set => True,
266+
Value =>
267+
(code => LSP.Enumerations.InternalError,
268+
message => Error_Msg));
269+
return;
270+
end if;
271+
272+
declare
273+
URI : constant LSP.Structures.DocumentUri :=
274+
Handler.To_URI (Other_File.Display_Full_Name);
275+
276+
Message : constant LSP.Structures.ShowDocumentParams :=
277+
(uri => (VSS.Strings.Virtual_String (URI) with null record),
278+
takeFocus => LSP.Constants.True,
279+
others => <>);
280+
281+
New_Id : constant LSP.Structures.Integer_Or_Virtual_String :=
282+
Handler.Server.Allocate_Request_Id;
283+
begin
284+
Handler.Sender.On_ShowDocument_Request (New_Id, Message);
285+
end;
173286
end Execute;
174287

175288
----------------

source/ada/lsp-ada_project_loading.adb

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ package body LSP.Ada_Project_Loading is
8686
("The project file has errors and could not be loaded.");
8787
when Valid_Project_With_Warning =>
8888
return VSS.Strings.To_Virtual_String
89-
("The project file was loaded but contains Warnings.");
89+
("The project file was loaded but contains warnings.");
9090
end case;
9191
end Load_Status_Message;
9292

@@ -159,17 +159,7 @@ package body LSP.Ada_Project_Loading is
159159
Parent_Diagnostic.source := "ada.project";
160160
Parent_Diagnostic.severity :=
161161
(True, Load_Status_Severity (Project));
162-
163-
Parent_Diagnostic.message := "Project Problems";
164-
Parent_Diagnostic.relatedInformation.Append
165-
(LSP.Structures.DiagnosticRelatedInformation'
166-
(location =>
167-
LSP.Structures.Location'
168-
(uri => Project_URI,
169-
a_range => Backup_Sloc,
170-
others => <>),
171-
message =>
172-
Load_Status_Message (Project)));
162+
Parent_Diagnostic.message := Load_Status_Message (Project);
173163
end Create_Project_Loading_Diagnostic;
174164

175165
-----------------------------
@@ -178,7 +168,6 @@ package body LSP.Ada_Project_Loading is
178168

179169
procedure Append_GPR2_Diagnostics is
180170
use GPR2.Message;
181-
use LSP.Enumerations;
182171
begin
183172
for Msg of GPR2_Messages loop
184173
if Msg.Level in GPR2.Message.Warning .. GPR2.Message.Error then
@@ -206,19 +195,6 @@ package body LSP.Ada_Project_Loading is
206195
(Msg.Message)));
207196
end if;
208197
end;
209-
210-
-- If we have one error in the GPR2 messages, the parent
211-
-- diagnostic's severity should be "error" too, otherwise
212-
-- "warning".
213-
if Msg.Level = GPR2.Message.Error then
214-
Parent_Diagnostic.severity :=
215-
(True, LSP.Enumerations.Error);
216-
elsif Parent_Diagnostic.severity.Value /=
217-
LSP.Enumerations.Error
218-
then
219-
Parent_Diagnostic.severity :=
220-
(True, LSP.Enumerations.Warning);
221-
end if;
222198
end if;
223199
end loop;
224200
end Append_GPR2_Diagnostics;
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package A with Pure is
2+
end A;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Main is
2+
begin
3+
null;
4+
end Main;

0 commit comments

Comments
 (0)