Skip to content

Commit dd48b8f

Browse files
committed
Add some more specific scopes for member access.
Add `meta.attribute.python` to mark otherwise non-special attributes. Add `meta.indexed-name.python` to mark the name of the object being indexed. In combination with `meta.member.access.python` the above scopes can help highlight member access that is no otherwise using a builtin or some other special case. For highlighting method names in method calls the combination of `meta.member.access.python` and `meta.function-call.generic.python` could be used. Fixes #188.
1 parent 0b09c1f commit dd48b8f

21 files changed

+110
-63
lines changed

grammars/MagicPython.cson

+12
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ repository:
431431
{
432432
include: "#member-access-base"
433433
}
434+
{
435+
include: "#member-access-attribute"
436+
}
434437
]
435438
"member-access-base":
436439
patterns: [
@@ -453,6 +456,14 @@ repository:
453456
include: "#item-access"
454457
}
455458
]
459+
"member-access-attribute":
460+
comment: "Highlight attribute access in otherwise non-specialized cases."
461+
name: "meta.attribute.python"
462+
match: '''
463+
(?x)
464+
\\b ([[:alpha:]_]\\w*) \\b
465+
466+
'''
456467
"special-names":
457468
name: "constant.other.caps.python"
458469
match: '''
@@ -1488,6 +1499,7 @@ repository:
14881499
include: "#special-names"
14891500
}
14901501
{
1502+
name: "meta.indexed-name.python"
14911503
match: '''
14921504
(?x)
14931505
\\b ([[:alpha:]_]\\w*) \\b

grammars/MagicPython.tmLanguage

+17
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ it's probably control flow like:
647647
<key>include</key>
648648
<string>#member-access-base</string>
649649
</dict>
650+
<dict>
651+
<key>include</key>
652+
<string>#member-access-attribute</string>
653+
</dict>
650654
</array>
651655
</dict>
652656
<key>member-access-base</key>
@@ -679,6 +683,17 @@ it's probably control flow like:
679683
</dict>
680684
</array>
681685
</dict>
686+
<key>member-access-attribute</key>
687+
<dict>
688+
<key>comment</key>
689+
<string>Highlight attribute access in otherwise non-specialized cases.</string>
690+
<key>name</key>
691+
<string>meta.attribute.python</string>
692+
<key>match</key>
693+
<string>(?x)
694+
\b ([[:alpha:]_]\w*) \b
695+
</string>
696+
</dict>
682697
<key>special-names</key>
683698
<dict>
684699
<key>name</key>
@@ -2340,6 +2355,8 @@ it's probably control flow like:
23402355
<string>#special-names</string>
23412356
</dict>
23422357
<dict>
2358+
<key>name</key>
2359+
<string>meta.indexed-name.python</string>
23432360
<key>match</key>
23442361
<string>(?x)
23452362
\b ([[:alpha:]_]\w*) \b

grammars/src/MagicPython.syntax.yaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ repository:
449449
patterns:
450450
- include: '#function-call'
451451
- include: '#member-access-base'
452+
- include: '#member-access-attribute'
452453

453454
member-access-base:
454455
patterns:
@@ -459,6 +460,13 @@ repository:
459460
- include: '#line-continuation'
460461
- include: '#item-access'
461462

463+
member-access-attribute:
464+
comment: Highlight attribute access in otherwise non-specialized cases.
465+
name: meta.attribute.python
466+
match: |
467+
(?x)
468+
\b ([[:alpha:]_]\w*) \b
469+
462470
special-names:
463471
name: constant.other.caps.python
464472
match: |
@@ -1142,7 +1150,8 @@ repository:
11421150
- include: '#special-variables'
11431151
- include: '#builtin-functions'
11441152
- include: '#special-names'
1145-
- match: |
1153+
- name: meta.indexed-name.python
1154+
match: |
11461155
(?x)
11471156
\b ([[:alpha:]_]\w*) \b
11481157

misc/scopes

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ keyword.operator.python
6060
keyword.operator.quantifier.regexp
6161
keyword.operator.unpacking.arguments.python
6262
keyword.operator.unpacking.parameter.python
63+
meta.attribute.python
6364
meta.backreference.named.regexp
6465
meta.backreference.regexp
6566
meta.character.set.regexp
@@ -73,6 +74,7 @@ meta.function-call.python
7374
meta.function.decorator.python
7475
meta.function.parameters.python
7576
meta.function.python
77+
meta.indexed-name.python
7678
meta.item-access.python
7779
meta.lambda-function.python
7880
meta.member.access.python

