Avoid appending 'auto-import' command when completing with-clauses

Since the user is already manually adding the missing with-clause, and
this causes the 'auto-import' command to fail since it can't be executed
from with-clause children nodes.

Add automatic-test.

Closes eng/ide/ada_language_server#1463
This commit is contained in:
Anthony Leonardo Gracio
2024-10-09 13:20:07 +00:00
parent 5a6f467b6a
commit 381fc8493d
6 changed files with 183 additions and 2 deletions

View File

@@ -118,6 +118,7 @@ package body LSP.Ada_Documents is
Completions_Count : Natural)
return LSP.Structures.CompletionItem
is
use Libadalang.Common;
package Weight_Formatters renames VSS.Strings.Formatters.Integers;
@@ -307,9 +308,13 @@ package body LSP.Ada_Documents is
Item.label.Append (" (invisible)");
Item.filterText := Label;
-- If the corresponding setting is enabled, append a command to
-- If the corresponding setting is enabled, and if we
-- are not completing within a with-clause, append a command to
-- insert the missing with-clause/qualifier.
if Handler.Get_Configuration.Insert_With_Clauses then
if Handler.Get_Configuration.Insert_With_Clauses
and then not (for some Parent of Node.Parents
=> Parent.Kind = Ada_With_Clause)
then
Append_Auto_Import_Command;
end if;
end if;

View File

@@ -0,0 +1,9 @@
package Bar is
type My_Int is tagged record
A : Integer;
end record;
procedure Do_Nothing (Obj : My_Int; A :Integer; B : Integer) is null;
end Bar;

View File

@@ -0,0 +1,2 @@
project Default is
end Default;

View File

@@ -0,0 +1,7 @@
with B;
procedure Main is
Obj : My_Int := (A => 10);
begin
Do_N
end Main;

View File

@@ -0,0 +1,157 @@
[
{
"comment": [
"This test checks that we do not append any 'auto-import' command to invisible ",
"completion items when completing inside with-clauses (e.g: when typing 'with Ada.Text'"
]
},
{
"start": {
"cmd": ["${ALS}"]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"processId": 199714,
"rootUri": "$URI{.}",
"capabilities": {
"workspace": {
"applyEdit": true
},
"textDocument": {
"completion": {
"completionItem": {
"snippetSupport": true,
"documentationFormat": ["markdown", "plaintext"]
}
}
},
"window": {
"workDoneProgress": true
}
}
}
},
"wait": [
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"capabilities": {
"textDocumentSync": 2,
"completionProvider": {
"triggerCharacters": [".", ",", "'", "("],
"resolveProvider": true
}
}
}
}
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "initialized"
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "workspace/didChangeConfiguration",
"params": {
"settings": {
"ada": {
"projectFile": "default.gpr",
"insertWithClauses": true
}
}
}
},
"wait": [
{
"jsonrpc": "2.0",
"method": "$/progress",
"params": {
"token": "<ANY>",
"value": {
"kind": "end"
}
}
}
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"uri": "$URI{main.adb}",
"languageId": "ada",
"version": 1,
"text": "with B;\n\nprocedure Main is\n Obj : My_Int := (A => 10);\nbegin\n Do_N\nend Main;\n"
}
}
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 13,
"method": "textDocument/completion",
"params": {
"textDocument": {
"uri": "$URI{main.adb}"
},
"position": {
"line": 0,
"character": 6
},
"context": {
"triggerKind": 1
}
}
},
"wait": [
{
"id": 13,
"result": {
"isIncomplete": false,
"items": [
"<HAS>",
{
"detail": "package Bar",
"documentation": "at bar.ads (1:1)",
"filterText": "Bar",
"insertText": "Bar",
"kind": 9,
"label": "Bar (invisible)",
"sortText": "~100&00003Bar"
}
]
}
}
]
}
},
{
"stop": {
"exit_code": 0
}
}
]

View File

@@ -0,0 +1 @@
title: 'completion.invisible.insert_with_clause.from_with_clause'