11-- ----------------------------------------------------------------------------
22-- Language Server Protocol --
33-- --
4- -- Copyright (C) 2023, AdaCore --
4+ -- Copyright (C) 2023-2024 , AdaCore --
55-- --
66-- This is free software; you can redistribute it and/or modify it under --
77-- terms of the GNU General Public License as published by the Free Soft- --
@@ -27,6 +27,7 @@ with Gpr_Parser.Common;
2727with Gpr_Parser_Support.Text ;
2828
2929with LSP.Structures.LSPAny_Vectors ;
30+ with LSP.Text_Documents.Langkit_Documents ;
3031
3132with VSS.String_Vectors ;
3233with VSS.Strings.Conversions ;
@@ -40,6 +41,7 @@ package body LSP.GPR_Completions is
4041 package PRAD renames GPR2.Project.Registry.Attribute.Description;
4142 package PRP renames GPR2.Project.Registry.Pack;
4243 package PRPD renames GPR2.Project.Registry.Pack.Description;
44+ package LKD renames LSP.Text_Documents.Langkit_Documents;
4345
4446 procedure Fill_Attribute_Completion_Response
4547 (File : LSP.GPR_Files.File;
@@ -187,10 +189,19 @@ package body LSP.GPR_Completions is
187189 (File_Provider => File_Provider,
188190 Path => File_Provider.To_File
189191 (Value.textDocument.uri));
190- Current : constant GPC.Token_Reference := File.Token (Value.position);
192+
193+ Location : constant Gpr_Parser.Slocs.Source_Location :=
194+ LSP.GPR_Files.To_Langkit_Location
195+ (LKD.To_Source_Location
196+ (Line_Text => File.Get_Line
197+ (LKD.To_Source_Line (Value.position.line)),
198+ Position => Value.position));
199+
200+ Current : constant GPC.Token_Reference := File.Token (Location);
201+
191202 In_Comment : constant Boolean :=
192- LSP.GPR_Files.Position_Is_In_Comment
193- (Current, Value.position);
203+ LSP.GPR_Files.Position_Is_In_Comment (Current, Location);
204+
194205 Previous : constant GPC.Token_Reference := Current.Previous (True);
195206
196207 function To_String
@@ -207,7 +218,8 @@ package body LSP.GPR_Completions is
207218 and then Previous /= GPC.No_Token
208219 then
209220 if Previous.Data.Kind in GPC.Gpr_For | GPC.Gpr_Package then
210- if not LSP.GPR_Files.At_End (Previous, Value.position) then
221+ if not LSP.GPR_Files.At_End (Previous.Data.Sloc_Range, Location)
222+ then
211223 case Previous.Data.Kind is
212224
213225 when GPC.Gpr_For =>
@@ -232,7 +244,8 @@ package body LSP.GPR_Completions is
232244 end if ;
233245
234246 elsif Previous.Data.Kind = GPC.Gpr_Identifier
235- and then LSP.GPR_Files.At_End (Previous, Value.position)
247+ and then LSP.GPR_Files.At_End
248+ (Previous.Data.Sloc_Range, Location)
236249 then
237250 declare
238251 Before_Identifier : constant GPC.Token_Reference :=
0 commit comments