Skip to content

Commit 6752d74

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents e21aea7 + 635eb9c commit 6752d74

18 files changed

+418
-67
lines changed

.vscode/settings.json.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@
8080
"triggerTaskOnSave.tasks": {
8181
// To work with automatically provided tasks, they
8282
// must be provided without the `ada: ` prefix.
83-
"Compile current file": ["*.adb"],
84-
"Check current file": ["*.ads"]
83+
"Check current file": ["*.ads", "*.adb"]
8584
},
8685
"triggerTaskOnSave.restart": true,
8786
"files.watcherExclude": {

source/ada/lsp-ada_contexts.adb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ package body LSP.Ada_Contexts is
485485
Callback : not null access procedure
486486
(File : GNATCOLL.VFS.Virtual_File;
487487
Name : Libadalang.Analysis.Defining_Name;
488-
Stop : in out Boolean))
488+
Stop : in out Boolean);
489+
Unit_Prefix : VSS.Strings.Virtual_String :=
490+
VSS.Strings.Empty_Virtual_String)
489491
is
490492
function Get_Defining_Name
491493
(File : GNATCOLL.VFS.Virtual_File;
@@ -512,7 +514,11 @@ package body LSP.Ada_Contexts is
512514

513515
begin
514516
Self.Source_Files.Get_Any_Symbol
515-
(Pattern, Only_Public, Get_Defining_Name'Access, Callback);
517+
(Pattern => Pattern,
518+
Only_Public => Only_Public,
519+
Get_Defining_Name => Get_Defining_Name'Access,
520+
Callback => Callback,
521+
Unit_Prefix => Unit_Prefix);
516522
end Get_Any_Symbol;
517523

518524
-----------------

source/ada/lsp-ada_contexts.ads

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,15 @@ package LSP.Ada_Contexts is
245245
Callback : not null access procedure
246246
(File : GNATCOLL.VFS.Virtual_File;
247247
Name : Libadalang.Analysis.Defining_Name;
248-
Stop : in out Boolean));
248+
Stop : in out Boolean);
249+
Unit_Prefix : VSS.Strings.Virtual_String :=
250+
VSS.Strings.Empty_Virtual_String);
249251
-- Find symbols starting with given Prefix in all files of the context and
250252
-- call Callback for each. Name could contain a stale reference if the File
251253
-- was updated since last indexing operation. If Only_Public is True it
252254
-- will skip any "private" symbols (like symbols in private part or body).
255+
-- Unit_Prefix is used for additional filtering: when specified, only the
256+
-- symbols declared in this non-visible unit will be returned.
253257

254258
function Charset (Self : Context) return String;
255259
-- Return the charset for this context

