Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit a757708

Browse files
authored
Fix tree-sitter constants (#241)
### Requirements * Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion. * All new code requires tests to ensure against regressions ### Description of the Change This PR fixes syntax highlighting for constants when using tree-sitter. Examples that are fixed now: ```java d = A1_B2_C3; e = A1_B2_C$; f = Test.A1_B2_C3; ``` ### Alternate Designs N/A ### Benefits N/A ### Possible Drawbacks <!-- What are the possible side-effects or negative impacts of the code change? --> ### Applicable Issues Fixes #240
1 parent 2817588 commit a757708

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

grammars/tree-sitter-java.cson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ scopes:
298298
method_reference > identifier,
299299
method_invocation > identifier
300300
''': [
301-
{match: '^[A-Z][A-Z_]+$', scopes: 'constant.other'},
301+
{match: '^[A-Z][A-Z0-9_\\$]+$', scopes: 'constant.other'},
302302
{match: '^[A-Z]', scopes: 'storage.type'}
303303
]
304304
'identifier': [
305-
{match: '^[A-Z][A-Z_]+$', scopes: 'constant.other'}
305+
{match: '^[A-Z][A-Z0-9_\\$]+$', scopes: 'constant.other'}
306306
]

spec/tree-sitter-java-spec.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,18 @@ describe 'Tree-sitter based Java grammar', ->
246246
a = CONSTANT + obj.func();
247247
b = conf.get(CONSTANT_ANOTHER);
248248
c = Integer.MAX_VALUE;
249+
d = A1_B2_C3;
250+
e = A1_B2_C$;
251+
f = Test.A1_B2_C3;
249252
'''
250253

251254
expect(tokens[0][2]).toEqual value: 'CONSTANT_STR', scopes: ['source.java', 'constant.other']
252255
expect(tokens[1][3]).toEqual value: 'CONSTANT', scopes: ['source.java', 'constant.other']
253256
expect(tokens[2][6]).toEqual value: 'CONSTANT_ANOTHER', scopes: ['source.java', 'constant.other']
254257
expect(tokens[3][5]).toEqual value: 'MAX_VALUE', scopes: ['source.java', 'constant.other']
258+
expect(tokens[4][3]).toEqual value: 'A1_B2_C3', scopes: ['source.java', 'constant.other']
259+
expect(tokens[5][3]).toEqual value: 'A1_B2_C$', scopes: ['source.java', 'constant.other']
260+
expect(tokens[6][5]).toEqual value: 'A1_B2_C3', scopes: ['source.java', 'constant.other']
255261

256262
it 'tokenizes reserved keywords', ->
257263
tokens = tokenizeLine 'const value;'

0 commit comments

Comments
 (0)