test/atom-spec/python-spec.js

+31-31
Large diffs are not rendered by default.

test/builtins/builtins3.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
__builtins__ : source.python, support.variable.magic.python
7272
__builtins__ : source.python, support.variable.magic.python
7373
. : meta.member.access.python, punctuation.separator.period.python, source.python
74-
len : meta.member.access.python, source.python
74+
len : meta.attribute.python, meta.member.access.python, source.python
7575
print : meta.function-call.python, source.python, support.function.builtin.python
7676
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
7777
__builtins__ : meta.function-call.arguments.python, meta.function-call.python, source.python, support.variable.magic.python
@@ -183,4 +183,4 @@
183183
__traceback__ : meta.member.access.python, source.python, support.variable.magic.python
184184
some : source.python
185185
. : meta.member.access.python, punctuation.separator.period.python, source.python
186-
__notspecial__ : meta.member.access.python, source.python
186+
__notspecial__ : meta.attribute.python, meta.member.access.python, source.python

test/builtins/builtins4.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
some : source.python
1212
. : meta.member.access.python, punctuation.separator.period.python, source.python
13-
int : meta.member.access.python, source.python
13+
int : meta.attribute.python, meta.member.access.python, source.python
1414
some : source.python
1515
. : meta.member.access.python, punctuation.separator.period.python, source.python
16-
sum : meta.member.access.python, source.python
16+
sum : meta.attribute.python, meta.member.access.python, source.python
1717
some : source.python
1818
. : meta.member.access.python, punctuation.separator.period.python, source.python
19-
super : meta.member.access.python, source.python
19+
super : meta.attribute.python, meta.member.access.python, source.python
2020
some : source.python
2121
. : meta.member.access.python, punctuation.separator.period.python, source.python
22-
unicode : meta.member.access.python, source.python
22+
unicode : meta.attribute.python, meta.member.access.python, source.python
2323
some : source.python
2424
. : meta.member.access.python, punctuation.separator.period.python, source.python
25-
foo : meta.member.access.python, source.python
25+
foo : meta.attribute.python, meta.member.access.python, source.python
2626
some : source.python
2727
. : meta.member.access.python, punctuation.separator.period.python, source.python
28-
Exception : meta.member.access.python, source.python
28+
Exception : meta.attribute.python, meta.member.access.python, source.python

test/calls/call1.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44

5+
56
some_call : meta.function-call.generic.python, meta.function-call.python, source.python
67
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
78
A : meta.function-call.arguments.python, meta.function-call.python, source.python
@@ -10,7 +11,7 @@
1011
b : meta.function-call.arguments.python, meta.function-call.python, source.python
1112
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
1213
: meta.function-call.arguments.python, meta.function-call.python, source.python
13-
c : meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, source.python
14+
c : meta.function-call.arguments.python, meta.function-call.python, meta.indexed-name.python, meta.item-access.python, source.python
1415
[ : meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, punctuation.definition.arguments.begin.python, source.python
1516
1 : constant.numeric.dec.python, meta.function-call.arguments.python, meta.function-call.python, meta.item-access.arguments.python, meta.item-access.python, source.python
1617
] : meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, punctuation.definition.arguments.end.python, source.python

test/calls/call4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
. : meta.member.access.python, punctuation.separator.period.python, source.python
3030
None : keyword.illegal.name.python, meta.member.access.python, source.python
3131
. : meta.member.access.python, punctuation.separator.period.python, source.python
32-
baz : meta.member.access.python, source.python
32+
baz : meta.attribute.python, meta.member.access.python, source.python

test/calls/print1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
>> : keyword.operator.bitwise.python, source.python
5858
sys : source.python
5959
. : meta.member.access.python, punctuation.separator.period.python, source.python
60-
stderr : meta.member.access.python, source.python
60+
stderr : meta.attribute.python, meta.member.access.python, source.python
6161
, : punctuation.separator.element.python, source.python
6262
: source.python
6363
" : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
@@ -74,7 +74,7 @@
7474
= : keyword.operator.assignment.python, meta.function-call.arguments.python, meta.function-call.python, source.python
7575
sys : meta.function-call.arguments.python, meta.function-call.python, source.python
7676
. : meta.function-call.arguments.python, meta.function-call.python, meta.member.access.python, punctuation.separator.period.python, source.python
77-
stderr : meta.function-call.arguments.python, meta.function-call.python, meta.member.access.python, source.python
77+
stderr : meta.attribute.python, meta.function-call.arguments.python, meta.function-call.python, meta.member.access.python, source.python
7878
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python
7979
print : meta.function-call.python, source.python, support.function.builtin.python
8080
: meta.function-call.python, source.python

