You've already forked ada_language_server
mirror of
https://github.com/AdaCore/ada_language_server.git
synced 2026-02-12 12:45:50 -08:00
Fix als-other-file command for child packages
For this command, we were calling Unit which expects an unit name but we were passing a file base name (without extension). So this doesn't work if the file base name contains '-' (child packages). Use the proper GPR2 API to get a proper unit name instead. Add an automatic test. For eng/ide/ada_language_server#1450
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
-- of the license. --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with GPR2.Build.Unit_Info;
|
||||
with GPR2.Project.View;
|
||||
with VSS.JSON.Streams;
|
||||
|
||||
with GNATCOLL.VFS; use GNATCOLL.VFS;
|
||||
@@ -126,20 +128,27 @@ package body LSP.Ada_Handlers.Other_File_Commands is
|
||||
-- Unit_For_File --
|
||||
-------------------
|
||||
|
||||
function Unit_For_File return GPR2.Build.Compilation_Unit.Object
|
||||
is
|
||||
Unit : GPR2.Build.Compilation_Unit.Object;
|
||||
function Unit_For_File return GPR2.Build.Compilation_Unit.Object is
|
||||
begin
|
||||
-- First look in the closure of sources, then in the
|
||||
-- runtime project.
|
||||
-- Check in the root project's closure for a visible source
|
||||
-- corresponding to this file.
|
||||
-- Not that the root's project closure includes the runtime.
|
||||
if Handler.Project_Tree.Is_Defined then
|
||||
Unit := Handler.Project_Tree.Root_Project.Unit (F.Base_Name);
|
||||
declare
|
||||
View : constant GPR2.Project.View.Object :=
|
||||
Handler.Project_Tree.Root_Project;
|
||||
Unit_Info : constant GPR2.Build.Unit_Info.Object :=
|
||||
View.Visible_Source (F.Simple_Name).Unit;
|
||||
Unit : GPR2.Build.Compilation_Unit.Object :=
|
||||
GPR2.Build.Compilation_Unit.Undefined;
|
||||
begin
|
||||
if Unit_Info.Is_Defined then
|
||||
Unit := View.Namespace_Roots.First_Element.Unit
|
||||
(Unit_Info.Name);
|
||||
end if;
|
||||
|
||||
if not Unit.Is_Defined then
|
||||
Unit := Handler.Project_Tree.Runtime_Project.Unit
|
||||
(F.Base_Name);
|
||||
end if;
|
||||
return Unit;
|
||||
return Unit;
|
||||
end;
|
||||
else
|
||||
return GPR2.Build.Compilation_Unit.Undefined;
|
||||
end if;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package body A.B is
|
||||
procedure Proc (X : in out Integer) is
|
||||
begin
|
||||
X := X + 2 * X;
|
||||
|
||||
Proc (X => X);
|
||||
end Proc;
|
||||
end A.B;
|
||||
@@ -0,0 +1,3 @@
|
||||
package A.B is
|
||||
procedure Proc (X : in out Integer);
|
||||
end A.B;
|
||||
@@ -0,0 +1,2 @@
|
||||
package A with Pure is
|
||||
end A;
|
||||
@@ -0,0 +1,2 @@
|
||||
project Default is
|
||||
end Default;
|
||||
163
testsuite/ada_lsp/commands.other_file.child_packages/test.json
Normal file
163
testsuite/ada_lsp/commands.other_file.child_packages/test.json
Normal file
@@ -0,0 +1,163 @@
|
||||
[
|
||||
{
|
||||
"comment": "Check that the 'als-other-file' command works fine with child packages"
|
||||
},
|
||||
{
|
||||
"start": {
|
||||
"cmd": ["${ALS}"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"send": {
|
||||
"request": {
|
||||
"jsonrpc": "2.0",
|
||||
"id": 0,
|
||||
"method": "initialize",
|
||||
"params": {
|
||||
"processId": 1,
|
||||
"rootUri": "$URI{.}",
|
||||
"capabilities": {}
|
||||
}
|
||||
},
|
||||
"wait": [
|
||||
{
|
||||
"id": 0,
|
||||
"result": {
|
||||
"capabilities": {
|
||||
"textDocumentSync": 2,
|
||||
"executeCommandProvider": {
|
||||
"commands": ["<HAS>", "als-other-file"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"send": {
|
||||
"request": {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "workspace/didChangeConfiguration",
|
||||
"params": {
|
||||
"settings": {
|
||||
"ada": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"wait": [
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "window/workDoneProgress/create",
|
||||
"params": {
|
||||
"token": "<ANY>"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"send": {
|
||||
"request": {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "textDocument/didOpen",
|
||||
"params": {
|
||||
"textDocument": {
|
||||
"uri": "$URI{a-b.ads}",
|
||||
"languageId": "ada",
|
||||
"version": 1,
|
||||
"text": "package A.B is\n procedure Proc (X : in out Integer);\nend A.B;\n"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wait": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"send": {
|
||||
"request": {
|
||||
"jsonrpc": "2.0",
|
||||
"id": "sw1",
|
||||
"method": "workspace/executeCommand",
|
||||
"params": {
|
||||
"command": "als-other-file",
|
||||
"arguments": [
|
||||
{
|
||||
"uri": "$URI{a-b.ads}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"wait": [
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "window/showDocument",
|
||||
"params": {
|
||||
"uri": "$URI{a-b.adb}",
|
||||
"takeFocus": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "sw1",
|
||||
"result": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"send": {
|
||||
"request": {
|
||||
"jsonrpc": "2.0",
|
||||
"id": "sw2",
|
||||
"method": "workspace/executeCommand",
|
||||
"params": {
|
||||
"command": "als-other-file",
|
||||
"arguments": [
|
||||
{
|
||||
"uri": "$URI{a-b.adb}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"wait": [
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "window/showDocument",
|
||||
"params": {
|
||||
"uri": "$URI{a-b.ads}",
|
||||
"takeFocus": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "sw2",
|
||||
"result": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"send": {
|
||||
"request": {
|
||||
"jsonrpc": "2.0",
|
||||
"id": "shutdown",
|
||||
"method": "shutdown",
|
||||
"params": null
|
||||
},
|
||||
"wait": [{ "id": "shutdown", "result": null }]
|
||||
}
|
||||
},
|
||||
{
|
||||
"send": {
|
||||
"request": { "jsonrpc": "2.0", "method": "exit" },
|
||||
"wait": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"stop": {
|
||||
"exit_code": 0
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
title: 'commands.other_file'
|
||||
Reference in New Issue
Block a user