Skip to content

Commit

Permalink
Merge branch 'topic/resolve_conflict' into 'edge'
Browse files Browse the repository at this point in the history
Resolve conflict merge master -> edge

See merge request eng/ide/ada_language_server!1552
  • Loading branch information
AnthonyLeonardoGracio committed Apr 24, 2024
2 parents 924a518 + 4450b19 commit 4c50e83
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 397 deletions.
248 changes: 0 additions & 248 deletions source/ada/lsp-ada_documents.adb
Original file line number Diff line number Diff line change
Expand Up @@ -805,254 +805,6 @@ package body LSP.Ada_Documents is
end if;
end Get_Errors;

------------------------
-- Get_Folding_Blocks --
------------------------

procedure Get_Folding_Blocks
(Self : Document;
Context : LSP.Ada_Contexts.Context;
Lines_Only : Boolean;
Comments : Boolean;
Canceled : access function return Boolean;
Result : out LSP.Structures.FoldingRange_Vector)
is
use Libadalang.Common;
use Libadalang.Analysis;

Location : LSP.Structures.Location;
foldingRange : LSP.Structures.FoldingRange;
Have_With : Boolean := False;

function Parse (Node : Ada_Node'Class) return Visit_Status;
-- Includes Node location to the result if the node has "proper" kind

procedure Store_Span (Span : LSP.Structures.A_Range);
-- Include Span to the result .

-----------
-- Parse --
-----------

function Parse (Node : Ada_Node'Class) return Visit_Status
is

procedure Store_With_Block;
-- Store folding for with/use clauses as one folding block

----------------------
-- Store_With_Block --
----------------------

procedure Store_With_Block is
begin
if not Have_With then
return;
end if;

if foldingRange.startLine /= foldingRange.endLine then
Result.Append (foldingRange);
end if;

Have_With := False;
end Store_With_Block;

Result : Visit_Status := Into;
begin
if Canceled.all then
return Stop;
end if;

-- Cat_Namespace,
-- Cat_Constructor,
-- Cat_Destructor,
-- Cat_Structure,
-- Cat_Case_Inside_Record,
-- Cat_Union,
-- Cat_Custom

case Node.Kind is
when Ada_Package_Decl |
Ada_Generic_Formal_Package |
Ada_Package_Body |
-- Cat_Package

Ada_Type_Decl |

Ada_Classwide_Type_Decl |
-- Cat_Class

Ada_Protected_Type_Decl |
-- Cat_Protected

Ada_Task_Type_Decl |
Ada_Single_Task_Type_Decl |
-- Cat_Task

Ada_Subp_Decl |
Ada_Subp_Body |
Ada_Generic_Formal_Subp_Decl |
Ada_Abstract_Subp_Decl |
Ada_Abstract_Formal_Subp_Decl |
Ada_Concrete_Formal_Subp_Decl |
Ada_Generic_Subp_Internal |
Ada_Null_Subp_Decl |
Ada_Subp_Renaming_Decl |
Ada_Subp_Body_Stub |
Ada_Generic_Subp_Decl |
Ada_Generic_Subp_Instantiation |
Ada_Generic_Subp_Renaming_Decl |
Ada_Subp_Kind_Function |
Ada_Subp_Kind_Procedure |
Ada_Access_To_Subp_Def |
-- Cat_Procedure
-- Cat_Function
-- Cat_Method

Ada_Case_Stmt |
-- Cat_Case_Statement

Ada_If_Stmt |
-- Cat_If_Statement

Ada_For_Loop_Stmt |
Ada_While_Loop_Stmt |
-- Cat_Loop_Statement

Ada_Begin_Block |
Ada_Decl_Block |
-- Cat_Declare_Block
-- Cat_Simple_Block

-- Ada_Return_Stmt |
-- Ada_Extended_Return_Stmt |
Ada_Extended_Return_Stmt_Object_Decl |
-- Cat_Return_Block

Ada_Select_Stmt |
-- Cat_Select_Statement

Ada_Entry_Body |
-- Cat_Entry

Ada_Exception_Handler |
-- Cat_Exception_Handler

Ada_Pragma_Node_List |
Ada_Pragma_Argument_Assoc |
Ada_Pragma_Node |
-- Cat_Pragma

Ada_Aspect_Spec =>
-- Cat_Aspect

Store_With_Block;

foldingRange.kind :=
(Is_Set => True, Value => LSP.Enumerations.Region);

Location := Self.To_LSP_Location (Node.Sloc_Range);
Store_Span (Location.a_range);

when Ada_With_Clause |
Ada_Use_Package_Clause |
Ada_Use_Type_Clause =>

Location := Self.To_LSP_Location (Node.Sloc_Range);

if not Have_With then
Have_With := True;

foldingRange.kind :=
(Is_Set => True, Value => LSP.Enumerations.Imports);

foldingRange.startLine := Location.a_range.start.line;
end if;

foldingRange.endLine := Location.a_range.an_end.line;

-- Do not step into with/use clause
Result := Over;

when others =>
Store_With_Block;
end case;

return Result;
end Parse;

----------------
-- Store_Span --
----------------

procedure Store_Span (Span : LSP.Structures.A_Range) is
begin
if not Lines_Only
or else Span.start.line /= Span.an_end.line
then
foldingRange.startLine := Span.start.line;
foldingRange.endLine := Span.an_end.line;

if not Lines_Only then
foldingRange.startCharacter :=
(Is_Set => True,
Value => Span.start.character);

foldingRange.startCharacter :=
(Is_Set => True,
Value => Span.an_end.character);
end if;

Result.Append (foldingRange);
end if;
end Store_Span;

Token : Token_Reference;
Span : LSP.Structures.A_Range;
Root : constant Ada_Node'Class := Self.Unit (Context).Root;

begin
if not Root.Is_Null then
Traverse (Root, Parse'Access);
end if;

if not Comments then
-- do not process comments
return;
end if;

-- Looking for comments
foldingRange.kind := (Is_Set => False);
Token := First_Token (Self.Unit (Context));

while Token /= No_Token
and then not Canceled.all
loop
case Kind (Data (Token)) is
when Ada_Comment =>
if not foldingRange.kind.Is_Set then
foldingRange.kind :=
(Is_Set => True, Value => LSP.Enumerations.Comment);
Span := Self.To_A_Range (Sloc_Range (Data (Token)));
else
Span.an_end :=
Self.To_A_Range (Sloc_Range (Data (Token))).an_end;
end if;

when Ada_Whitespace =>
null;

when others =>
if foldingRange.kind.Is_Set then
Store_Span (Span);
foldingRange.kind := (Is_Set => False);
end if;
end case;

Token := Next (Token);
end loop;
end Get_Folding_Blocks;

---------------------------
-- Get_Formatting_Region --
---------------------------
Expand Down
10 changes: 0 additions & 10 deletions source/ada/lsp-ada_documents.ads
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,6 @@ package LSP.Ada_Documents is
Result : in out LSP.Ada_Completions.Completion_Maps.Map);
-- See Contexts.Get_Any_Symbol

procedure Get_Folding_Blocks
(Self : Document;
Context : LSP.Ada_Contexts.Context;
Lines_Only : Boolean;
Comments : Boolean;
Canceled : access function return Boolean;
Result : out LSP.Structures.FoldingRange_Vector);
-- Populate Result with code folding blocks in the document. If Lines_Only
-- is True does not return characters positions in lines.

function Get_Formatting_Region
(Self : Document;
Context : LSP.Ada_Contexts.Context;
Expand Down
10 changes: 10 additions & 0 deletions source/ada/lsp-ada_driver.adb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ with LSP.Ada_Declaration;
with LSP.Ada_Document_Symbol;
with LSP.Ada_Did_Change_Configurations;
with LSP.Ada_Did_Change_Document;
with LSP.Ada_Folding_Range;
with LSP.Ada_Hover;
with LSP.Ada_References;
with LSP.Ada_Handlers;
Expand Down Expand Up @@ -84,6 +85,7 @@ with LSP.Server_Notifications.DidChangeConfiguration;
with LSP.Server_Requests.Definition;
with LSP.Server_Requests.Declaration;
with LSP.Server_Requests.DocumentSymbol;
with LSP.Server_Requests.FoldingRange;
with LSP.Server_Requests.Hover;
with LSP.Server_Requests.References;
with LSP.Server_Requests.Tokens_Full;
Expand Down Expand Up @@ -211,6 +213,10 @@ procedure LSP.Ada_Driver is
LSP.Ada_Document_Symbol.Ada_Document_Symbol_Handler
(Ada_Handler'Unchecked_Access);

Ada_Folding_Range_Handler : aliased
LSP.Ada_Folding_Range.Ada_Folding_Range_Handler
(Ada_Handler'Unchecked_Access);

Ada_Tokens_Full_Handler : aliased
LSP.Ada_Tokens_Full.Ada_Tokens_Full_Handler
(Ada_Handler'Unchecked_Access);
Expand Down Expand Up @@ -443,6 +449,10 @@ begin
(LSP.Server_Requests.DocumentSymbol.Request'Tag,
Ada_Document_Symbol_Handler'Unchecked_Access);

Server.Register_Handler
(LSP.Server_Requests.FoldingRange.Request'Tag,
Ada_Folding_Range_Handler'Unchecked_Access);

Server.Register_Handler
(LSP.Server_Requests.Tokens_Full.Request'Tag,
Ada_Tokens_Full_Handler'Unchecked_Access);
Expand Down
Loading

0 comments on commit 4c50e83

Please sign in to comment.