test/classes/class11.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ def : meta.function.python, source.python, storage.type.function.pytho
3434
: source.python
3535
self : source.python, variable.language.special.self.python
3636
. : meta.member.access.python, punctuation.separator.period.python, source.python
37-
a : meta.member.access.python, source.python
37+
a : meta.attribute.python, meta.member.access.python, source.python
3838
: source.python
3939
= : keyword.operator.assignment.python, source.python
4040
: source.python
4141
a : source.python
4242
: source.python
4343
self : source.python, variable.language.special.self.python
4444
. : meta.member.access.python, punctuation.separator.period.python, source.python
45-
b : meta.member.access.python, source.python
45+
b : meta.attribute.python, meta.member.access.python, source.python
4646
: source.python
4747
= : keyword.operator.assignment.python, source.python
4848
: source.python
@@ -59,17 +59,17 @@ def : meta.function.python, source.python, storage.type.function.pytho
5959
: source.python
6060
a : source.python
6161
. : meta.member.access.python, punctuation.separator.period.python, source.python
62-
self : meta.member.access.python, source.python
62+
self : meta.attribute.python, meta.member.access.python, source.python
6363
: source.python
6464
= : keyword.operator.assignment.python, source.python
6565
: source.python
6666
1 : constant.numeric.dec.python, source.python
6767
: source.python
6868
a : source.python
6969
. : meta.member.access.python, punctuation.separator.period.python, source.python
70-
self : meta.member.access.python, source.python
70+
self : meta.attribute.python, meta.member.access.python, source.python
7171
. : meta.member.access.python, punctuation.separator.period.python, source.python
72-
bar : meta.member.access.python, source.python
72+
bar : meta.attribute.python, meta.member.access.python, source.python
7373
: source.python
7474
= : keyword.operator.assignment.python, source.python
7575
: source.python

test/classes/class12.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ def : meta.function.python, source.python, storage.type.function.pytho
3939
: source.python
4040
cls : source.python, variable.language.special.cls.python
4141
. : meta.member.access.python, punctuation.separator.period.python, source.python
42-
a : meta.member.access.python, source.python
42+
a : meta.attribute.python, meta.member.access.python, source.python
4343
: source.python
4444
= : keyword.operator.assignment.python, source.python
4545
: source.python
4646
a : source.python
4747
: source.python
4848
cls : source.python, variable.language.special.cls.python
4949
. : meta.member.access.python, punctuation.separator.period.python, source.python
50-
b : meta.member.access.python, source.python
50+
b : meta.attribute.python, meta.member.access.python, source.python
5151
: source.python
5252
= : keyword.operator.assignment.python, source.python
5353
: source.python
@@ -70,15 +70,15 @@ def : meta.function.python, source.python, storage.type.function.pytho
7070
: source.python
7171
a : source.python
7272
. : meta.member.access.python, punctuation.separator.period.python, source.python
73-
cls : meta.member.access.python, source.python
73+
cls : meta.attribute.python, meta.member.access.python, source.python
7474
: source.python
7575
= : keyword.operator.assignment.python, source.python
7676
: source.python
7777
1 : constant.numeric.dec.python, source.python
7878
: source.python
7979
a : source.python
8080
. : meta.member.access.python, punctuation.separator.period.python, source.python
81-
cls : meta.member.access.python, source.python
81+
cls : meta.attribute.python, meta.member.access.python, source.python
8282
. : meta.member.access.python, punctuation.separator.period.python, source.python
8383
__name__ : meta.member.access.python, source.python, support.variable.magic.python
8484
: source.python

test/expressions/const1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
: source.python
1515
QQQ : constant.other.caps.python, source.python
1616
. : meta.member.access.python, punctuation.separator.period.python, source.python
17-
bar : meta.member.access.python, source.python
17+
bar : meta.attribute.python, meta.member.access.python, source.python
1818
: source.python
1919
baz : source.python
2020
. : meta.member.access.python, punctuation.separator.period.python, source.python

