Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions source/ada/lsp-ada_handlers.adb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,21 @@ package body LSP.Ada_Handlers is
Document : constant LSP.Ada_Documents.Document_Access :=
Self.Context.Get_Document (Value.textDocument.uri);

Definition : constant Libadalang.Analysis.Defining_Name :=
LSP.Lal_Utils.Resolve_Node (Document.Get_Node_At (Value.position));

use Libadalang.Analysis;

Name_Node : constant Name := LSP.Lal_Utils.Get_Node_As_Name
(Document.Get_Node_At (Value.position));

Definition : Defining_Name;

begin

if Name_Node = No_Name then
return;
end if;

Definition := LSP.Lal_Utils.Resolve_Name (Name_Node);

if Definition = No_Defining_Name then
return;
end if;
Expand Down Expand Up @@ -254,11 +262,20 @@ package body LSP.Ada_Handlers is
Document : constant LSP.Ada_Documents.Document_Access :=
Self.Context.Get_Document (Value.textDocument.uri);

Definition : constant Defining_Name :=
LSP.Lal_Utils.Resolve_Node (Document.Get_Node_At (Value.position));
Name_Node : constant Name := LSP.Lal_Utils.Get_Node_As_Name
(Document.Get_Node_At (Value.position));

Definition : Defining_Name;

begin
if Definition.Is_Null then

if Name_Node = No_Name then
return;
end if;

Definition := LSP.Lal_Utils.Resolve_Name (Name_Node);

if Definition = No_Defining_Name then
return;
end if;

Expand Down Expand Up @@ -294,6 +311,7 @@ package body LSP.Ada_Handlers is
end;
end loop;
end;

end Text_Document_References_Request;

----------------------------------
Expand Down
71 changes: 48 additions & 23 deletions source/ada/lsp-lal_utils.adb
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,75 @@ with Libadalang.Common; use Libadalang.Common;

package body LSP.Lal_Utils is

----------------------------
-- Get_Definition_In_Node --
----------------------------
----------------------
-- Get_Node_As_Name --
----------------------

function Get_Definition_In_Node (Node : Ada_Node) return Defining_Name is
function Get_Node_As_Name (Node : Ada_Node) return Name is
begin

if Node /= No_Ada_Node and then Node.Kind in Ada_Name then
declare
Name : constant Libadalang.Analysis.Name := Node.As_Name;
begin
if Name.P_Is_Defining then
return Name.P_Enclosing_Defining_Name;
end if;
end;
if Node = No_Ada_Node or else Node.Kind not in Ada_Name then
return No_Name;
end if;

return Node.As_Name;

end Get_Node_As_Name;

--------------------------
-- Get_Name_As_Defining --
--------------------------

function Get_Name_As_Defining (Name_Node : Name) return Defining_Name is
begin

if Name_Node = No_Name or else not Name_Node.P_Is_Defining then
return No_Defining_Name;
end if;

return No_Defining_Name;
return Name_Node.P_Enclosing_Defining_Name;

end Get_Definition_In_Node;
end Get_Name_As_Defining;

------------------
-- Resolve_Node --
-- Resolve_Name --
------------------

function Resolve_Node (Node : Ada_Node) return Defining_Name is
function Resolve_Name (Name_Node : Name) return Defining_Name is

Definition : Defining_Name := Get_Definition_In_Node (Node);
Definition : Defining_Name := Get_Name_As_Defining (Name_Node);

begin

if Definition = No_Defining_Name then

Definition :=
Node.P_Referenced_Decl.P_Canonical_Part.P_Defining_Name;
declare
Names : constant Defining_Name_Array :=
Name_Node.P_Referenced_Decl (Imprecise_Fallback => True)
.P_Canonical_Part.P_Defining_Names;
begin

for I in Names'Range loop

declare
Decl_Name : constant Defining_Name := Names (I);
begin

if Definition = No_Defining_Name then
return No_Defining_Name;
end if;
if P_Name_Matches (Decl_Name, Name_Node) then
Definition := Decl_Name;
exit;
end if;

end;

end loop;

end;

end if;

return Definition;

end Resolve_Node;
end Resolve_Name;

end LSP.Lal_Utils;
6 changes: 4 additions & 2 deletions source/ada/lsp-lal_utils.ads
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ with Libadalang.Analysis; use Libadalang.Analysis;

package LSP.Lal_Utils is

function Get_Definition_In_Node (Node : Ada_Node) return Defining_Name;
function Get_Node_As_Name (Node : Ada_Node) return Name;

function Resolve_Node (Node : Ada_Node) return Defining_Name;
function Get_Name_As_Defining (Name_Node : Name) return Defining_Name;

function Resolve_Name (Name_Node : Name) return Defining_Name;

end LSP.Lal_Utils;
7 changes: 4 additions & 3 deletions testsuite/ada_lsp/project_config/third.ads
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
generic
package To_Be_Called is
end;



procedure To_Be_Called (Text : String);
20 changes: 15 additions & 5 deletions testsuite/ada_lsp/project_config_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
"comment":[
"This test check language server is able to find a project file",
"specified in configuration. It tries to load wrong project and",
"get error after search for a custom named subprogram."
"specified in configuration. It tries to load 'wrong project' and",
"get other reply after search for a custom named subprogram."
]
}, {
"start": {
Expand Down Expand Up @@ -75,9 +75,19 @@
},
"wait":[{
"id": "defname-1",
"error":{
"code": -32603
}
"result":[{
"uri": "$URI{project_config/third.ads}",
"range": {
"start": {
"line": 3,
"character": 10
},
"end": {
"line": 3,
"character": 22
}
}
}]
}]
}
}, {
Expand Down