Skip to content

Commit 3c10bc5

Browse files
author
Philippe Gil
committed
textDocument/definition request implementation
Part of eng/ide/ada_language_server#1223
1 parent dcbc798 commit 3c10bc5

18 files changed

+2109
-277
lines changed

source/gpr/lsp-gpr_completions.adb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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;
2727
with Gpr_Parser_Support.Text;
2828

2929
with LSP.Structures.LSPAny_Vectors;
30+
with LSP.Text_Documents.Langkit_Documents;
3031

3132
with VSS.String_Vectors;
3233
with 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 :=

source/gpr/lsp-gpr_documentation.adb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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- --
@@ -21,6 +21,9 @@ with Gpr_Parser.Common;
2121

2222
with GPR2.Project.Registry.Attribute.Description;
2323
with GPR2.Project.Registry.Pack.Description;
24+
25+
with LSP.Text_Documents.Langkit_Documents;
26+
2427
with VSS.Strings.Conversions;
2528

2629
package body LSP.GPR_Documentation is
@@ -31,7 +34,16 @@ package body LSP.GPR_Documentation is
3134
Tooltip_Text : out VSS.Strings.Virtual_String) is
3235
use Gpr_Parser.Common;
3336

34-
Token : constant Token_Reference := Self.Token (Position);
37+
package LKD renames LSP.Text_Documents.Langkit_Documents;
38+
39+
Location : constant Gpr_Parser.Slocs.Source_Location :=
40+
LSP.GPR_Files.To_Langkit_Location
41+
(LKD.To_Source_Location
42+
(Line_Text => Self.Get_Line
43+
(LKD.To_Source_Line (Position.line)),
44+
Position => Position));
45+
46+
Token : constant Token_Reference := Self.Token (Location);
3547

3648
use GPR2.Project.Registry.Attribute.Description;
3749
use GPR2.Project.Registry.Pack.Description;

source/gpr/lsp-gpr_file_readers.adb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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- --
@@ -36,7 +36,6 @@ with VSS.Strings.Converters.Decoders;
3636
with VSS.Strings.Conversions;
3737

3838
with LSP.GPR_Documents; use LSP.GPR_Documents;
39-
with LSP.Structures;
4039
with URIs;
4140

4241
with Langkit_Support.Text;
@@ -67,8 +66,6 @@ package body LSP.GPR_File_Readers is
6766
-- present
6867
-- Default flags for the text decoder.
6968

70-
function To_URI (Item : String) return LSP.Structures.DocumentUri;
71-
7269
------------
7370
-- Create --
7471
------------

source/gpr/lsp-gpr_file_readers.ads

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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- --
@@ -22,6 +22,7 @@ with GPR2.File_Readers;
2222
with GPR2.Log;
2323

2424
with LSP.GPR_Handlers;
25+
with LSP.Structures;
2526

2627
package LSP.GPR_File_Readers is
2728

@@ -42,6 +43,8 @@ package LSP.GPR_File_Readers is
4243
(Handler : access LSP.GPR_Handlers.Message_Handler)
4344
return GPR2.File_Readers.File_Reader_Reference;
4445

46+
function To_URI (Item : String) return LSP.Structures.DocumentUri;
47+
4548
private
4649

4750
type File_Reader is new GPR2.File_Readers.File_Reader_Interface with

0 commit comments

Comments
 (0)