Skip to content

Commit e4996a5

Browse files
committed
Merge branch 'topic/inline_val' into 'master'
Implementation of the `inlineValues` request See merge request eng/ide/ada_language_server!2017
2 parents 88b7faf + 2a657e0 commit e4996a5

14 files changed

+787
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ section below it for the last release. -->
66
## \<next>
77

88
* Added `onEnterRules` for Ada/GPR files to split long comments by adding automatically a comment tag to the next line
9+
* Added support for new LSP request `textDocument/inlineValue`
910

1011
## 26.0.202504171
1112

liblsp_3_17/source/lsp-constants.ads

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ package LSP.Constants is
3535
return LSP.Structures.implementationProvider_OfServerCapabilities_Optional
3636
is (Is_Set => True, Value => True);
3737

38+
function True
39+
return LSP.Structures.inlineValueProvider_OfServerCapabilities
40+
is (Kind => LSP.Structures.Variant_1, Variant_1 => True);
41+
42+
function True
43+
return LSP.Structures.inlineValueProvider_OfServerCapabilities_Optional
44+
is (Is_Set => True, Value => True);
45+
3846
function True
3947
return LSP.Structures.declarationProvider_OfServerCapabilities
4048
is (Kind => LSP.Structures.Variant_1, Variant_1 => True);

source/ada/lsp-ada_client_capabilities.adb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ package body LSP.Ada_Client_Capabilities is
418418
Result.foldingRangeProvider := LSP.Constants.True;
419419
Result.hoverProvider := LSP.Constants.True;
420420
Result.implementationProvider := LSP.Constants.True;
421+
Result.inlineValueProvider := LSP.Constants.True;
421422
Result.referencesProvider := LSP.Constants.True;
422423
Result.selectionRangeProvider := LSP.Constants.True;
423424
Result.typeDefinitionProvider := LSP.Constants.True;

