Skip to content

Commit d08bb13

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

File tree

7 files changed

+102
-543
lines changed

7 files changed

+102
-543
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ section below it for the last release. -->
1616
* Provide an integration of the [e3-testsuite](https://github.com/AdaCore/e3-testsuite) framework with the VS Code testing UI
1717
* Provide an interactive options picker for GNATprove invocations
1818
* Automatically open SARIF reports generated by GNATprove
19+
* New SemanticTokenModifiers for global/local variables have been added.
1920

2021
## 26.0.202507021
2122

doc/Custom-colors-in-VS-Code.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Ada Language Server uses next modifiers of tokens:
5656
| modification | write access to a name
5757
| documentation | ghost code or aspect
5858
| defaultLibrary | predefined name
59+
| globalVariable | the variable exists during all time program execution
60+
| localVariable | the variable is local for the scope
5961

6062
## Example
6163

@@ -135,6 +137,8 @@ Open `settings.json` and append next:
135137
"*.modification": {"bold": true},
136138
"*.deprecated": {"strikethrough": true},
137139
"*.readonly": "#4FC1FF",
140+
"*.globalVariable": "#C92002",
141+
"*.localVariable": "#02A322",
138142
"property.readonly": "#3E52EB",
139143
"typeParameter.readonly": {"foreground": "#3E52EB", "italic": true},
140144
"*.documentation": "#6A9955",

doc/global_local_variables.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# Global/local variables
1+
# Global/Local Variables highlighting
22

33
## Short introduction
44

5-
This feature uses custom modifiers for SemanticTokenModifiers to mark
6-
global/local variable in the semanticTokens request.
7-
5+
This feature uses custom modifiers for `SemanticTokenModifiers` to mark **global** and **local** variables in the `semanticTokens` request.
86

97
## Change description
108

119
We extend the `SemanticTokenModifiers` by adding extra modifiers:
12-
- "globalVariable" marks global variable
13-
- "localVariable" marks local variable
10+
11+
* `globalVariable`: Marks a **global variable**. This refers to a variable whose **lifetime is the same as the program itself** (program-level visibility and duration). These variables are typically declared in the declarative part of a library-level package:
12+
* **Library-level packages**.
13+
* **Nested packages**, **Protected Objects** or **Tasks** that are themselves declared at the library level. .
14+
15+
The variable exists for the entire program execution and is not local to any locally declared subprogram or block.
16+
17+
* `localVariable`: Marks a **local variable**. This refers to a variable whose name is declared within the **nearest enclosing declarative part** (e.g., within a subprogram body, a block statement). Their scope and lifetime are typically restricted to that specific program element.
Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,18 @@
11

22
with Ada.Text_IO;
3-
with Ada.Strings.Unbounded;
43

54
package body A is
65

76
C : Boolean := True;
87

9-
type SemanticTokenModifiers is
10-
(declaration,
11-
definition,
12-
readonly,
13-
static,
14-
deprecated,
15-
an_abstract,
16-
async,
17-
modification,
18-
documentation,
19-
defaultLibrary,
20-
globalVariable,
21-
localVariable);
22-
23-
type Modifiers_Array is array (SemanticTokenModifiers) of Boolean;
24-
258
-----------
269
-- Print --
2710
-----------
2811

2912
procedure Print is
3013
B : Boolean := True;
31-
32-
function Correct_Name (Value : String) return String;
33-
34-
function Correct_Name (Value : String) return String is
35-
begin
36-
return Value;
37-
end Correct_Name;
38-
39-
function Get_Modifiers (Modifiers : Modifiers_Array) return String
40-
is
41-
use Ada.Strings.Unbounded;
42-
43-
M : Unbounded_String;
44-
begin
45-
for Index in SemanticTokenModifiers'Range loop
46-
if Modifiers (Index) then
47-
if Index = globalVariable
48-
or else Index = localVariable
49-
then
50-
M := "-" & Correct_Name
51-
(SemanticTokenModifiers'Image (Index)) & M;
52-
else
53-
Append (M, "-" & Correct_Name
54-
(SemanticTokenModifiers'Image (Index)));
55-
end if;
56-
end if;
57-
end loop;
58-
59-
return To_String (M);
60-
end Get_Modifiers;
61-
62-
begin
63-
Ada.Text_IO.Put_Line ("A");
64-
if B
65-
and then C
66-
and then D
67-
then
68-
null;
69-
end if;
70-
71-
Ada.Text_IO.Put_Line
72-
(Get_Modifiers ((deprecated => True, others => False)));
73-
end Print;
74-
75-
-----------
76-
-- Print --
77-
-----------
78-
79-
procedure Print (Value : String) is
8014
begin
81-
Ada.Text_IO.Put_Line (Value);
15+
Ada.Text_IO.Put_Line (B'Img & C'Img);
8216
end Print;
8317

8418
end A;

testsuite/ada_lsp/highlight_variables/a.ads

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,4 @@ package A is
22

33
procedure Print;
44

5-
procedure Print (Value : String);
6-
7-
type Print_Access is access procedure (Value : String);
8-
9-
private
10-
11-
D : Boolean := True;
12-
135
end A;

testsuite/ada_lsp/highlight_variables/main.adb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
with A;
33

44
procedure Main is
5-
use A;
65
begin
76
A.Print;
87
end Main;

0 commit comments

Comments
 (0)