1717
1818with GNATCOLL.Traces ;
1919
20+ with Laltools ;
21+ with Laltools.Common ;
2022with Langkit_Support.Slocs ;
2123with Langkit_Support.Text ;
2224with Libadalang.Common ; use Libadalang.Common;
@@ -477,6 +479,7 @@ package body LSP.Ada_Highlighters is
477479 use all type LSP.Enumerations.SemanticTokenTypes;
478480 use all type LSP.Enumerations.SemanticTokenModifiers;
479481 use type Libadalang.Analysis.Defining_Name;
482+ use type Libadalang.Analysis.Ada_Node;
480483
481484 procedure Highlight_Token
482485 (Token : Libadalang.Common.Token_Reference;
@@ -497,6 +500,9 @@ package body LSP.Ada_Highlighters is
497500 function Is_Predefined (Decl : Libadalang.Analysis.Basic_Decl)
498501 return Boolean;
499502
503+ procedure Get_Variable_Modifiers (Decl : Libadalang.Analysis.Basic_Decl);
504+ -- Add variable's modifiers if Decl is a variable
505+
500506 -- ----------------
501507 -- Has_Abstract --
502508 -- ----------------
@@ -741,10 +747,75 @@ package body LSP.Ada_Highlighters is
741747 end case ;
742748 end To_Kind ;
743749
750+ -- --------------------------
751+ -- Get_Variable_Modifiers --
752+ -- --------------------------
753+
754+ procedure Get_Variable_Modifiers
755+ (Decl : Libadalang.Analysis.Basic_Decl)
756+ is
757+ -- ------------------------
758+ -- Investigate_Variable --
759+ -- ------------------------
760+
761+ procedure Investigate_Variable ;
762+ procedure Investigate_Variable is
763+ use Libadalang.Analysis;
764+ use Langkit_Support.Slocs;
765+
766+ Node_Enclosing_Declarative_Part : constant Declarative_Part :=
767+ Laltools.Common.Get_Enclosing_Declarative_Part (Node);
768+
769+ Decl_Declarative_Part : Declarative_Part;
770+ begin
771+ if Compare
772+ (Node_Enclosing_Declarative_Part.Sloc_Range,
773+ Decl.Sloc_Range.Start_Sloc) = Inside
774+ then
775+ Highlight_Token (Node.Token_Start, localVariable);
776+
777+ else
778+ Decl_Declarative_Part :=
779+ Laltools.Common.Get_Enclosing_Declarative_Part (Decl);
780+
781+ if Decl_Declarative_Part.Parent /= No_Ada_Node
782+ and then
783+ (Decl_Declarative_Part.Parent.Kind in
784+ Ada_Package_Body_Range
785+ or else Decl_Declarative_Part.Parent.Kind in
786+ Ada_Base_Package_Decl)
787+ then
788+ Highlight_Token (Node.Token_Start, globalVariable);
789+ end if ;
790+ end if ;
791+ end Investigate_Variable ;
792+
793+ begin
794+ case Decl.Kind is
795+ when Ada_Base_Formal_Param_Decl =>
796+ if Ada_Base_Formal_Param_Decl'(Decl.Kind) =
797+ Ada_Generic_Formal_Obj_Decl
798+ then
799+ Investigate_Variable;
800+ end if ;
801+
802+ when Ada_Entry_Index_Spec | Ada_Object_Decl |
803+ Ada_Single_Protected_Decl | Ada_Single_Task_Decl =>
804+ Investigate_Variable;
805+
806+ when Ada_For_Loop_Var_Decl |
807+ Ada_Extended_Return_Stmt_Object_Decl =>
808+ Highlight_Token (Node.Token_Start, localVariable);
809+
810+ when others =>
811+ null ;
812+ end case ;
813+ end Get_Variable_Modifiers ;
814+
744815 Failsafe_Decl : Libadalang.Analysis.Refd_Decl;
745- Def : Libadalang.Analysis.Defining_Name;
746- Decl : Libadalang.Analysis.Basic_Decl;
747- Kind : LSP.Enumerations.SemanticTokenTypes;
816+ Def : Libadalang.Analysis.Defining_Name;
817+ Decl : Libadalang.Analysis.Basic_Decl;
818+ Kind : LSP.Enumerations.SemanticTokenTypes;
748819 begin
749820 if Node.Kind not in Ada_Identifier | Ada_String_Literal then
750821 -- Highlight only identifiers and operator symbols
@@ -753,11 +824,10 @@ package body LSP.Ada_Highlighters is
753824
754825 if Node.P_Is_Defining then
755826 Def := Node.P_Enclosing_Defining_Name;
756-
757827 begin
758828 declare
759829 Is_Canonical : constant Boolean :=
760- not Def.Is_Null and then Def.P_Canonical_Part = Def;
830+ not Def.Is_Null and then Def.P_Canonical_Part = Def;
761831 begin
762832 if Is_Canonical then
763833 Highlight_Token (Node.Token_Start, declaration);
@@ -795,6 +865,14 @@ package body LSP.Ada_Highlighters is
795865 Highlight_Token (Node.Token_Start, Kind);
796866 end if ;
797867
868+ if Kind = variable
869+ -- not a declaration itself
870+ and then Laltools.Common.
871+ Find_First_Common_Parent (Decl, Node, True) /= Decl
872+ then
873+ Get_Variable_Modifiers (Decl);
874+ end if ;
875+
798876 begin
799877 if Kind in variable | parameter | typeParameter | property
800878 and then Decl.P_Is_Constant_Object
@@ -961,6 +1039,8 @@ package body LSP.Ada_Highlighters is
9611039 Append_Modifier (modification, " modification" );
9621040 Append_Modifier (documentation, " documentation" );
9631041 Append_Modifier (defaultLibrary, " defaultLibrary" );
1042+ Append_Modifier (globalVariable, " globalVariable" );
1043+ Append_Modifier (localVariable, " localVariable" );
9641044
9651045 Obsolescent := +" Obsolescent" ;
9661046 Ada_Package := +" Ada" ;
0 commit comments