source/ada/lsp-ada_driver.adb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ with LSP.Ada_Handlers.Refactor.Suppress_Seperate;
7979
with LSP.Ada_Handlers.Show_Dependencies_Commands;
8080
with LSP.Ada_Handlers.Source_Dirs_Commands;
8181
with LSP.Ada_Handlers.Suspend_Executions;
82+
with LSP.Ada_Inline_Value;
8283
with LSP.Ada_Selection_Range;
8384
with LSP.Ada_Tokens_Full;
8485
with LSP.Ada_Tokens_Range;
@@ -111,6 +112,7 @@ with LSP.Server_Requests.ExecuteCommand;
111112
with LSP.Server_Requests.FoldingRange;
112113
with LSP.Server_Requests.Hover;
113114
with LSP.Server_Requests.Initialize;
115+
with LSP.Server_Requests.InlineValue;
114116
with LSP.Server_Requests.PrepareTypeHierarchy;
115117
with LSP.Server_Requests.References;
116118
with LSP.Server_Requests.SelectionRange;
@@ -308,6 +310,10 @@ procedure LSP.Ada_Driver is
308310
LSP.Ada_Selection_Range.Ada_Selection_Range_Handler
309311
(Ada_Handler'Unchecked_Access);
310312

313+
Ada_Inline_Value_Handler : aliased
314+
LSP.Ada_Inline_Value.Ada_Inline_Value_Handler
315+
(Ada_Handler'Unchecked_Access);
316+
311317
Ada_Tokens_Full_Handler : aliased
312318
LSP.Ada_Tokens_Full.Ada_Tokens_Full_Handler
313319
(Ada_Handler'Unchecked_Access);
@@ -689,6 +695,10 @@ begin
689695
(LSP.Server_Requests.SelectionRange.Request'Tag,
690696
Ada_Selection_Range_Handler'Unchecked_Access);
691697

698+
Server.Register_Handler
699+
(LSP.Server_Requests.InlineValue.Request'Tag,
700+
Ada_Inline_Value_Handler'Unchecked_Access);
701+
692702
Server.Register_Handler
693703
(LSP.Server_Requests.Tokens_Full.Request'Tag,
694704
Ada_Tokens_Full_Handler'Unchecked_Access);

source/ada/lsp-ada_handlers-locations.adb

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ package body LSP.Ada_Handlers.Locations is
3131
Sloc : Langkit_Support.Slocs.Source_Location_Range)
3232
return LSP.Structures.A_Range;
3333

34+
function From_LSP_Range
35+
(Unit : Libadalang.Analysis.Analysis_Unit;
36+
Sloc : LSP.Structures.A_Range)
37+
return Langkit_Support.Slocs.Source_Location_Range;
38+
3439
---------------------
3540
-- Append_Location --
3641
---------------------
@@ -80,6 +85,99 @@ package body LSP.Ada_Handlers.Locations is
8085
end if;
8186
end Append_Location;
8287

88+
--------------------
89+
-- From_LSP_Range --
90+
--------------------
91+
92+
function From_LSP_Range
93+
(Self : in out Message_Handler'Class;
94+
Unit : Libadalang.Analysis.Analysis_Unit;
95+
Sloc : LSP.Structures.A_Range)
96+
return Langkit_Support.Slocs.Source_Location_Range
97+
is
98+
use type LSP.Ada_Documents.Document_Access;
99+
100+
URI : constant LSP.Structures.DocumentUri :=
101+
(VSS.Strings.Conversions.To_Virtual_String
102+
(URIs.Conversions.From_File (Unit.Get_Filename))
103+
with null record);
104+
105+
Doc : constant LSP.Ada_Documents.Document_Access :=
106+
Self.Get_Open_Document (URI);
107+
108+
begin
109+
if Doc /= null then
110+
return Doc.To_Source_Location_Range (Sloc);
111+
112+
else
113+
return From_LSP_Range (Unit, Sloc);
114+
end if;
115+
end From_LSP_Range;
116+
117+
--------------------
118+
-- From_LSP_Range --
119+
--------------------
120+
121+
function From_LSP_Range
122+
(Unit : Libadalang.Analysis.Analysis_Unit;
123+
Sloc : LSP.Structures.A_Range)
124+
return Langkit_Support.Slocs.Source_Location_Range
125+
is
126+
use type Langkit_Support.Slocs.Column_Number;
127+
128+
Result : Langkit_Support.Slocs.Source_Location_Range :=
129+
(Start_Line => Positive'Pos (Sloc.start.line + 1),
130+
End_Line => Positive'Pos (Sloc.an_end.line + 1),
131+
others => 0);
132+
begin
133+
declare
134+
Line : constant VSS.Strings.Virtual_String :=
135+
VSS.Strings.To_Virtual_String
136+
(Unit.Get_Line (Sloc.start.line + 1));
137+
138+
Cursor : VSS.Strings.Character_Iterators.Character_Iterator :=
139+
Line.Before_First_Character;
140+
141+
begin
142+
while Cursor.Forward and then
143+
Natural (Cursor.First_UTF16_Offset) <= Sloc.start.character
144+
loop
145+
Result.Start_Column := @ + 1;
146+
end loop;
147+
148+
if Sloc.start.line = Sloc.an_end.line then
149+
150+
Result.End_Column := Result.Start_Column;
151+
152+
while Cursor.Forward and then
153+
Natural (Cursor.First_UTF16_Offset) <= Sloc.an_end.character
154+
loop
155+
Result.End_Column := @ + 1;
156+
end loop;
157+
158+
return Result;
159+
end if;
160+
end;
161+
162+
declare
163+
Line : constant VSS.Strings.Virtual_String :=
164+
VSS.Strings.To_Virtual_String
165+
(Unit.Get_Line (Sloc.an_end.line + 1));
166+
167+
Cursor : VSS.Strings.Character_Iterators.Character_Iterator :=
168+
Line.Before_First_Character;
169+
170+
begin
171+
while Cursor.Forward and then
172+
Natural (Cursor.First_UTF16_Offset) <= Sloc.an_end.character
173+
loop
174+
Result.End_Column := @ + 1;
175+
end loop;
176+
177+
return Result;
178+
end;
179+
end From_LSP_Range;
180+
83181
-----------------
84182
-- Get_Node_At --
85183
-----------------

source/ada/lsp-ada_handlers-locations.ads

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ package LSP.Ada_Handlers.Locations is
5656
Node : Libadalang.Analysis.Ada_Node'Class)
5757
return LSP.Structures.A_Range;
5858

59+
function From_LSP_Range
60+
(Self : in out Message_Handler'Class;
61+
Unit : Libadalang.Analysis.Analysis_Unit;
62+
Sloc : LSP.Structures.A_Range)
63+
return Langkit_Support.Slocs.Source_Location_Range;
64+
5965
function Get_Node_At
6066
(Self : in out Message_Handler'Class;
6167
Context : LSP.Ada_Contexts.Context;

source/ada/lsp-ada_handlers.adb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ with VSS.Strings.Templates;
3333
with Laltools.Common;
3434
with Laltools.Partial_GNATPP;
3535

36-
with Langkit_Support.Slocs;
3736
with Langkit_Support.Text;
3837

3938
with LAL_Refactor.Extract_Subprogram;
@@ -163,6 +162,13 @@ package body LSP.Ada_Handlers is
163162
return LSP.Structures.A_Range is
164163
(LSP.Ada_Handlers.Locations.To_LSP_Range (Self, Unit, Token));
165164

165+
overriding function From_LSP_Range
166+
(Self : in out Message_Handler;
167+
Unit : Libadalang.Analysis.Analysis_Unit;
168+
Sloc : LSP.Structures.A_Range)
169+
return Langkit_Support.Slocs.Source_Location_Range is
170+
(LSP.Ada_Handlers.Locations.From_LSP_Range (Self, Unit, Sloc));
171+
166172
overriding function Get_Node_At
167173
(Self : in out Message_Handler;
168174
Context : LSP.Ada_Contexts.Context;

source/ada/lsp-ada_handlers.ads

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ with GNATCOLL.VFS;
2828
with GPR2.Build.Source.Sets;
2929
with GPR2.Project.Tree;
3030

31+
with Langkit_Support.Slocs;
3132
with Libadalang.Analysis;
3233
with Libadalang.Common;
3334

@@ -557,6 +558,12 @@ private
557558
Node : Libadalang.Analysis.Ada_Node'Class)
558559
return LSP.Structures.A_Range;
559560

561+
overriding function From_LSP_Range
562+
(Self : in out Message_Handler;
563+
Unit : Libadalang.Analysis.Analysis_Unit;
564+
Sloc : LSP.Structures.A_Range)
565+
return Langkit_Support.Slocs.Source_Location_Range;
566+
560567
overriding procedure Append_Location
561568
(Self : in out Message_Handler;
562569
Result : in out LSP.Structures.Location_Vector;

0 commit comments

Comments
 (0)