Skip to content

Commit 7107396

Browse files
committed
fix: limit locals queries to function parameters only
1 parent 9ad2f24 commit 7107396

File tree

6 files changed

+61031
-55005
lines changed

6 files changed

+61031
-55005
lines changed

grammar.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,6 @@ module.exports = grammar({
408408
optional('async'),
409409
'def',
410410
field('name', $.identifier),
411-
$.function_definition_scope,
412-
),
413-
414-
function_definition_scope: $ => seq(
415411
field('type_parameters', optional($.type_parameter)),
416412
'(',
417413
field('parameters', optional($.parameters)),
@@ -499,9 +495,6 @@ module.exports = grammar({
499495
class_definition: $ => seq(
500496
'class',
501497
field('name', $.identifier),
502-
$.class_definition_scope,
503-
),
504-
class_definition_scope: $ => seq(
505498
field('type_parameters', optional($.type_parameter)),
506499
field('superclasses', optional($.argument_list)),
507500
':',

queries/highlights.scm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,26 @@
9292

9393
(assignment left: [(identifier) @variable
9494
(_ attribute: _ @member_variable)])
95-
(class_definition (_ (_ (assignment left: (identifier) @member_variable))))
95+
(class_definition (_ (assignment left: (identifier) @member_variable)))
9696

9797
(assignment left: (identifier) @type
9898
(#match? @type "^[A-Z]"))
9999
([(assignment left: (_ attribute: _ @member_type))
100-
(class_definition (_ (_ (assignment left: (identifier) @member_type))))]
100+
(class_definition (_ (assignment left: (identifier) @member_type)))]
101101
(#match? @member_type "^[A-Z]"))
102102

103103
(assignment
104104
left: (identifier) @constant
105105
(#match? @constant "^[A-Z_0-9]*$"))
106106
([(assignment left: (_ attribute: _ @member_constant))
107-
(class_definition (_ (_ (assignment left: (identifier) @member_constant))))]
107+
(class_definition (_ (assignment left: (identifier) @member_constant)))]
108108
(#match? @member_constant "^[A-Z_0-9]*$"))
109109

110110
(function_definition name: _ @function)
111111
(class_definition
112-
(_ (_
113-
[(function_definition name: _ @member_function)
114-
(decorated_definition (function_definition name: _ @member_function))])))
112+
(_
113+
[(function_definition name: _ @member_function)
114+
(decorated_definition (function_definition name: _ @member_function))]))
115115
(assignment
116116
left: [(identifier) @function
117117
(_ attribute: _ @member_function)]
@@ -122,9 +122,9 @@
122122

123123
(class_definition name: _ @type)
124124
(class_definition
125-
(_ (_
126-
[(class_definition name: _ @member_type)
127-
(decorated_definition (class_definition name: _ @member_type))])))
125+
(_
126+
[(class_definition name: _ @member_type)
127+
(decorated_definition (class_definition name: _ @member_type))]))
128128

129129
(parameter name: _ @function_parameter)
130130
(keyword_argument name: _ @function_parameter)
@@ -140,21 +140,21 @@
140140
"__loader__" "__name__" "__package__" "__path__" "__spec__"))
141141

142142
([(member_identifier) @special_member_variable
143-
(class_definition (_ (_ (assignment left: (identifier) @special_member_variable))))]
143+
(class_definition (_ (assignment left: (identifier) @special_member_variable)))]
144144
(#any-of? @special_member_variable "__dict__" "__doc__" "__match_args__"
145145
"__metaclass__" "__objclass__" "__slots__" "__weakref__"))
146146

147147
([(member_identifier) @special_member_constant
148-
(class_definition (_ (_ (assignment left: (identifier) @special_member_constant))))]
148+
(class_definition (_ (assignment left: (identifier) @special_member_constant)))]
149149
(#any-of? @special_member_constant "__annotations__" "__bases__" "__cached__"
150150
"__class__" "__classcell__" "__closure__" "__code__" "__defaults__" "__file__"
151151
"__firstlineno__" "__func__" "__globals__" "__kwdefaults__" "__loader__"
152152
"__module__" "__mro__" "__name__" "__package__" "__path__" "__qualname__"
153153
"__self__" "__spec__" "__static_attributes__" "__type_params__"))
154154

155155
([(member_identifier) @_name @special_member_function
156-
(class_definition (_ (_ [(assignment left: (identifier) @_name @special_member_function)
157-
(function_definition name: _ @_name @special_member_function)])))
156+
(class_definition (_ [(assignment left: (identifier) @_name @special_member_function)
157+
(function_definition name: _ @_name @special_member_function)]))
158158
(module (function_definition name: _ @_name @special_function))]
159159
(#any-of? @_name "__abs__" "__add__" "__aenter__" "__aexit__" "__aiter__"
160160
"__and__" "__anext__" "__await__" "__bool__" "__buffer__" "__bytes__"

queries/locals.scm

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
;; Scopes
22

3-
[(module)
4-
(class_definition_scope)
5-
(function_definition_scope)
6-
(lambda)] @local.scope
3+
[(function_definition) (lambda)] @local.scope
74

85
;; Definitions
96

10-
; TODO: Type parameters, patterns in assignment and match statements
11-
12-
(import_statement (dotted_name . _ @local.definition))
13-
(import_from_statement name: (dotted_name . _ @local.definition))
14-
(aliased_import alias: _ @local.definition)
15-
(class_definition name: _ @local.definition)
16-
(type_alias_statement left: (type . (identifier) @local.definition))
17-
(function_definition name: _ @local.definition)
187
(parameter name: _ @local.definition)
19-
(as_pattern alias: _ @local.definition)
20-
(named_expression name: (identifier) @local.definition)
21-
(assignment left: (identifier) @local.definition)
228

239
;; References
2410

src/grammar.json

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

Lines changed: 10 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)