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

Commit 2817588

Browse files
authored
Fix tree-sitter annotations (#242)
### 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 adds missing annotations with scoped identifiers. Previously we only handled single identifiers. This fixes the following cases: ```java class A { @Test.Annotation @Test.Annotation() void func() { // test } } ``` ### 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 #239
1 parent 3f1bb76 commit 2817588

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

grammars/tree-sitter-java.cson

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,17 @@ scopes:
253253

254254
'marker_annotation': 'meta.declaration.annotation'
255255
'marker_annotation > "@"': 'punctuation.definition.annotation'
256-
'marker_annotation > identifier': 'storage.type.annotation'
256+
'''
257+
marker_annotation > identifier,
258+
marker_annotation > scoped_identifier > identifier
259+
''': 'storage.type.annotation'
257260

258261
'annotation': 'meta.declaration.annotation'
259262
'annotation > "@"': 'punctuation.definition.annotation'
260-
'annotation > identifier': 'storage.type.annotation'
263+
'''
264+
annotation > identifier,
265+
annotation > scoped_identifier > identifier
266+
''': 'storage.type.annotation'
261267

262268
'element_value_pair > identifier': 'variable.other.annotation.element'
263269

spec/tree-sitter-java-spec.coffee

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,8 @@ describe 'Tree-sitter based Java grammar', ->
900900
@Annotation2()
901901
@Annotation3("value")
902902
@Annotation4(key = "value")
903+
@Test.Annotation5
904+
@Test.Annotation6()
903905
class A { }
904906
'''
905907

@@ -925,6 +927,18 @@ describe 'Tree-sitter based Java grammar', ->
925927
expect(tokens[3][7]).toEqual value: '\"value\"', scopes: ['source.java', 'meta.declaration.annotation', 'string.quoted.double']
926928
expect(tokens[3][8]).toEqual value: ')', scopes: ['source.java', 'meta.declaration.annotation', 'punctuation.bracket.round']
927929

930+
expect(tokens[4][0]).toEqual value: '@', scopes: ['source.java', 'meta.declaration.annotation', 'punctuation.definition.annotation']
931+
expect(tokens[4][1]).toEqual value: 'Test', scopes: ['source.java', 'meta.declaration.annotation', 'storage.type.annotation']
932+
expect(tokens[4][2]).toEqual value: '.', scopes: ['source.java', 'meta.declaration.annotation', 'punctuation.separator.period']
933+
expect(tokens[4][3]).toEqual value: 'Annotation5', scopes: ['source.java', 'meta.declaration.annotation', 'storage.type.annotation']
934+
935+
expect(tokens[5][0]).toEqual value: '@', scopes: ['source.java', 'meta.declaration.annotation', 'punctuation.definition.annotation']
936+
expect(tokens[5][1]).toEqual value: 'Test', scopes: ['source.java', 'meta.declaration.annotation', 'storage.type.annotation']
937+
expect(tokens[5][2]).toEqual value: '.', scopes: ['source.java', 'meta.declaration.annotation', 'punctuation.separator.period']
938+
expect(tokens[5][3]).toEqual value: 'Annotation6', scopes: ['source.java', 'meta.declaration.annotation', 'storage.type.annotation']
939+
expect(tokens[5][4]).toEqual value: '(', scopes: ['source.java', 'meta.declaration.annotation', 'punctuation.bracket.round']
940+
expect(tokens[5][5]).toEqual value: ')', scopes: ['source.java', 'meta.declaration.annotation', 'punctuation.bracket.round']
941+
928942
it 'tokenizes constructor declarations', ->
929943
tokens = tokenizeLines '''
930944
class A {

0 commit comments

Comments
 (0)