Skip to content

Commit 319ec42

Browse files
committed
Fix onTypeFormatting.indentOnly option reading
Fix handling of RangeFormat errors on the onTypeFormatting request. Move onTypeFormatting.indentOnly = True to its own directory. Add test with onTypeFormatting.indentOnly = False.
1 parent c48970f commit 319ec42

File tree

9 files changed

+237
-20
lines changed

9 files changed

+237
-20
lines changed

source/ada/lsp-ada_handlers.adb

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,8 +4460,10 @@ package body LSP.Ada_Handlers is
44604460
"useCompletionSnippets";
44614461
logThreshold : constant String :=
44624462
"logThreshold";
4463-
onTypeFormattingIndentOnly : constant String :=
4464-
"onTypeFormatting.indentOnly";
4463+
onTypeFormatting : constant String :=
4464+
"onTypeFormatting";
4465+
indentOnly : constant String :=
4466+
"indentOnly";
44654467

44664468
Variables : Scenario_Variable_List;
44674469

@@ -4599,13 +4601,21 @@ package body LSP.Ada_Handlers is
45994601
end;
46004602
end if;
46014603

4602-
if Has_Field (onTypeFormattingIndentOnly) then
4604+
if Has_Field (onTypeFormatting) then
4605+
declare
4606+
On_Type_Formatting : constant GNATCOLL.JSON.JSON_Value'Class :=
4607+
Options.Get (onTypeFormatting);
46034608
begin
4604-
Self.Options.On_Type_Formatting.Indent_Only :=
4605-
Options.Get (onTypeFormattingIndentOnly);
4609+
if On_Type_Formatting.Has_Field (indentOnly) then
4610+
Self.Options.On_Type_Formatting.Indent_Only :=
4611+
On_Type_Formatting.Get (indentOnly);
4612+
end if;
46064613

46074614
exception
46084615
when Constraint_Error =>
4616+
Self.Trace.Trace
4617+
("Failed to get " & onTypeFormatting & "." & indentOnly
4618+
& " option. Using True as default.");
46094619
Self.Options.On_Type_Formatting.Indent_Only := True;
46104620
end;
46114621
end if;
@@ -6656,22 +6666,15 @@ package body LSP.Ada_Handlers is
66566666

