diff --git a/source/ada/lsp-ada_handlers-refactor-auto_import.adb b/source/ada/lsp-ada_handlers-refactor-auto_import.adb index 707ab2214..f21982f52 100644 --- a/source/ada/lsp-ada_handlers-refactor-auto_import.adb +++ b/source/ada/lsp-ada_handlers-refactor-auto_import.adb @@ -135,7 +135,10 @@ package body LSP.Ada_Handlers.Refactor.Auto_Import is use Ada.Strings.Wide_Wide_Unbounded; Title : constant Langkit_Support.Text.Unbounded_Text_Type := - "Qualify with " & Suggestion.Qualifier; + (if Suggestion.Qualifier = Null_Unbounded_Wide_Wide_String then + "Import from " & Suggestion.Import + else + "Qualify with " & Suggestion.Qualifier); begin return VSS.Strings.To_Virtual_String diff --git a/testsuite/ada_lsp/refactoring_imports_commands/U511-009.refactoring.import_with_use/test.json b/testsuite/ada_lsp/refactoring_imports_commands/U511-009.refactoring.import_with_use/test.json index 2bc901336..ff6fa2803 100644 --- a/testsuite/ada_lsp/refactoring_imports_commands/U511-009.refactoring.import_with_use/test.json +++ b/testsuite/ada_lsp/refactoring_imports_commands/U511-009.refactoring.import_with_use/test.json @@ -1,10 +1,14 @@ [ { - "comment": ["Test codeaction import refactor"] + "comment": [ + "Test codeaction import refactor" + ] }, { "start": { - "cmd": ["${ALS}"] + "cmd": [ + "${ALS}" + ] } }, { @@ -32,12 +36,22 @@ "referencesProvider": true, "textDocumentSync": 2, "completionProvider": { - "triggerCharacters": [".", ",", "'", "("], + "triggerCharacters": [ + ".", + ",", + "'", + "(" + ], "resolveProvider": true }, "signatureHelpProvider": { - "triggerCharacters": [",", "("], - "retriggerCharacters": ["\b"] + "triggerCharacters": [ + ",", + "(" + ], + "retriggerCharacters": [ + "\b" + ] }, "definitionProvider": true } @@ -491,19 +505,6 @@ } }, "newText": "with Foo;\n" - }, - { - "range": { - "start": { - "line": 9, - "character": 20 - }, - "end": { - "line": 9, - "character": 20 - } - }, - "newText": "" } ] } @@ -617,4 +618,4 @@ "exit_code": 0 } } -] +] \ No newline at end of file diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/a.adb b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/a.adb new file mode 100644 index 000000000..24e650b4c --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/a.adb @@ -0,0 +1,8 @@ +package body A is + + procedure Subprogram is + begin + null; + end Subprogram; + +end A; diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/a.ads b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/a.ads new file mode 100644 index 000000000..e62159d7e --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/a.ads @@ -0,0 +1,5 @@ +package A is + + procedure Subprogram; + +end A; diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/default.gpr b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/default.gpr new file mode 100644 index 000000000..ce7c7bb85 --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/default.gpr @@ -0,0 +1,4 @@ +project Default is + for Main use ("main.adb"); + for Runtime ("Ada") use "./rts-empty"; +end Default; diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/e.ads b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/e.ads new file mode 100644 index 000000000..2183bf725 --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/e.ads @@ -0,0 +1,3 @@ +with A; + +package E renames A; diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/main.adb b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/main.adb new file mode 100644 index 000000000..c33ea1e15 --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/main.adb @@ -0,0 +1,4 @@ +procedure Main is +begin + A.Subprogram; +end Main; diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/refactor_imports_commands.json b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/refactor_imports_commands.json new file mode 100644 index 000000000..058a8cef0 --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/refactor_imports_commands.json @@ -0,0 +1,259 @@ +[ + { + "comment": [ + "This test checks if imports (with clause + prefix) are being suggested to unresolved names." + ] + }, + { + "start": { + "cmd": ["${ALS}"] + } + }, + { + "send": { + "request": { + "params": { + "processId": 13950, + "capabilities": { + "workspace": { + "workspaceEdit": { + "documentChanges": true + }, + "applyEdit": false + } + }, + "rootUri": "$URI{.}" + }, + "jsonrpc": "2.0", + "id": 1, + "method": "initialize" + }, + "wait": [ + { + "id": 1, + "result": { + "capabilities": { + "textDocumentSync": 2, + "executeCommandProvider": { + "commands": ["", "als-auto-import"] + } + } + } + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "method": "initialized" + }, + "wait": [] + } + }, + { + "send": { + "request": { + "params": { + "settings": { + "ada": { + "projectFile": "default.gpr", + "scenarioVariables": {}, + "defaultCharset": "ISO-8859-1" + } + } + }, + "jsonrpc": "2.0", + "method": "workspace/didChangeConfiguration" + }, + "wait": [ + { + "jsonrpc": "2.0", + "id": 1, + "method": "window/workDoneProgress/create", + "params": { + "token": "" + } + }, + { + "jsonrpc": "2.0", + "method": "$/progress", + "params": { + "token": "", + "value": { + "kind": "end" + } + } + } + ] + } + }, + { + "send": { + "request": { + "params": { + "textDocument": { + "text": "procedure Main is\nbegin\n A.Subprogram;\nend Main;", + "version": 0, + "uri": "$URI{main.adb}", + "languageId": "Ada" + } + }, + "jsonrpc": "2.0", + "method": "textDocument/didOpen" + }, + "wait": [] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 2, + "method": "textDocument/codeAction", + "params": { + "textDocument": { + "uri": "$URI{main.adb}" + }, + "range": { + "start": { + "line": 2, + "character": 3 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "context": { + "diagnostics": [] + } + } + }, + "wait": [ + { + "jsonrpc": "2.0", + "id": 2, + "result": [ + { + "title": "Import from A", + "kind": "quickfix", + "command": { + "title": "", + "command": "als-auto-import", + "arguments": [ + { + "context": "Default", + "where": { + "textDocument": { + "uri": "$URI{main.adb}" + }, + "position": { + "line": 2, + "character": 5 + } + }, + "import": "A", + "qualifier": "" + } + ] + } + }, + { + "title": "Qualify with E", + "kind": "quickfix", + "command": { + "title": "", + "command": "als-auto-import", + "arguments": [ + { + "context": "Default", + "where": { + "textDocument": { + "uri": "$URI{main.adb}" + }, + "position": { + "line": 2, + "character": 5 + } + }, + "import": "E", + "qualifier": "E" + } + ] + } + } + ] + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 3, + "method": "workspace/executeCommand", + "params": { + "command": "als-auto-import", + "arguments": [ + { + "context": "Default", + "where": { + "textDocument": { + "uri": "$URI{main.adb}" + }, + "position": { + "line": 2, + "character": 3 + } + }, + "import": "A", + "qualifier": "" + } + ] + } + }, + "wait": [ + { + "jsonrpc": "2.0", + "id": 2, + "method": "workspace/applyEdit", + "params": { + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "$URI{main.adb}", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "with A;\n" + } + ] + } + ] + } + } + } + ] + } + }, + { + "stop": { + "exit_code": 0 + } + } +] diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/rts-empty/adainclude/ada.ads b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/rts-empty/adainclude/ada.ads new file mode 100644 index 000000000..4c2a3d00e --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/rts-empty/adainclude/ada.ads @@ -0,0 +1,20 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT RUN-TIME COMPONENTS -- +-- -- +-- A D A -- +-- -- +-- S p e c -- +-- -- +-- This specification is derived from the Ada Reference Manual for use with -- +-- GNAT. In accordance with the copyright of that document, you can freely -- +-- copy and modify this specification, provided that if you redistribute a -- +-- modified version, any changes that you have made are clearly indicated. -- +-- -- +------------------------------------------------------------------------------ + +package Ada is + pragma No_Elaboration_Code_All; + pragma Pure; + +end Ada; diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/rts-empty/adainclude/system.ads b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/rts-empty/adainclude/system.ads new file mode 100644 index 000000000..61c8ae3ed --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/rts-empty/adainclude/system.ads @@ -0,0 +1,156 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT RUN-TIME COMPONENTS -- +-- -- +-- S Y S T E M -- +-- -- +-- S p e c -- +-- (GNU-Linux/x86 Version) -- +-- -- +-- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- +-- -- +-- This specification is derived from the Ada Reference Manual for use with -- +-- GNAT. The copyright notice above, and the license provisions that follow -- +-- apply solely to the contents of the part following the private keyword. -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- As a special exception under Section 7 of GPL version 3, you are granted -- +-- additional permissions described in the GCC Runtime Library Exception, -- +-- version 3.1, as published by the Free Software Foundation. -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT was originally developed by the GNAT team at New York University. -- +-- Extensive contributions were provided by Ada Core Technologies Inc. -- +-- -- +------------------------------------------------------------------------------ + +package System is + pragma Pure; + -- Note that we take advantage of the implementation permission to make + -- this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada + -- 2005, this is Pure in any case (AI-362). + + pragma No_Elaboration_Code_All; + -- Allow the use of that restriction in units that WITH this unit + + type Name is (SYSTEM_NAME_GNAT); + System_Name : constant Name := SYSTEM_NAME_GNAT; + + -- System-Dependent Named Numbers + + Min_Int : constant := -2 ** (Standard'Max_Integer_Size - 1); + Max_Int : constant := 2 ** (Standard'Max_Integer_Size - 1) - 1; + + Max_Binary_Modulus : constant := 2 ** Standard'Max_Integer_Size; + Max_Nonbinary_Modulus : constant := 2 ** Integer'Size - 1; + + Max_Base_Digits : constant := Long_Long_Float'Digits; + Max_Digits : constant := Long_Long_Float'Digits; + + Max_Mantissa : constant := 63; + Fine_Delta : constant := 2.0 ** (-Max_Mantissa); + + Tick : constant := 0.000_001; + + -- Storage-related Declarations + + type Address is private; + pragma Preelaborable_Initialization (Address); + Null_Address : constant Address; + + Storage_Unit : constant := 8; + Word_Size : constant := Standard'Word_Size; + Memory_Size : constant := 2 ** Long_Integer'Size; + + -- Address comparison + + function "<" (Left, Right : Address) return Boolean; + function "<=" (Left, Right : Address) return Boolean; + function ">" (Left, Right : Address) return Boolean; + function ">=" (Left, Right : Address) return Boolean; + function "=" (Left, Right : Address) return Boolean; + + pragma Import (Intrinsic, "<"); + pragma Import (Intrinsic, "<="); + pragma Import (Intrinsic, ">"); + pragma Import (Intrinsic, ">="); + pragma Import (Intrinsic, "="); + + -- Other System-Dependent Declarations + + type Bit_Order is (High_Order_First, Low_Order_First); + Default_Bit_Order : constant Bit_Order := Low_Order_First; + pragma Warnings (Off, Default_Bit_Order); -- kill constant condition warning + + -- Priority-related Declarations (RM D.1) + + -- 0 .. 98 corresponds to the system priority range 1 .. 99. + -- + -- If the scheduling policy is SCHED_FIFO or SCHED_RR the runtime makes use + -- of the entire range provided by the system. + -- + -- If the scheduling policy is SCHED_OTHER the only valid system priority + -- is 1 and other values are simply ignored. + + Max_Priority : constant Positive := 97; + Max_Interrupt_Priority : constant Positive := 98; + + subtype Any_Priority is Integer range 0 .. 98; + subtype Priority is Any_Priority range 0 .. 97; + subtype Interrupt_Priority is Any_Priority range 98 .. 98; + + Default_Priority : constant Priority := 48; + +private + + type Address is mod Memory_Size; + Null_Address : constant Address := 0; + + -------------------------------------- + -- System Implementation Parameters -- + -------------------------------------- + + -- These parameters provide information about the target that is used + -- by the compiler. They are in the private part of System, where they + -- can be accessed using the special circuitry in the Targparm unit + -- whose source should be consulted for more detailed descriptions + -- of the individual switch values. + + Backend_Divide_Checks : constant Boolean := False; + Backend_Overflow_Checks : constant Boolean := True; + Command_Line_Args : constant Boolean := True; + Configurable_Run_Time : constant Boolean := False; + Denorm : constant Boolean := True; + Duration_32_Bits : constant Boolean := False; + Exit_Status_Supported : constant Boolean := True; + Fractional_Fixed_Ops : constant Boolean := False; + Frontend_Layout : constant Boolean := False; + Machine_Overflows : constant Boolean := False; + Machine_Rounds : constant Boolean := True; + Preallocated_Stacks : constant Boolean := False; + Signed_Zeros : constant Boolean := True; + Stack_Check_Default : constant Boolean := False; + Stack_Check_Probes : constant Boolean := True; + Stack_Check_Limits : constant Boolean := False; + Support_Aggregates : constant Boolean := True; + Support_Atomic_Primitives : constant Boolean := True; + Support_Composite_Assign : constant Boolean := True; + Support_Composite_Compare : constant Boolean := True; + Support_Long_Shifts : constant Boolean := True; + Always_Compatible_Rep : constant Boolean := False; + Suppress_Standard_Library : constant Boolean := False; + Use_Ada_Main_Program_Name : constant Boolean := False; + Frontend_Exceptions : constant Boolean := False; + ZCX_By_Default : constant Boolean := False; + +end System; diff --git a/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/test.yaml b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/test.yaml new file mode 100644 index 000000000..57c1304cb --- /dev/null +++ b/testsuite/ada_lsp/refactoring_imports_commands/issue_1250/test.yaml @@ -0,0 +1 @@ +title: 'refactoring_imports_commands/suggestions_with_nested_packages'