Skip to content

Commit c1d8fc6

Browse files
ogorodnikreznikmm
andcommitted
Apply 1 suggestion(s) to 1 file(s)
Co-authored-by: Max Reznik <reznik@adacore.com>
1 parent efdcba1 commit c1d8fc6

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

doc/extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ related resources.
6969
* [Project file](project_file.md)
7070
* [Source dirs](source_dirs.md)
7171
* [Workspace symbol params](workspace_symbol_params.md)
72+
* [Global/local variables](global_local_variables.md)
7273

7374
```{toctree}
7475
:maxdepth: 1

doc/global_local_variables.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Global/local variables
2+
3+
## Short introduction
4+
5+
This feature uses custom modifiers for SemanticTokenModifiers to mark
6+
global/local variable in the semanticTokens request.
7+
8+
9+
## Change description
10+
11+
We extend the `SemanticTokenModifiers` by adding extra modifiers:
12+
- "globalVariable" marks global variable
13+
- "localVariable" marks local variable

source/ada/lsp-ada_highlighters.adb

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ package body LSP.Ada_Highlighters is
766766
Node_Enclosing_Declarative_Part : constant Declarative_Part :=
767767
Laltools.Common.Get_Enclosing_Declarative_Part (Node);
768768

769-
Decl_Declarative_Part : Declarative_Part;
769+
Parent : Ada_Node;
770770
begin
771771
if Compare
772772
(Node_Enclosing_Declarative_Part.Sloc_Range,
@@ -775,29 +775,24 @@ package body LSP.Ada_Highlighters is
775775
Highlight_Token (Node.Token_Start, localVariable);
776776

777777
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;
778+
Parent := Decl.Parent;
779+
while not Parent.Is_Null loop
780+
if Parent.Kind in Ada_Subp_Body_Range
781+
or else Parent.Kind in Ada_Entry_Body
782+
then
783+
return;
784+
end if;
785+
Parent := Parent.Parent;
786+
end loop;
787+
788+
Highlight_Token (Node.Token_Start, globalVariable);
790789
end if;
791790
end Investigate_Variable;
792791

793792
begin
794793
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;
794+
when Ada_Generic_Formal_Obj_Decl =>
795+
Investigate_Variable;
801796

802797
when Ada_Entry_Index_Spec | Ada_Object_Decl |
803798
Ada_Single_Protected_Decl | Ada_Single_Task_Decl =>

0 commit comments

Comments
 (0)