Skip to content

Commit

Permalink
Merge branch 'issue_1153_edge' into 'edge'
Browse files Browse the repository at this point in the history
Fix onTypeFormatting.indentOnly option reading

See merge request eng/ide/ada_language_server!1255
  • Loading branch information
joaopsazevedo committed Jul 12, 2023
2 parents c48970f + e4ff8cd commit a98bd18
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 20 deletions.
42 changes: 22 additions & 20 deletions source/ada/lsp-ada_handlers.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4460,8 +4460,10 @@ package body LSP.Ada_Handlers is
"useCompletionSnippets";
logThreshold : constant String :=
"logThreshold";
onTypeFormattingIndentOnly : constant String :=
"onTypeFormatting.indentOnly";
onTypeFormatting : constant String :=
"onTypeFormatting";
indentOnly : constant String :=
"indentOnly";

Variables : Scenario_Variable_List;

Expand Down Expand Up @@ -4599,13 +4601,21 @@ package body LSP.Ada_Handlers is
end;
end if;

if Has_Field (onTypeFormattingIndentOnly) then
if Has_Field (onTypeFormatting) then
declare
On_Type_Formatting : constant GNATCOLL.JSON.JSON_Value'Class :=
Options.Get (onTypeFormatting);
begin
Self.Options.On_Type_Formatting.Indent_Only :=
Options.Get (onTypeFormattingIndentOnly);
if On_Type_Formatting.Has_Field (indentOnly) then
Self.Options.On_Type_Formatting.Indent_Only :=
On_Type_Formatting.Get (indentOnly);
end if;

exception
when Constraint_Error =>
Self.Trace.Trace
("Failed to get " & onTypeFormatting & "." & indentOnly
& " option. Using True as default.");
Self.Options.On_Type_Formatting.Indent_Only := True;
end;
end if;
Expand Down Expand Up @@ -6656,22 +6666,14 @@ package body LSP.Ada_Handlers is

declare
Result :
LSP.Messages.Server_Responses.Formatting_Response
(Is_Error => False) :=
Range_Format
(Self => Context.all,
Document => Document,
Span => Previous_NWNC_Token_Span,
Options => Request.params.options);
LSP.Messages.Server_Responses.Formatting_Response :=
Range_Format
(Self => Context.all,
Document => Document,
Span => Previous_NWNC_Token_Span,
Options => Request.params.options);
begin
Result :=
Range_Format
(Self => Context.all,
Document => Document,
Span => Previous_NWNC_Token_Span,
Options => Request.params.options);

if not Result.Is_Error then
if Result.Is_Error then
declare
Result :
LSP.Messages.Server_Responses.Formatting_Response
Expand Down
5 changes: 5 additions & 0 deletions testsuite/ada_lsp/onTypeFormatting/indentOnlyFalse/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
with Ada.Text_IO;
procedure Test is
begin
Ada.Text_IO.Put_Line("Hello, World!");
end Test;
3 changes: 3 additions & 0 deletions testsuite/ada_lsp/onTypeFormatting/indentOnlyFalse/test.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project Test is
for Main use ("test.adb");
end Test;
205 changes: 205 additions & 0 deletions testsuite/ada_lsp/onTypeFormatting/indentOnlyFalse/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
[
{
"comment": [
"This test checks that the textDocument/onTypeFormatting request ",
"does not fail on a basic example (one line break added after the ",
"begin keyword."
]
},
{
"start": {
"cmd": [
"${ALS}"
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 0,
"method": "initialize",
"params": {
"rootUri": "$URI{.}",
"capabilities": {
"workspace": {
"applyEdit": true,
"workspaceEdit": {
"documentChanges": true,
"resourceOperations": [
"create",
"rename",
"delete"
]
},
"didChangeConfiguration": {
"dynamicRegistration": true
},
"executeCommand": {
"dynamicRegistration": true
},
"configuration": true,
"workspaceFolders": true
},
"textDocument": {
"onTypeFormatting": {
"dynamicRegistration": true
}
}
}
}
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "workspace/didChangeConfiguration",
"params": {
"settings": {
"ada": {
"projectFile": "$URI{test.gpr}",
"onTypeFormatting": {
"indentOnly": false
}
}
}
}
},
"wait": [
{
"jsonrpc": "2.0",
"method": "$/progress",
"params": {
"token": "<ANY>",
"value": {
"kind": "end"
}
}
}
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"uri": "$URI{test.adb}",
"languageId": "ada",
"version": 1,
"text": "with Ada.Text_IO;\nprocedure Test is\nbegin\n Ada.Text_IO.Put_Line(\"Hello, World!\");\nend Test;\n"
}
}
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "textDocument/didChange",
"params": {
"textDocument": {
"uri": "$URI{test.adb}",
"version": 2
},
"contentChanges": [
{
"range": {
"start": {
"line": 3,
"character": 41
},
"end": {
"line": 3,
"character": 41
}
},
"rangeLength": 0,
"text": "\n"
}
]
}
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 2,
"method": "textDocument/onTypeFormatting",
"params": {
"textDocument": {
"uri": "$URI{test.adb}"
},
"position": {
"line": 4,
"character": 0
},
"ch": "\n",
"options": {
"tabSize": 3,
"insertSpaces": true
}
}
},
"wait": [
{
"jsonrpc": "2.0",
"id": 2,
"result": [
{
"range": {
"start": {
"line": 3,
"character": 0
},
"end": {
"line": 3,
"character": 41
}
},
"newText": " Ada.Text_IO.Put_Line (\"Hello, World!\");"
},
{
"range": {
"start": {
"line": 4,
"character": 0
},
"end": {
"line": 4,
"character": 0
}
},
"newText": " "
}
]
}
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 13,
"method": "shutdown"
},
"wait": []
}
},
{
"stop": {
"exit_code": 0
}
}
]
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title: 'testi'

0 comments on commit a98bd18

Please sign in to comment.