test/expressions/expr11.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
: source.python
1010
self : source.python, variable.language.special.self.python
1111
. : meta.member.access.python, punctuation.separator.period.python, source.python
12-
some_list : meta.item-access.python, meta.member.access.python, source.python
12+
some_list : meta.indexed-name.python, meta.item-access.python, meta.member.access.python, source.python
1313
[ : meta.item-access.python, meta.member.access.python, punctuation.definition.arguments.begin.python, source.python
1414
1 : constant.numeric.dec.python, meta.item-access.arguments.python, meta.item-access.python, meta.member.access.python, source.python
1515
: : meta.item-access.arguments.python, meta.item-access.python, meta.member.access.python, punctuation.separator.slice.python, source.python

test/expressions/expr15.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
foofrom : source.python
77
. : meta.member.access.python, punctuation.separator.period.python, source.python
8-
something : meta.member.access.python, source.python
8+
something : meta.attribute.python, meta.member.access.python, source.python

test/expressions/expr18.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
a : source.python
88
. : meta.member.access.python, punctuation.separator.period.python, source.python
9-
Exception : meta.member.access.python, source.python
9+
Exception : meta.attribute.python, meta.member.access.python, source.python
1010
Exception : source.python, support.type.exception.python
1111
. : meta.member.access.python, punctuation.separator.period.python, source.python
12-
a : meta.member.access.python, source.python
12+
a : meta.attribute.python, meta.member.access.python, source.python

test/fstrings/nested1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
: meta.fstring.python, meta.function-call.arguments.python, meta.function-call.python, source.python, string.interpolated.python, string.quoted.multi.python
2727
{ : constant.character.format.placeholder.other.python, meta.fstring.python, meta.function-call.arguments.python, meta.function-call.python, source.python
2828
: meta.fstring.python, meta.function-call.arguments.python, meta.function-call.python, source.python
29-
bar : meta.fstring.python, meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, source.python
29+
bar : meta.fstring.python, meta.function-call.arguments.python, meta.function-call.python, meta.indexed-name.python, meta.item-access.python, source.python
3030
[ : meta.fstring.python, meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, punctuation.definition.arguments.begin.python, source.python
3131
" : meta.fstring.python, meta.function-call.arguments.python, meta.function-call.python, meta.item-access.arguments.python, meta.item-access.python, punctuation.definition.string.begin.python, source.python, string.quoted.single.python
3232
q : meta.fstring.python, meta.function-call.arguments.python, meta.function-call.python, meta.item-access.arguments.python, meta.item-access.python, source.python, string.quoted.single.python

test/functions/decl2.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ def result_annot(lambda, lambda=) -> qqq[None]:
22
pass
33

44

5+
6+
57
def : meta.function.python, source.python, storage.type.function.python
68
: meta.function.python, source.python
79
result_annot : entity.name.function.python, meta.function.python, source.python
@@ -14,7 +16,7 @@ def : meta.function.python, source.python, storage.type.function.pytho
1416
: meta.function.python, source.python
1517
-> : meta.function.python, punctuation.separator.annotation.result.python, source.python
1618
: meta.function.python, source.python
17-
qqq : meta.function.python, meta.item-access.python, source.python
19+
qqq : meta.function.python, meta.indexed-name.python, meta.item-access.python, source.python
1820
[ : meta.function.python, meta.item-access.python, punctuation.definition.arguments.begin.python, source.python
1921
None : constant.language.python, meta.function.python, meta.item-access.arguments.python, meta.item-access.python, source.python
2022
] : meta.function.python, meta.item-access.python, punctuation.definition.arguments.end.python, source.python

test/functions/decorators6.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
def foo(): pass
77
88
9+
10+
911
@ : entity.name.function.decorator.python, meta.function.decorator.python, punctuation.definition.decorator.python, source.python
1012
a : entity.name.function.decorator.python, meta.function.decorator.python, source.python
1113
. : entity.name.function.decorator.python, meta.function.decorator.python, punctuation.separator.period.python, source.python
@@ -29,7 +31,7 @@ def foo(): pass
2931
) : meta.function.decorator.python, punctuation.definition.arguments.end.python, source.python
3032
. \ : invalid.illegal.decorator.python, meta.function.decorator.python, source.python
3133
: source.python
32-
baz : meta.item-access.python, source.python
34+
baz : meta.indexed-name.python, meta.item-access.python, source.python
3335
[ : meta.item-access.python, punctuation.definition.arguments.begin.python, source.python
3436
1 : constant.numeric.dec.python, meta.item-access.arguments.python, meta.item-access.python, source.python
3537
: : meta.item-access.arguments.python, meta.item-access.python, punctuation.separator.slice.python, source.python

0 commit comments

Comments
 (0)