Skip to content

Commit 9e75ad9

Browse files
committed
Merge branch 'als_1738' into 'master'
Register ALS custom token modifiers in VS Code See merge request eng/ide/ada_language_server!2155
2 parents a636d75 + 3420145 commit 9e75ad9

File tree

6 files changed

+50
-25
lines changed

6 files changed

+50
-25
lines changed

integration/vscode/ada/package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@
108108
"path": "./syntaxes/gpr.tmLanguage.json"
109109
}
110110
],
111+
"semanticTokenModifiers": [
112+
{
113+
"id": "globalVariable",
114+
"description": "Annotates a variable with the executable's lifetime"
115+
},
116+
{
117+
"id": "localVariable",
118+
"description": "Annotates a variable that is local to the code block"
119+
}
120+
],
111121
"semanticTokenScopes": [
112122
{
113123
"language": "ada",
@@ -261,7 +271,13 @@
261271
],
262272
"operator.defaultLibrary": [
263273
"support.function.operator.ada"
264-
]
274+
],
275+
"variable.globalVariable": [
276+
"variable.other.global.ada"
277+
],
278+
"variable.localVariable": [
279+
"variable.other.local.ada"
280+
]
265281
}
266282
}
267283
],

integration/vscode/ada/src/alsClientFeatures.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ export class ALSClientFeatures implements StaticFeature {
4646
* that this client can provide user inputs
4747
*/
4848
fillClientCapabilities(capabilities: ClientCapabilities): void {
49+
// add custom ALS token modifiers as "known"
50+
if (capabilities.textDocument !== undefined) {
51+
if (capabilities.textDocument.semanticTokens !== undefined) {
52+
capabilities.textDocument.semanticTokens.tokenModifiers =
53+
capabilities.textDocument.semanticTokens.tokenModifiers.concat([
54+
'globalVariable',
55+
'localVariable',
56+
]);
57+
}
58+
}
59+
4960
const advanced_refactorings = [
5061
'add_parameter',
5162
'change_parameters_type',

integration/vscode/ada/test/general/ws/src/highlighting/lsp-ada_handlers/lsp-ada_handlers.adb.sem.tokens

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ line 58: column 4 - 33: variable [declaration, readonly] : Allow
5656
line 64: column 4 - 12: variable [declaration, readonly] : Is_Parent
5757
line 67: column 4 - 11: variable [declaration, readonly] : Is_Child
5858
line 72: column 4 - 12: variable [declaration, readonly] : Line_Feed
59-
line 72: column 61 - 62: variable [readonly, static, defaultLibrary] : LF
59+
line 72: column 61 - 62: variable [readonly, static, defaultLibrary, globalVariable] : LF
6060
line 74: column 13 - 15: function [declaration] : "+"
6161
line 74: column 18 - 21: parameter [declaration, readonly] : Text
6262
line 74: column 25 - 27: namespace [defaultLibrary] : Ada

integration/vscode/ada/test/general/ws/src/highlighting/pkgs-and-specs/pkgbodynospec.adb.sem.tokens

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ line 6: column 27 - 30: parameter [declaration, readonly] : Arg2
66
line 7: column 7 - 7: variable [declaration] : Y
77
line 7: column 22 - 25: parameter [readonly] : Arg1
88
line 7: column 29 - 32: parameter [readonly] : Arg2
9-
line 7: column 36 - 42: variable : Global1
9+
line 7: column 36 - 42: variable [globalVariable] : Global1
1010
line 10: column 8 - 12: function : Proc1
1111
line 12: column 13 - 20: function [declaration] : Expr_Fct
1212
line 12: column 23 - 26: parameter [declaration, readonly] : Arg1
1313
line 12: column 29 - 32: parameter [declaration, readonly] : Arg2
1414
line 13: column 8 - 11: parameter [readonly] : Arg1
1515
line 13: column 15 - 18: parameter [readonly] : Arg2
16-
line 13: column 22 - 28: variable : Global1
16+
line 13: column 22 - 28: variable [globalVariable] : Global1
1717
line 15: column 14 - 18: function [declaration] : Proc2
1818
line 15: column 21 - 24: parameter [declaration, readonly] : Arg1
1919
line 15: column 27 - 30: parameter [declaration, readonly] : Arg2
@@ -24,6 +24,6 @@ line 17: column 11 - 14: parameter [readonly] : Arg1
2424
line 17: column 18 - 21: parameter [readonly] : Arg2
2525
line 17: column 25 - 28: parameter [readonly] : Arg3
2626
line 17: column 32 - 35: parameter [readonly] : Arg4
27-
line 17: column 39 - 45: variable : Global1
27+
line 17: column 39 - 45: variable [globalVariable] : Global1
2828
line 20: column 8 - 12: function : Proc2
2929
line 22: column 5 - 17: namespace : PkgBodyNoSpec

integration/vscode/ada/test/general/ws/src/highlighting/pkgs-and-specs/pkgbodywithspec.adb.sem.tokens

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ line 5: column 7 - 7: variable [declaration] : Y
99
line 5: column 11 - 17: type [static, defaultLibrary] : Integer
1010
line 5: column 22 - 25: parameter [readonly] : Arg1
1111
line 5: column 29 - 32: parameter [readonly] : Arg2
12-
line 5: column 36 - 42: variable : Global1
12+
line 5: column 36 - 42: variable [globalVariable] : Global1
1313
line 8: column 8 - 12: function : Proc1
1414
line 10: column 13 - 20: function [declaration] : Expr_Fct
1515
line 10: column 23 - 26: parameter [declaration, readonly] : Arg1
@@ -18,7 +18,7 @@ line 10: column 36 - 42: type [static, defaultLibrary] : Integ
1818
line 10: column 52 - 58: type [static, defaultLibrary] : Integer
1919
line 11: column 8 - 11: parameter [readonly] : Arg1
2020
line 11: column 15 - 18: parameter [readonly] : Arg2
21-
line 11: column 22 - 28: variable : Global1
21+
line 11: column 22 - 28: variable [globalVariable] : Global1
2222
line 13: column 14 - 18: function [declaration] : Proc2
2323
line 13: column 21 - 24: parameter [declaration, readonly] : Arg1
2424
line 13: column 27 - 30: parameter [declaration, readonly] : Arg2
@@ -32,6 +32,6 @@ line 15: column 11 - 14: parameter [readonly] : Arg1
3232
line 15: column 18 - 21: parameter [readonly] : Arg2
3333
line 15: column 25 - 28: parameter [readonly] : Arg3
3434
line 15: column 32 - 35: parameter [readonly] : Arg4
35-
line 15: column 39 - 45: variable : Global1
35+
line 15: column 39 - 45: variable [globalVariable] : Global1
3636
line 18: column 8 - 12: function : Proc2
3737
line 20: column 5 - 19: namespace : PkgBodyWithSpec

source/ada/lsp-ada_highlighters.adb

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

769-
Parent : Ada_Node;
769+
Parent : Ada_Node := Decl.Parent;
770770
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-
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
771+
while not Parent.Is_Null loop
772+
if Parent.Kind in Ada_Subp_Body_Range
773+
or else Parent.Kind in Ada_Entry_Body
774+
then
775+
if Compare
776+
(Node_Enclosing_Declarative_Part.Sloc_Range,
777+
Decl.Sloc_Range.Start_Sloc) = Inside
782778
then
783-
return;
779+
Highlight_Token (Node.Token_Start, localVariable);
784780
end if;
785-
Parent := Parent.Parent;
786-
end loop;
787781

788-
Highlight_Token (Node.Token_Start, globalVariable);
789-
end if;
782+
return;
783+
end if;
784+
Parent := Parent.Parent;
785+
end loop;
786+
787+
Highlight_Token (Node.Token_Start, globalVariable);
790788
end Investigate_Variable;
791789

792790
begin

0 commit comments

Comments
 (0)