Skip to content

Commit 0eaecc9

Browse files
BoulangerAdrienBoulanger
authored andcommitted
Change detection of sources using GPR2
LAL project provider is also using GPR2 Project_Tree and they are not been designed to support Update_Sources. The only solution is to do a full reload to recreate the contexts. Also add defensive code when trying to access the potential undefined source. Add missing blocking priority for didCreate/Rename/Delete-Files Add tests. Closes eng/ide/ada_language_server#1465
1 parent caaea3f commit 0eaecc9

File tree

15 files changed

+625
-156
lines changed

15 files changed

+625
-156
lines changed

source/ada/lsp-ada_driver.adb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ with LSP.Server_Notifications.DidChange;
9696
with LSP.Server_Notifications.DidChangeConfiguration;
9797
with LSP.Server_Notifications.DidChangeWorkspaceFolders;
9898
with LSP.Server_Notifications.DidClose;
99+
with LSP.Server_Notifications.DidCreateFiles;
100+
with LSP.Server_Notifications.DidDeleteFiles;
99101
with LSP.Server_Notifications.DidOpen;
102+
with LSP.Server_Notifications.DidRenameFiles;
100103
with LSP.Server_Notifications.Exits;
101104
with LSP.Server_Requests.Declaration;
102105
with LSP.Server_Requests.Definition;
@@ -626,6 +629,18 @@ begin
626629
(LSP.Server_Notifications.DidClose.Notification'Tag,
627630
Ada_Fence_Message_Handler'Unchecked_Access);
628631

632+
Server.Register_Handler
633+
(LSP.Server_Notifications.DidCreateFiles.Notification'Tag,
634+
Ada_Fence_Message_Handler'Unchecked_Access);
635+
636+
Server.Register_Handler
637+
(LSP.Server_Notifications.DidRenameFiles.Notification'Tag,
638+
Ada_Fence_Message_Handler'Unchecked_Access);
639+
640+
Server.Register_Handler
641+
(LSP.Server_Notifications.DidDeleteFiles.Notification'Tag,
642+
Ada_Fence_Message_Handler'Unchecked_Access);
643+
629644
Server.Register_Handler
630645
(LSP.Server_Notifications.DidChangeWorkspaceFolders.Notification'Tag,
631646
Ada_Fence_Message_Handler'Unchecked_Access);

source/ada/lsp-ada_handlers-other_file_commands.adb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ package body LSP.Ada_Handlers.Other_File_Commands is
166166
View : constant GPR2.Project.View.Object :=
167167
Handler.Project_Tree.Root_Project;
168168
Visible_Source : constant GPR2.Build.Source.Object :=
169-
View.Visible_Source (F.Simple_Name);
169+
(if View.Has_Source (F.Simple_Name)
170+
then View.Visible_Source (F.Simple_Name)
171+
else GPR2.Build.Source.Undefined);
170172
Unit : GPR2.Build.Compilation_Unit.Object :=
171173
GPR2.Build.Compilation_Unit.Undefined;
172174
begin

source/ada/lsp-ada_handlers.adb

Lines changed: 10 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,42 +1848,9 @@ package body LSP.Ada_Handlers is
18481848
begin
18491849
Self.Log_Method_In ("On_DidCreateFiles_Notification");
18501850

1851-
-- New sources were created on this project, so recompute its view
1852-
Self.Project_Tree.Clear_Sources;
1853-
1854-
-- For each created file of Value.files:
1855-
-- - find the contexts that contains its directory
1856-
-- - add it to those contexts
1857-
-- - index it on those contexts
1858-
1859-
for File of Value.files loop
1860-
declare
1861-
use VSS.Strings.Conversions;
1862-
1863-
Created_File : constant GNATCOLL.VFS.Virtual_File :=
1864-
Self.To_File (To_DocumentUri (File.uri));
1865-
1866-
function Has_Dir
1867-
(Context : LSP.Ada_Contexts.Context)
1868-
return Boolean
1869-
is (Context.List_Source_Directories.Contains
1870-
(Created_File.Dir));
1871-
-- Return True if Old_File is a source of the project held by
1872-
-- Context.
1873-
1874-
begin
1875-
for Context of Self.Contexts.Each_Context
1876-
(Has_Dir'Unrestricted_Access)
1877-
loop
1878-
Context.Include_File (Created_File);
1879-
Context.Index_File (Created_File);
1880-
1881-
Self.Tracer.Trace
1882-
("Included " & Created_File.Display_Base_Name
1883-
& " in context " & To_UTF_8_String (Context.Id));
1884-
end loop;
1885-
end;
1886-
end loop;
1851+
-- LAL Contexts are not handling source updates so we need a full reload
1852+
-- to avoid caching issues.
1853+
Self.Reload_Project;
18871854

18881855
Self.Log_Method_Out ("On_DidCreateFiles_Notification");
18891856
end On_DidCreateFiles_Notification;
@@ -1898,34 +1865,9 @@ package body LSP.Ada_Handlers is
18981865
begin
18991866
Self.Log_Method_In ("On_DidDeleteFiles_Notification");
19001867

1901-
-- Some project sources were deleted, so recompute its view
1902-
Self.Project_Tree.Clear_Sources;
1903-
1904-
-- For each delete file of Value.files:
1905-
-- - find the contexts that contains it
1906-
-- - remove it from those contexts
1907-
-- - re-index it on those contexts so that an empty unit is reparsed
1908-
1909-
for File of Value.files loop
1910-
declare
1911-
Deleted_URI : constant LSP.Structures.DocumentUri :=
1912-
To_DocumentUri (File.uri);
1913-
1914-
Deleted_File : constant GNATCOLL.VFS.Virtual_File :=
1915-
Self.To_File (Deleted_URI);
1916-
1917-
begin
1918-
for Context of Self.Contexts_For_File (Deleted_File) loop
1919-
Context.Exclude_File (Deleted_File);
1920-
Context.Index_File (Deleted_File);
1921-
1922-
Self.Tracer.Trace
1923-
("Excluded " & Deleted_File.Display_Base_Name
1924-
& " from context "
1925-
& VSS.Strings.Conversions.To_UTF_8_String (Context.Id));
1926-
end loop;
1927-
end;
1928-
end loop;
1868+
-- LAL Contexts are not handling source updates so we need a full reload
1869+
-- to avoid caching issues.
1870+
Self.Reload_Project;
19291871

19301872
Self.Log_Method_Out ("On_DidDeleteFiles_Notification");
19311873
end On_DidDeleteFiles_Notification;
@@ -1995,100 +1937,13 @@ package body LSP.Ada_Handlers is
19951937

19961938
overriding procedure On_DidRenameFiles_Notification
19971939
(Self : in out Message_Handler;
1998-
Value : LSP.Structures.RenameFilesParams)
1999-
is
2000-
use LSP.Ada_Context_Sets;
2001-
2002-
package URI_Contexts_Maps is new
2003-
Ada.Containers.Hashed_Maps
2004-
(Key_Type => LSP.Structures.DocumentUri,
2005-
Element_Type => Context_Lists.List,
2006-
Hash => LSP.Structures.Get_Hash,
2007-
Equivalent_Keys => LSP.Structures."=",
2008-
"=" => Context_Lists."=");
2009-
2010-
subtype URI_Contexts_Map is URI_Contexts_Maps.Map;
2011-
2012-
URIs_Contexts : URI_Contexts_Map;
2013-
1940+
Value : LSP.Structures.RenameFilesParams) is
20141941
begin
20151942
Self.Log_Method_In ("On_DidRenameFiles_Notification");
20161943

2017-
-- Some project sources were renamed, so recompute its view
2018-
Self.Project_Tree.Clear_Sources;
2019-
2020-
-- For each oldUri of Value.files:
2021-
-- - map it to a list of context that contains it
2022-
-- - remove it from those contexts
2023-
-- - re-index it on those contexts so that an empty unit is reparsed
2024-
2025-
for File_Rename of Value.files loop
2026-
declare
2027-
use VSS.Strings.Conversions;
2028-
2029-
Old_URI : constant LSP.Structures.DocumentUri :=
2030-
To_DocumentUri (File_Rename.oldUri);
2031-
2032-
Old_File : constant GNATCOLL.VFS.Virtual_File :=
2033-
Self.To_File (Old_URI);
2034-
2035-
URI_Contexts : Context_Lists.List;
2036-
2037-
begin
2038-
for Context of Self.Contexts_For_File (Old_File) loop
2039-
URI_Contexts.Append (Context);
2040-
Context.Exclude_File (Old_File);
2041-
Context.Index_File (Old_File);
2042-
2043-
Self.Tracer.Trace
2044-
("Excluded " & Old_File.Display_Full_Name
2045-
& " from context " & To_UTF_8_String (Context.Id));
2046-
end loop;
2047-
2048-
URIs_Contexts.Insert (Old_URI, URI_Contexts);
2049-
end;
2050-
end loop;
2051-
2052-
-- For each (oldUri, newUri) tuple:
2053-
-- - add newUri to all contexts that contained oldUri
2054-
-- - index the newUri (using the appriate method depending if
2055-
-- (there's an open document of not)
2056-
2057-
for File_Rename of Value.files loop
2058-
declare
2059-
use VSS.Strings.Conversions;
2060-
use type LSP.Ada_Documents.Document_Access;
2061-
2062-
New_URI : constant LSP.Structures.DocumentUri :=
2063-
To_DocumentUri (File_Rename.newUri);
2064-
2065-
Old_URI : constant LSP.Structures.DocumentUri :=
2066-
To_DocumentUri (File_Rename.oldUri);
2067-
2068-
New_File : constant GNATCOLL.VFS.Virtual_File :=
2069-
Self.To_File (New_URI);
2070-
2071-
Document : constant LSP.Ada_Documents.Document_Access :=
2072-
Get_Open_Document (Self, New_URI);
2073-
2074-
Is_Document_Open : constant Boolean := Document /= null;
2075-
2076-
begin
2077-
for Context of URIs_Contexts (Old_URI) loop
2078-
Context.Include_File (New_File);
2079-
2080-
if Is_Document_Open then
2081-
Context.Index_Document (Document.all);
2082-
else
2083-
Context.Index_File (New_File);
2084-
end if;
2085-
2086-
Self.Tracer.Trace
2087-
("Included " & New_File.Display_Base_Name & " in context "
2088-
& To_UTF_8_String (Context.Id));
2089-
end loop;
2090-
end;
2091-
end loop;
1944+
-- LAL Contexts are not handling source updates so we need a full reload
1945+
-- to avoid caching issues.
1946+
Self.Reload_Project;
20921947

20931948
Self.Log_Method_Out ("On_DidRenameFiles_Notification");
20941949
end On_DidRenameFiles_Notification;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
with Foo;
2+
procedure Main is
3+
begin
4+
Foo.Bar;
5+
end Main;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Foo is
2+
3+
procedure Bar;
4+
5+
end Foo;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package body Foo is
2+
3+
procedure Bar is
4+
begin
5+
null;
6+
end Bar;
7+
8+
end Foo;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project Test is
2+
3+
for Source_Dirs use (".", "src1", "src2");
4+
5+
package Naming is
6+
for Spec_Suffix ("Ada") use ".1.ada";
7+
end Naming;
8+
9+
end Test;

0 commit comments

Comments
 (0)