Skip to content

Commit a78b8cd

Browse files
committed
Merge branch 'onTypeFormatting_edge' into 'edge'
Add onTypeFormatting request initial implementation See merge request eng/ide/ada_language_server!1229
2 parents 5b54290 + 44ed79e commit a78b8cd

File tree

40 files changed

+970
-275
lines changed

40 files changed

+970
-275
lines changed

.vscode/settings.json.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
// ada_language_server executable after relaction into the VS Code
66
// extension.
77
"LIBRARY_TYPE": "static"
8+
"ada.onTypeFormatting.indentOnly": true,
9+
"[ada]": {
10+
"editor.autoIndent": "none",
11+
"editor.formatOnType": false,
12+
"editor.tabSize": 3
813
},
914
"python.analysis.extraPaths": ["testsuite"],
1015
"python.linting.enabled": true,

doc/settings.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Ada Language Server understands these settings:
4747
* [foldComments](#foldComments)
4848
* [followSymlinks](#followSymlinks)
4949
* [documentationStyle](#documentationStyle)
50+
* [onTypeFormatting.indentOnly](#onTypeFormatting.indentOnly)
5051

5152
----
5253

@@ -214,4 +215,10 @@ For more information about documentation styles see GNATdoc User's Manual.
214215
## trace.server
215216

216217
This option controls the tracing of the communication between VSCode and the Ada language server.
217-
The separate setting `gpr.trace.server` controls tracing for GPR language server.
218+
The separate setting `gpr.trace.server` controls tracing for GPR language server.
219+
220+
## onTypeFormatting.indentOnly
221+
222+
This option controls if the `textDocument/onTypeFormatting` request only indents a new line, or if
223+
it additionally tries to format the previous node. By default, this option is enabled, that is,
224+
`textDocument/onTypeFormatting` only indents new lines.

integration/vscode/ada/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,13 @@
401401
"scope": "resource",
402402
"type": "boolean",
403403
"default": false,
404-
"description": "Enable editing Ada comments while executing `textDocument/rename` reques."
404+
"description": "Enable editing Ada comments while executing `textDocument/rename` request."
405+
},
406+
"ada.onTypeFormatting.indentOnly": {
407+
"scope": "resource",
408+
"type": "boolean",
409+
"default": true,
410+
"description": "Controls if the `textDocument/onTypeFormatting` request only indents a new line, or if it additionally tries to format the previous node."
405411
}
406412
}
407413
}

scripts/generate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@
295295
'DocumentFormattingParams', 'Formatting_Response'),
296296
('textDocument/rangeFormatting', 'Range_Formatting',
297297
'DocumentRangeFormattingParams', 'Range_Formatting_Response'),
298+
('textDocument/onTypeFormatting', 'On_Type_Formatting',
299+
'DocumentOnTypeFormattingParams', 'On_Type_Formatting_Response'),
298300
('textDocument/selectionRange', 'Selection_Range',
299301
'SelectionRangeParams', 'SelectionRange_Response'),
300302
('textDocument/semanticTokens/full', 'Document_Tokens_Full',

source/ada/lsp-ada_documents.adb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ with Libadalang.Sources;
3535
with Libadalang.Iterators;
3636

3737
with Laltools.Common;
38-
with Laltools.Partial_GNATPP;
3938

4039
with VSS.Strings.Character_Iterators;
4140
with VSS.Strings.Line_Iterators;
@@ -919,6 +918,22 @@ package body LSP.Ada_Documents is
919918
end;
920919
end Diff_Symbols;
921920

921+
---------------------------
922+
-- Get_Formatting_Region --
923+
---------------------------
924+
925+
function Get_Formatting_Region
926+
(Self : Document;
927+
Context : LSP.Ada_Contexts.Context;
928+
Position : LSP.Messages.Position)
929+
return Laltools.Partial_GNATPP.Formatting_Region_Type
930+
is (Laltools.Partial_GNATPP.Get_Formatting_Region
931+
(Unit => Self.Unit (Context),
932+
Input_Range =>
933+
Langkit_Support.Slocs.Make_Range
934+
(Self.Get_Source_Location (Position),
935+
Self.Get_Source_Location (Position))));
936+
922937
----------------
923938
-- Formatting --
924939
----------------
@@ -1628,6 +1643,24 @@ package body LSP.Ada_Documents is
16281643
end if;
16291644
end Line_Terminator;
16301645

1646+
---------------------
1647+
-- Get_Indentation --
1648+
---------------------
1649+
1650+
function Get_Indentation
1651+
(Self : Document;
1652+
Context : LSP.Ada_Contexts.Context;
1653+
Line : LSP.Types.Line_Number)
1654+
return Natural
1655+
is
1656+
Unit : constant Libadalang.Analysis.Analysis_Unit :=
1657+
Self.Unit (Context);
1658+
Line_Number : constant Langkit_Support.Slocs.Line_Number :=
1659+
Self.Get_Source_Location (LSP.Messages.Position'(Line, 1)).Line;
1660+
begin
1661+
return Laltools.Partial_GNATPP.Estimate_Indentation (Unit, Line_Number);
1662+
end Get_Indentation;
1663+
16311664
-----------------
16321665
-- Get_Node_At --
16331666
-----------------

source/ada/lsp-ada_documents.ads

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private with VSS.Strings.Markers;
2626
with Libadalang.Analysis;
2727
with Libadalang.Common;
2828
with Langkit_Support.Slocs;
29+
with Laltools.Partial_GNATPP;
2930

3031
with GNATCOLL.Traces;
3132

@@ -134,10 +135,17 @@ package LSP.Ada_Documents is
134135
Result : out LSP.Messages.Symbol_Vector);
135136
-- Populate Result with a symbol hierarchy from the document.
136137

138+
function Get_Indentation
139+
(Self : Document;
140+
Context : LSP.Ada_Contexts.Context;
141+
Line : LSP.Types.Line_Number)
142+
return Natural;
143+
-- Estimates the indention a line should have
144+
137145
function Get_Node_At
138-
(Self : Document;
139-
Context : LSP.Ada_Contexts.Context;
140-
Position : LSP.Messages.Position)
146+
(Self : Document;
147+
Context : LSP.Ada_Contexts.Context;
148+
Position : LSP.Messages.Position)
141149
return Libadalang.Analysis.Ada_Node;
142150
-- Get Libadalang Node for given position in the document.
143151

@@ -190,6 +198,14 @@ package LSP.Ada_Documents is
190198
-- Populate Result with code folding blocks in the document. If Lines_Only
191199
-- is True does not return characters positions in lines.
192200

201+
function Get_Formatting_Region
202+
(Self : Document;
203+
Context : LSP.Ada_Contexts.Context;
204+
Position : LSP.Messages.Position)
205+
return Laltools.Partial_GNATPP.Formatting_Region_Type;
206+
-- Given Position, get the region that would be formatted if
207+
-- Range_Formatting was called.
208+
193209
function Formatting
194210
(Self : Document;
195211
Context : LSP.Ada_Contexts.Context;

0 commit comments

Comments
 (0)