diff --git a/source/ada/lsp-ada_handlers.adb b/source/ada/lsp-ada_handlers.adb index 85a97aa66..7d40316ff 100644 --- a/source/ada/lsp-ada_handlers.adb +++ b/source/ada/lsp-ada_handlers.adb @@ -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; @@ -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; @@ -294,6 +311,7 @@ package body LSP.Ada_Handlers is end; end loop; end; + end Text_Document_References_Request; ---------------------------------- diff --git a/source/ada/lsp-lal_utils.adb b/source/ada/lsp-lal_utils.adb index bc9cf8cbf..57b02d793 100644 --- a/source/ada/lsp-lal_utils.adb +++ b/source/ada/lsp-lal_utils.adb @@ -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; diff --git a/source/ada/lsp-lal_utils.ads b/source/ada/lsp-lal_utils.ads index ffeba5fb9..a8a4bc4d4 100644 --- a/source/ada/lsp-lal_utils.ads +++ b/source/ada/lsp-lal_utils.ads @@ -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; diff --git a/testsuite/ada_lsp/project_config/third.ads b/testsuite/ada_lsp/project_config/third.ads index b62a89723..003face66 100644 --- a/testsuite/ada_lsp/project_config/third.ads +++ b/testsuite/ada_lsp/project_config/third.ads @@ -1,3 +1,4 @@ -generic -package To_Be_Called is -end; + + + +procedure To_Be_Called (Text : String); diff --git a/testsuite/ada_lsp/project_config_2.json b/testsuite/ada_lsp/project_config_2.json index a3bfdcac2..cfb6046f1 100644 --- a/testsuite/ada_lsp/project_config_2.json +++ b/testsuite/ada_lsp/project_config_2.json @@ -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": { @@ -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 + } + } + }] }] } }, {