Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic-merge committed Mar 6, 2024
2 parents 91b229c + ad4d590 commit 5a376d5
Show file tree
Hide file tree
Showing 27 changed files with 2,005 additions and 18 deletions.
19 changes: 18 additions & 1 deletion source/gpr/lsp-gpr_documents.adb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
-- of the license. --
------------------------------------------------------------------------------

with Ada.Exceptions;

with GPR2.Message;
with GPR2.Source_Reference;

package body LSP.GPR_Documents is

Expand Down Expand Up @@ -171,12 +174,26 @@ package body LSP.GPR_Documents is
Update_Diagnostics;

exception
when GPR2.Project_Error | GPR2.Processing_Error =>

Update_Diagnostics;

when E : others =>

Self.Tracer.Trace_Exception (E);

Update_Diagnostics;
Self.Tree.Log_Messages.Append
(GPR2.Message.Create
(Level => GPR2.Message.Error,
Message => "GPR parser unexpected " &
Ada.Exceptions.Exception_Name (E) & " " &
Ada.Exceptions.Exception_Message (E),
Sloc => GPR2.Source_Reference.Create
(Filename => Self.File.Value,
Line => 1,
Column => 1)));

Update_Diagnostics;
end Load;

-----------------------------
Expand Down
4 changes: 2 additions & 2 deletions source/gpr/lsp-gpr_external_tools.adb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- Language Server Protocol --
-- --
-- Copyright (C) 2023, AdaCore --
-- Copyright (C) 2023-2024, AdaCore --
-- --
-- This 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- --
Expand Down Expand Up @@ -184,7 +184,7 @@ package body LSP.GPR_External_Tools is
Inherit_From_Extended => Inherit_From_Extended,
Is_Set => Is_Set);
end if;
if Get_Attribute_Description (Name)'Length > 0
if Get_Attribute_Description (Name)'Length = 0
and then Description'Length > 0
then
Set_Attribute_Description (Name, Description);
Expand Down
53 changes: 40 additions & 13 deletions source/gpr/lsp-gpr_files.adb
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,47 @@ package body LSP.GPR_Files is

package LKD renames LSP.Text_Documents.Langkit_Documents;

function To_Valid_Name
(Name : VSS.Strings.Virtual_String)
return VSS.Strings.Virtual_String;
-- Avoid empty Name, set Name to " " when required.

procedure Append_New_To_Current (New_Symbol : Symbol);
-- Append New_Symbol to current list.

---------------------------
-- Append_New_To_Current --
---------------------------

procedure Append_New_To_Current (New_Symbol : Symbol) is
begin
Current_Symbols.Append (New_Symbol);
end Append_New_To_Current;

-------------------
-- To_Valid_Name --
-------------------

function To_Valid_Name
(Name : VSS.Strings.Virtual_String)
return VSS.Strings.Virtual_String is

begin
if Name.Is_Empty
then
-- avoid name: "", in documentSymbol.
return " ";
else
return Name;
end if;
end To_Valid_Name;

New_Symbol : Symbol :=
(New_Id,
Current_Symbol.Id,
Token.Ref,
Kind,
Name,
To_Valid_Name (Name),
LKD.To_A_Range
(Start_Line_Text =>
File.Get_Line (Location_Range.Start_Line),
Expand All @@ -489,18 +524,6 @@ package body LSP.GPR_Files is
LK_Slocs.Column_Number
(Location_Range.End_Column))));

procedure Append_New_To_Current (New_Symbol : Symbol);
-- Append New_Symbol to current list.

---------------------------
-- Append_New_To_Current --
---------------------------

procedure Append_New_To_Current (New_Symbol : Symbol) is
begin
Current_Symbols.Append (New_Symbol);
end Append_New_To_Current;

begin
case Kind is
when K_Imported =>
Expand Down Expand Up @@ -1466,6 +1489,10 @@ package body LSP.GPR_Files is
else
return Path_Name.Undefined;
end if;
exception
when E : others =>
File.Tracer.Trace_Exception (E);
return Path_Name.Undefined;
end Get_Referenced_GPR;

