Skip to content

Commit 0ace5e7

Browse files
U929-027: Various completion provider enhancement.
- don't trigger completion when inside a string literal - add "," as a trigger character to automatically have "completion parameter" when writing. - automatically add a whitespace when adding a parameter after a "," Adapt the tests.
1 parent 7e41b50 commit 0ace5e7

File tree

103 files changed

+125
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+125
-16
lines changed

source/ada/lsp-ada_completions-parameters.adb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ package body LSP.Ada_Completions.Parameters is
4646
use Libadalang.Analysis;
4747
use Libadalang.Common;
4848

49-
Call_Expr_Node : constant Libadalang.Analysis.Call_Expr :=
49+
Call_Expr_Node : constant Libadalang.Analysis.Call_Expr :=
5050
LSP.Lal_Utils.Get_Call_Expr (Node);
51-
Token_Kind : Libadalang.Common.Token_Kind :=
51+
Token_Kind : Libadalang.Common.Token_Kind :=
5252
Kind (Data (Token));
53-
Designators : Laltools.Common.Node_Vectors.Vector;
53+
Whitespace_Prefix : LSP_String := Empty_LSP_String;
54+
-- Empty if we already have a whitespace before a ","
55+
56+
Designators : Laltools.Common.Node_Vectors.Vector;
5457

5558
function Is_Present (Id_Text : Text_Type) return Boolean;
5659
-- Return True if Id_Name match one of the designators
@@ -78,6 +81,8 @@ package body LSP.Ada_Completions.Parameters is
7881

7982
if Token_Kind = Ada_Whitespace then
8083
Token_Kind := Kind (Data (Previous (Token, Exclude_Trivia => True)));
84+
elsif Token_Kind = Ada_Comma then
85+
Whitespace_Prefix := Whitespace_Prefix & " ";
8186
end if;
8287

8388
declare
@@ -119,7 +124,9 @@ package body LSP.Ada_Completions.Parameters is
119124
Item.label := To_Virtual_String (Name);
120125
Item.insertTextFormat :=
121126
(True, LSP.Messages.PlainText);
122-
Item.insertText := (True, Name & " => ");
127+
Item.insertText :=
128+
(True,
129+
Whitespace_Prefix & Name & " => ");
123130
Item.kind := (True, LSP.Messages.Text);
124131
Result.items.Append (Item);
125132
end if;
@@ -139,7 +146,9 @@ package body LSP.Ada_Completions.Parameters is
139146
end loop;
140147

141148
-- If the string is empty => nothing to do
142-
if Params_Snippet /= Empty_LSP_String then
149+
if Params_Snippet /= Empty_LSP_String
150+
and then Token_Kind in Ada_Par_Open | Ada_Comma
151+
then
143152
-- Remove the last 2 characters which are ", " and
144153
-- replace it by ")" and the final tab stop
145154
Params_Snippet := Unbounded_Slice
@@ -156,7 +165,8 @@ package body LSP.Ada_Completions.Parameters is
156165
(Snippet_Name);
157166
Item.insertTextFormat :=
158167
(True, LSP.Messages.Snippet);
159-
Item.insertText := (True, Params_Snippet);
168+
Item.insertText :=
169+
(True, Whitespace_Prefix & Params_Snippet);
160170
Item.kind := (True, LSP.Messages.Snippet);
161171
Result.items.Append (Item);
162172
end if;

source/ada/lsp-ada_completions-parameters.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ package LSP.Ada_Completions.Parameters is
3232
Filter : in out LSP.Ada_Completions.Filters.Filter;
3333
Names : out Ada_Completions.Completion_Maps.Map;
3434
Result : out LSP.Messages.CompletionList);
35-
-- Get completion for keywords, filtering them with the prefix.
35+
-- Using the context, check if we are inside a function call and get its
36+
-- unset parameters while filtering them with the prefix.
3637

3738
end LSP.Ada_Completions.Parameters;

source/ada/lsp-ada_documents.adb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,11 @@ package body LSP.Ada_Documents is
22272227

22282228
Filter : LSP.Ada_Completions.Filters.Filter;
22292229
begin
2230+
if Node.Kind in Libadalang.Common.Ada_String_Literal_Range then
2231+
-- Do nothing when inside a string
2232+
return;
2233+
end if;
2234+
22302235
Context.Trace.Trace
22312236
("Getting completions, Pos = ("
22322237
& Sloc.Line'Image & ", " & Sloc.Column'Image & ") Node = "

source/ada/lsp-ada_handlers.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ package body LSP.Ada_Handlers is
722722
Response.result.capabilities.completionProvider :=
723723
(True,
724724
(resolveProvider => LSP.Types.True,
725-
triggerCharacters => (True, Empty_Vector & (+".") & (+"(")),
725+
triggerCharacters => (True,
726+
Empty_Vector & (+".") & (+",") & (+"(")),
726727
allCommitCharacters => (Is_Set => False),
727728
workDoneProgress => LSP.Types.None));
728729
Response.result.capabilities.hoverProvider :=

testsuite/ada_lsp/C825-005.xrefs.extending/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"completionProvider": {
4242
"triggerCharacters": [
4343
".",
44+
",",
4445
"("
4546
],
4647
"resolveProvider": true

testsuite/ada_lsp/D301-004.xrefs.generics/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"completionProvider": {
4242
"triggerCharacters": [
4343
".",
44+
",",
4445
"("
4546
],
4647
"resolveProvider": true

testsuite/ada_lsp/D803-003.xrefs.generics_go_to_body/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"completionProvider": {
4242
"triggerCharacters": [
4343
".",
44+
",",
4445
"("
4546
],
4647
"resolveProvider": true

testsuite/ada_lsp/F131-024.xrefs.separate_body/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"completionProvider": {
4949
"triggerCharacters": [
5050
".",
51+
",",
5152
"("
5253
],
5354
"resolveProvider": true

testsuite/ada_lsp/F222-029.xrefs.prefixed_notation/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"completionProvider": {
4242
"triggerCharacters": [
4343
".",
44+
",",
4445
"("
4546
],
4647
"resolveProvider": true

testsuite/ada_lsp/G323-009.tooltips.function_prototype/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"completionProvider": {
4949
"triggerCharacters": [
5050
".",
51+
",",
5152
"("
5253
],
5354
"resolveProvider": true

0 commit comments

Comments
 (0)