source/ada/lsp-ada_driver.adb

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ with LSP.Ada_Handlers.Source_Dirs_Commands;
7474
with LSP.Ada_Handlers.Suspend_Executions;
7575
with LSP.Ada_Tokens_Full;
7676
with LSP.Ada_Tokens_Range;
77+
with LSP.Default_Message_Handlers;
7778
with LSP.GNATCOLL_Trace_Streams;
7879
with LSP.GNATCOLL_Tracers;
7980
with LSP.GPR_Handlers;
@@ -82,14 +83,20 @@ with LSP.GPR_Did_Change_Document;
8283
with LSP.Memory_Statistics;
8384
with LSP.Predefined_Completion;
8485
with LSP.Secure_Message_Loggers;
86+
with LSP.Server_Jobs;
8587
with LSP.Server_Notifications.DidChange;
8688
with LSP.Server_Notifications.DidChangeConfiguration;
87-
with LSP.Server_Requests.Definition;
89+
with LSP.Server_Notifications.DidChangeWorkspaceFolders;
90+
with LSP.Server_Notifications.DidClose;
91+
with LSP.Server_Notifications.DidOpen;
92+
with LSP.Server_Notifications.Exits;
8893
with LSP.Server_Requests.Declaration;
94+
with LSP.Server_Requests.Definition;
8995
with LSP.Server_Requests.DocumentSymbol;
9096
with LSP.Server_Requests.ExecuteCommand;
9197
with LSP.Server_Requests.FoldingRange;
9298
with LSP.Server_Requests.Hover;
99+
with LSP.Server_Requests.Initialize;
93100
with LSP.Server_Requests.References;
94101
with LSP.Server_Requests.Tokens_Full;
95102
with LSP.Server_Requests.Tokens_Range;
@@ -232,6 +239,10 @@ procedure LSP.Ada_Driver is
232239
LSP.Ada_Tokens_Range.Ada_Tokens_Range_Handler
233240
(Ada_Handler'Unchecked_Access);
234241

242+
Ada_Fence_Message_Handler : aliased
243+
LSP.Default_Message_Handlers.Default_Message_Handler;
244+
-- A shared handler with Fense priority
245+
235246
GPR_Did_Change_Doc_Handler : aliased
236247
LSP.GPR_Did_Change_Document.GPR_Did_Change_Handler
237248
(GPR_Handler'Unchecked_Access);
@@ -451,6 +462,30 @@ begin
451462
LSP.Predefined_Completion.Load_Predefined_Completion_Db
452463
(Server_Trace);
453464

465+
Ada_Fence_Message_Handler.Initialize
466+
(Handler => Ada_Handler'Unchecked_Access,
467+
Priority => LSP.Server_Jobs.Fence);
468+
469+
Server.Register_Handler
470+
(LSP.Server_Requests.Initialize.Request'Tag,
471+
Ada_Fence_Message_Handler'Unchecked_Access);
472+
473+
Server.Register_Handler
474+
(LSP.Server_Notifications.DidOpen.Notification'Tag,
475+
Ada_Fence_Message_Handler'Unchecked_Access);
476+
477+
Server.Register_Handler
478+
(LSP.Server_Notifications.DidClose.Notification'Tag,
479+
Ada_Fence_Message_Handler'Unchecked_Access);
480+
481+
Server.Register_Handler
482+
(LSP.Server_Notifications.DidChangeWorkspaceFolders.Notification'Tag,
483+
Ada_Fence_Message_Handler'Unchecked_Access);
484+
485+
Server.Register_Handler
486+
(LSP.Server_Notifications.Exits.Notification'Tag,
487+
Ada_Fence_Message_Handler'Unchecked_Access);
488+
454489
Server.Register_Handler
455490
(LSP.Server_Notifications.DidChangeConfiguration.Notification'Tag,
456491
Ada_Did_Change_Handler'Unchecked_Access);
@@ -501,7 +536,8 @@ begin
501536
In_Logger => (if In_Trace.Is_Active
502537
then In_Logger'Unchecked_Access else null),
503538
Out_Logger => (if Out_Trace.Is_Active
504-
then Out_Logger'Unchecked_Access else null));
539+
then Out_Logger'Unchecked_Access else null),
540+
Priority => LSP.Server_Jobs.Low);
505541
end if;
506542
exception
507543
when E : others =>

source/ada/lsp-ada_file_sets.adb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
------------------------------------------------------------------------------
1717

1818
with Langkit_Support.Symbols; use Langkit_Support.Symbols;
19+
with Langkit_Support.Text;
1920
with Libadalang.Common; use Libadalang.Common;
2021
with Libadalang.Iterators;
2122
with Libadalang.Sources;
2223

2324
with LSP.Predicates;
2425

26+
with VSS.Strings.Conversions;
27+
2528
package body LSP.Ada_File_Sets is
2629

2730
procedure Flush_File_Index
@@ -91,7 +94,9 @@ package body LSP.Ada_File_Sets is
9194
Callback : not null access procedure
9295
(File : GNATCOLL.VFS.Virtual_File;
9396
Defining_Name : Libadalang.Analysis.Defining_Name;
94-
Stop : in out Boolean))
97+
Stop : in out Boolean);
98+
Unit_Prefix : VSS.Strings.Virtual_String :=
99+
VSS.Strings.Empty_Virtual_String)
95100
is
96101
use all type LSP.Search.Search_Kind;
97102

@@ -105,6 +110,29 @@ package body LSP.Ada_File_Sets is
105110
and then Pattern.Get_Whole_Word)
106111
or else Pattern.Get_Kind = Start_Word_Text);
107112

113+
function Matches_Unit_Prefix
114+
(Name : Libadalang.Analysis.Defining_Name'Class) return Boolean;
115+
-- Return true if the given defining name's unit matches the unit prefix
116+
-- given in parameter.
117+
118+
-------------------------
119+
-- Matches_Unit_Prefix --
120+
-------------------------
121+
122+
function Matches_Unit_Prefix
123+
(Name : Libadalang.Analysis.Defining_Name'Class) return Boolean
124+
is
125+
Unit_Root_Decl : constant Libadalang.Analysis.Basic_Decl :=
126+
Name.P_Enclosing_Compilation_Unit.P_Decl;
127+
Unit_Name : constant VSS.Strings.Virtual_String :=
128+
VSS.Strings.Conversions.To_Virtual_String
129+
(Langkit_Support.Text.To_UTF8
130+
(Unit_Root_Decl.P_Fully_Qualified_Name));
131+
begin
132+
return Unit_Prefix.Is_Empty
133+
or else Unit_Name.Starts_With (Unit_Prefix);
134+
end Matches_Unit_Prefix;
135+
108136
begin
109137
if Use_Celling then
110138
Cursor := Self.All_Symbols.Ceiling (Pattern.Get_Canonical_Pattern);
@@ -139,7 +167,9 @@ package body LSP.Ada_File_Sets is
139167
for Item of Self.All_Symbols (Cursor) loop
140168
if not Only_Public or else Item.Is_Public then
141169
Defining_Name := Get_Defining_Name (Item.File, Item.Loc);
142-
if not Defining_Name.Is_Null then
170+
if not Defining_Name.Is_Null
171+
and then Matches_Unit_Prefix (Defining_Name)
172+
then
143173
Callback (Item.File, Defining_Name, Stop);
144174
end if;
145175
end if;

source/ada/lsp-ada_file_sets.ads

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ package LSP.Ada_File_Sets is
8585
Callback : not null access procedure
8686
(File : GNATCOLL.VFS.Virtual_File;
8787
Defining_Name : Libadalang.Analysis.Defining_Name;
88-
Stop : in out Boolean));
88+
Stop : in out Boolean);
89+
Unit_Prefix : VSS.Strings.Virtual_String :=
90+
VSS.Strings.Empty_Virtual_String);
8991
-- Find symbols starting with given Prefix in all files of the set and
9092
-- call Callback for each. Get_Defining_Name callback is used for getting
9193
-- the Defining_Name at the given location Loc in a unit.

source/ada/lsp-ada_handlers-invisibles.adb

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with GNATCOLL;
19+
with GNATCOLL.Utils;
1820
with GNATCOLL.VFS;
1921

22+
with Langkit_Support.Text;
2023
with VSS.Strings;
2124

2225
with LSP.Enumerations;
@@ -39,8 +42,6 @@ package body LSP.Ada_Handlers.Invisibles is
3942
Result : in out LSP.Structures.CompletionList)
4043
is
4144
pragma Unreferenced (Result);
42-
use all type Libadalang.Common.Token_Kind;
43-
use all type Libadalang.Common.Token_Reference;
4445
use type Ada.Containers.Count_Type;
4546

4647
procedure On_Inaccessible_Name
@@ -79,22 +80,17 @@ package body LSP.Ada_Handlers.Invisibles is
7980
end if;
8081
end On_Inaccessible_Name;
8182

82-
Previous_Tok : constant Libadalang.Common.Token_Reference :=
83-
Libadalang.Common.Previous (Token, Exclude_Trivia => True);
84-
Dot_Token : constant Libadalang.Common.Token_Data_Type :=
85-
Libadalang.Common.Data
86-
(if Libadalang.Common.Is_Trivia (Token)
87-
and then Previous_Tok /= Libadalang.Common.No_Token
88-
then Previous_Tok
89-
else Token);
90-
9183
function Dummy_Canceled return Boolean is (False);
9284

85+
Unit_Prefix : VSS.Strings.Virtual_String;
86+
-- The unit prefix specified before the point of completion, if any
87+
-- (e.g: "Ada.Text_IO" when completing "Ada.Text_IO.").
88+
-- Used to filter invisible completion items: if there is a unit prefix,
89+
-- we want to show only the public symbols declared in this
90+
-- non-visible unit.
91+
9392
begin
94-
if Libadalang.Common.Kind (Dot_Token) = Ada_Dot then
95-
-- Don't provide completion after a dot
96-
return;
97-
elsif Filter.Is_Numeric_Literal
93+
if Filter.Is_Numeric_Literal
9894
or else Filter.Is_Attribute_Ref
9995
or else Filter.Is_Aspect
10096
or else Filter.Is_End_Label
@@ -111,8 +107,7 @@ package body LSP.Ada_Handlers.Invisibles is
111107
if Node.Is_Null or else
112108
(not Node.Parent.Is_Null and then Node.Parent.Kind in
113109
Libadalang.Common.Ada_Defining_Name_Range
114-
| Libadalang.Common.Ada_Dotted_Name_Range
115-
| Libadalang.Common.Ada_Ada_Node_List_Range)
110+
| Libadalang.Common.Ada_Ada_Node_List_Range)
116111
then
117112
return;
118113
end if;
@@ -123,6 +118,20 @@ package body LSP.Ada_Handlers.Invisibles is
123118
return;
124119
end if;
125120

121+
-- We are completing a dotted-name: check if we have a unit prefix
122+
if Node.Kind in Libadalang.Common.Ada_Dotted_Name_Range then
123+
declare
124+
Prefix : constant String :=
125+
Langkit_Support.Text.To_UTF8 (Node.Text);
126+
Dot_Idx : Integer := -1;
127+
begin
128+
Dot_Idx := GNATCOLL.Utils.Find_Char (Prefix, '.');
129+
Unit_Prefix :=
130+
VSS.Strings.Conversions.To_Virtual_String
131+
(Prefix (Prefix'First .. Dot_Idx - 1));
132+
end;
133+
end if;
134+
126135
declare
127136
Word : constant VSS.Strings.Virtual_String :=
128137
VSS.Strings.To_Virtual_String
@@ -146,7 +155,8 @@ package body LSP.Ada_Handlers.Invisibles is
146155
Self.Context.Get_Any_Symbol
147156
(Pattern => Pattern,
148157
Only_Public => True,
149-
Callback => On_Inaccessible_Name'Access);
158+
Callback => On_Inaccessible_Name'Access,
159+
Unit_Prefix => Unit_Prefix);
150160

151161
for Doc of Self.Handler.Open_Documents loop
152162
Doc.Get_Any_Symbol

source/ada/lsp-ada_handlers-project_diagnostics.adb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,26 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
143143
Sloc : constant GPR2.Source_Reference.Object :=
144144
GPR2.Message.Sloc (Msg);
145145
File : constant GPR2.Path_Name.Object :=
146-
(if Sloc.Is_Defined and then Sloc.Has_Source_Reference then
146+
(if Sloc.Is_Defined and then Sloc.Has_Source_Reference
147+
then
147148
GPR2.Path_Name.Create_File
148149
(GPR2.Filename_Type (Sloc.Filename))
149150
else
150151
Self.Handler.Project_Tree.Root_Project.Path_Name);
151152
begin
152-
Parent_Diagnostic.relatedInformation.Append
153-
(LSP .Structures.DiagnosticRelatedInformation'
154-
(location => LSP.Structures.Location'
155-
(uri => LSP.Utils.To_URI (File),
156-
a_range => LSP.Utils.To_Range (Sloc),
157-
others => <>),
158-
message => VSS.Strings.Conversions.To_Virtual_String
159-
(Msg.Message)));
153+
-- Display a diagnostic for GPR2 messages only if the file
154+
-- attached to the message is defined.
155+
if File.Is_Defined and then File.Has_Value then
156+
Parent_Diagnostic.relatedInformation.Append
157+
(LSP .Structures.DiagnosticRelatedInformation'
158+
(location => LSP.Structures.Location'
159+
(uri => LSP.Utils.To_URI (File),
160+
a_range => LSP.Utils.To_Range (Sloc),
161+
others => <>),
162+
message =>
163+
VSS.Strings.Conversions.To_Virtual_String
164+
(Msg.Message)));
165+
end if;
160166
end;
161167

162168
-- If we have one error in the GPR2 messages, the parent

0 commit comments

Comments
 (0)