Skip to content

Commit 8ff5864

Browse files
V823-006: Add nullity check in Code_Action handler
We can get a null node if the cursor is located on a comment or an empty line for instance. In that case, don't try to analyze the node to see which codeActions should be available. Add a minimal test.
1 parent 99dcad2 commit 8ff5864

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

source/ada/lsp-ada_handlers.adb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ package body LSP.Ada_Handlers is
12521252
-- Result with Code_Actions in this case. Return Done = True if futher
12531253
-- analysis has no sense.
12541254

1255-
procedure Append_Project_Status
1255+
procedure Append_Project_Status_Code_Actions
12561256
(Result : in out LSP.Messages.CodeAction_Vector);
12571257
-- Append project status code action if needed
12581258

@@ -1999,14 +1999,19 @@ package body LSP.Ada_Handlers is
19991999
Node : constant Libadalang.Analysis.Ada_Node :=
20002000
Document.Get_Node_At (Context.all, Params.span.first);
20012001
begin
2002+
if Node.Is_Null then
2003+
Found := False;
2004+
return;
2005+
end if;
2006+
20022007
Analyse_Node (Context, Node, Result, Found);
20032008
end Analyse_In_Context;
20042009

2005-
---------------------------
2006-
-- Append_Project_Status --
2007-
---------------------------
2010+
----------------------------------------
2011+
-- Append_Project_Status_Code_Actions --
2012+
----------------------------------------
20082013

2009-
procedure Append_Project_Status
2014+
procedure Append_Project_Status_Code_Actions
20102015
(Result : in out LSP.Messages.CodeAction_Vector)
20112016
is
20122017
use type VSS.Strings.Virtual_String;
@@ -2085,7 +2090,7 @@ package body LSP.Ada_Handlers is
20852090
when Invalid_Project_Configured =>
20862091
null;
20872092
end case;
2088-
end Append_Project_Status;
2093+
end Append_Project_Status_Code_Actions;
20892094

20902095
use type LSP.Messages.Position;
20912096

@@ -2110,7 +2115,7 @@ package body LSP.Ada_Handlers is
21102115
end loop;
21112116

21122117
if Params.span.first = (0, 0) then
2113-
Append_Project_Status (Response.result);
2118+
Append_Project_Status_Code_Actions (Response.result);
21142119
end if;
21152120

21162121
return Response;

0 commit comments

Comments
 (0)