66576667
declare
66586668
Result :
6659-
LSP.Messages.Server_Responses.Formatting_Response
6660-
(Is_Error => False) :=
6661-
Range_Format
6662-
(Self => Context.all,
6663-
Document => Document,
6664-
Span => Previous_NWNC_Token_Span,
6665-
Options => Request.params.options);
6669+
LSP.Messages.Server_Responses.Formatting_Response
6670+
(Is_Error => False) :=
6671+
Range_Format
6672+
(Self => Context.all,
6673+
Document => Document,
6674+
Span => Previous_NWNC_Token_Span,
6675+
Options => Request.params.options);
66666676
begin
6667-
Result :=
6668-
Range_Format
6669-
(Self => Context.all,
6670-
Document => Document,
6671-
Span => Previous_NWNC_Token_Span,
6672-
Options => Request.params.options);
6673-
6674-
if not Result.Is_Error then
6677+
if Result.Is_Error then
66756678
declare
66766679
Result :
66776680
LSP.Messages.Server_Responses.Formatting_Response
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
with Ada.Text_IO;
2+
procedure Test is
3+
begin
4+
Ada.Text_IO.Put_Line("Hello, World!");
5+
end Test;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Test is
2+
for Main use ("test.adb");
3+
end Test;
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
[
2+
{
3+
"comment": [
4+
"This test checks that the textDocument/onTypeFormatting request ",
5+
"does not fail on a basic example (one line break added after the ",
6+
"begin keyword."
7+
]
8+
},
9+
{
10+
"start": {
11+
"cmd": [
12+
"${ALS}"
13+
]
14+
}
15+
},
16+
{
17+
"send": {
18+
"request": {
19+
"jsonrpc": "2.0",
20+
"id": 0,
21+
"method": "initialize",
22+
"params": {
23+
"rootUri": "$URI{.}",
24+
"capabilities": {
25+
"workspace": {
26+
"applyEdit": true,
27+
"workspaceEdit": {
28+
"documentChanges": true,
29+
"resourceOperations": [
30+
"create",
31+
"rename",
32+
"delete"
33+
]
34+
},
35+
"didChangeConfiguration": {
36+
"dynamicRegistration": true
37+
},
38+
"executeCommand": {
39+
"dynamicRegistration": true
40+
},
41+
"configuration": true,
42+
"workspaceFolders": true
43+
},
44+
"textDocument": {
45+
"onTypeFormatting": {
46+
"dynamicRegistration": true
47+
}
48+
}
49+
}
50+
}
51+
},
52+
"wait": []
53+
}
54+
},
55+
{
56+
"send": {
57+
"request": {
58+
"jsonrpc": "2.0",
59+
"method": "workspace/didChangeConfiguration",
60+
"params": {
61+
"settings": {
62+
"ada": {
63+
"projectFile": "$URI{test.gpr}",
64+
"onTypeFormatting": {
65+
"indentOnly": false
66+
}
67+
}
68+
}
69+
}
70+
},
71+
"wait": [
72+
{
73+
"jsonrpc": "2.0",
74+
"method": "$/progress",
75+
"params": {
76+
"token": "<ANY>",
77+
"value": {
78+
"kind": "end"
79+
}
80+
}
81+
}
82+
]
83+
}
84+
},
85+
{
86+
"send": {
87+
"request": {
88+
"jsonrpc": "2.0",
89+
"method": "textDocument/didOpen",
90+
"params": {
91+
"textDocument": {
92+
"uri": "$URI{test.adb}",
93+
"languageId": "ada",
94+
"version": 1,
95+
"text": "with Ada.Text_IO;\nprocedure Test is\nbegin\n Ada.Text_IO.Put_Line(\"Hello, World!\");\nend Test;\n"
96+
}
97+
}
98+
},
99+
"wait": []
100+
}
101+
},
102+
{
103+
"send": {
104+
"request": {
105+
"jsonrpc": "2.0",
106+
"method": "textDocument/didChange",
107+
"params": {
108+
"textDocument": {
109+
"uri": "$URI{test.adb}",
110+
"version": 2
111+
},
112+
"contentChanges": [
113+
{
114+
"range": {
115+
"start": {
116+
"line": 3,
117+
"character": 41
118+
},
119+
"end": {
120+
"line": 3,
121+
"character": 41
122+
}
123+
},
124+
"rangeLength": 0,
125+
"text": "\n"
126+
}
127+
]
128+
}
129+
},
130+
"wait": []
131+
}
132+
},
133+
{
134+
"send": {
135+
"request": {
136+
"jsonrpc": "2.0",
137+
"id": 2,
138+
"method": "textDocument/onTypeFormatting",
139+
"params": {
140+
"textDocument": {
141+
"uri": "$URI{test.adb}"
142+
},
143+
"position": {
144+
"line": 4,
145+
"character": 0
146+
},
147+
"ch": "\n",
148+
"options": {
149+
"tabSize": 3,
150+
"insertSpaces": true
151+
}
152+
}
153+
},
154+
"wait": [
155+
{
156+
"jsonrpc": "2.0",
157+
"id": 2,
158+
"result": [
159+
{
160+
"range": {
161+
"start": {
162+
"line": 3,
163+
"character": 0
164+
},
165+
"end": {
166+
"line": 3,
167+
"character": 41
168+
}
169+
},
170+
"newText": " Ada.Text_IO.Put_Line (\"Hello, World!\");"
171+
},
172+
{
173+
"range": {
174+
"start": {
175+
"line": 4,
176+
"character": 0
177+
},
178+
"end": {
179+
"line": 4,
180+
"character": 0
181+
}
182+
},
183+
"newText": " "
184+
}
185+
]
186+
}
187+
]
188+
}
189+
},
190+
{
191+
"send": {
192+
"request": {
193+
"jsonrpc": "2.0",
194+
"id": 13,
195+
"method": "shutdown"
196+
},
197+
"wait": []
198+
}
199+
},
200+
{
201+
"stop": {
202+
"exit_code": 0
203+
}
204+
}
205+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'testi'

0 commit comments

Comments
 (0)