end LSP.GPR_Files;
4 changes: 4 additions & 0 deletions source/gpr/lsp-gpr_files.ads
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ package LSP.GPR_Files is
return LSP.Structures.DocumentUri is abstract;
-- Turn GPR2 path object into URI.

function Tracer
(Self : access File_Provider)
return LSP.Tracers.Tracer_Access is abstract;

procedure Initialize
(Self : in out File;
Path : GPR2.Path_Name.Object;
Expand Down
5 changes: 5 additions & 0 deletions source/gpr/lsp-gpr_handlers.ads
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,9 @@ private
Document : not null LSP.GPR_Documents.Document_Access);
-- Publish diagnostic messages for given document if needed

overriding function Tracer
(Self : access Message_Handler)
return LSP.Tracers.Tracer_Access is
(Self.Tracer);

end LSP.GPR_Handlers;
14 changes: 14 additions & 0 deletions testsuite/gpr_lsp/gpr2_assertions/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@
"params": {
"uri": "$URI{prj.gpr}",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"severity": 1,
"message": "GPR parser unexpected ADA.ASSERTIONS.ASSERTION_ERROR DYNAMIC_PREDICATE failed at gpr2-message.adb:23"
}
]
}
}
Expand Down
12 changes: 12 additions & 0 deletions testsuite/gpr_lsp/gpr2_unexpected_exceptions/prj.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
with "";
project Prj is
for Source_List_File use "";
for Excluded_Source_List_File use "";
for Warning_Message use "";
package Naming is
for Body ("Ada") use "" ;
for Implementation ("Ada") use "";
for Spec ("Ada") use "";
for Specification ("Ada") use "";
end Naming;
end Prj;
136 changes: 136 additions & 0 deletions testsuite/gpr_lsp/gpr2_unexpected_exceptions/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
[
{
"comment": [
"test gpr unexpected exception handling"
]
},
{
"start": {
"cmd": [
"${ALS}",
"--language-gpr"
]
}
},
{
"send": {
"request": {
"params": {
"processId": 30612,
"capabilities": {
"workspace": {
"applyEdit": false
}
},
"rootUri": "$URI{.}"
},
"jsonrpc": "2.0",
"id": 1,
"method": "initialize"
},
"wait": [
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"capabilities": {
"textDocumentSync": {
"openClose": true,
"change": 1
},
"completionProvider": {
"triggerCharacters": [
" "
],
"resolveProvider": true
},
"hoverProvider": true,
"definitionProvider": true,
"documentSymbolProvider": {}
}
}
}
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "initialized"
},
"wait": []
}
},
{
"send": {
"request": {
"params": {
"textDocument": {
"text": "with \"\";\nproject Prj is\n for Source_List_File use \"\";\n for Excluded_Source_List_File use \"\";\n for Warning_Message use \"\";\n package Naming is\n for Body (\"Ada\") use \"\" ;\n for Implementation (\"Ada\") use \"\";\n for Spec (\"Ada\") use \"\";\n for Specification (\"Ada\") use \"\";\n end Naming;\nend Prj;",
"version": 0,
"uri": "$URI{prj.gpr}",
"languageId": "Gpr"
}
},
"jsonrpc": "2.0",
"method": "textDocument/didOpen"
},
"wait": [
{
"jsonrpc": "2.0",
"method": "textDocument/publishDiagnostics",
"params": {
"uri": "$URI{prj.gpr}",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"severity": 1,
"message": "GPR parser unexpected ADA.ASSERTIONS.ASSERTION_ERROR DYNAMIC_PREDICATE failed at gpr2-project-parser.adb:83"
}
]
}
}
]
}
},
{
"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
}
}
]
1 change: 1 addition & 0 deletions testsuite/gpr_lsp/gpr2_unexpected_exceptions/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title: 'gpr2 parsing assertions error handling'
3 changes: 3 additions & 0 deletions testsuite/gpr_lsp/hover/prj1.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ for Source_Dirs use ("src");
package Compiler is
for Switches ("Ada") use ();
end Compiler;
package IDE is
for Artifacts_Dir use "";
end IDE;
end Prj1;
Loading

0 comments on commit 5a376d5

Please sign in to comment.