12
12
13
13
import SwiftSyntax
14
14
15
- extension SyntaxProtocol {
15
+ @ _spi ( Experimental ) extension SyntaxProtocol {
16
16
/// Parent scope of this syntax node, or scope introduced by this syntax node.
17
- var scope : ScopeSyntax ? {
17
+ @ _spi ( Experimental ) public var scope : ScopeSyntax ? {
18
18
if let scopeSyntax = Syntax ( self ) . asProtocol ( SyntaxProtocol . self) as? ScopeSyntax {
19
19
scopeSyntax
20
20
} else {
@@ -26,7 +26,7 @@ extension SyntaxProtocol {
26
26
@_spi ( Experimental) extension SourceFileSyntax : SequentialScopeSyntax {
27
27
/// All names introduced in the file scope
28
28
/// according to the default strategy: `memberBlockUpToLastDecl`.
29
- public var introducedNames : [ LookupName ] {
29
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
30
30
introducedNames ( using: . memberBlockUpToLastDecl)
31
31
}
32
32
@@ -47,10 +47,10 @@ extension SyntaxProtocol {
47
47
/// ```
48
48
/// During lookup, according to different configurations,
49
49
/// names available at the marked place are:
50
- /// - for `fileScopeNameIntroductionStrategy ` - a, b, c, d
50
+ /// - for `memberBlockUpToLastDecl ` - a, b, c, d
51
51
/// - for `memberBlock` - a, b, c, d, e, f
52
52
/// - for `codeBlock` - a
53
- public func introducedNames( using fileScopeHandling: FileScopeHandlingConfig ) -> [ LookupName ] {
53
+ @ _spi ( Experimental ) public func introducedNames( using fileScopeHandling: FileScopeHandlingConfig ) -> [ LookupName ] {
54
54
switch fileScopeHandling {
55
55
case . memberBlockUpToLastDecl:
56
56
var encounteredNonDeclaration = false
@@ -61,7 +61,7 @@ extension SyntaxProtocol {
61
61
if encounteredNonDeclaration {
62
62
return LookupName . getNames ( from: item, accessibleAfter: codeBlockItem. endPosition)
63
63
} else {
64
- if item. is ( DeclSyntax . self) || item . is ( VariableDeclSyntax . self ) {
64
+ if item. is ( DeclSyntax . self) {
65
65
return LookupName . getNames ( from: item)
66
66
} else {
67
67
encounteredNonDeclaration = true
@@ -97,10 +97,10 @@ extension SyntaxProtocol {
97
97
/// ```
98
98
/// According to different configurations,
99
99
/// names available at the marked place are:
100
- /// - for `fileScopeNameIntroductionStrategy ` - a, b, c, d
100
+ /// - for `memberBlockUpToLastDecl ` - a, b, c, d
101
101
/// - for `memberBlock` - a, b, c, d, e, f
102
102
/// - for `codeBlock` - a
103
- public func lookup(
103
+ @ _spi ( Experimental ) public func lookup(
104
104
for name: String ? ,
105
105
at syntax: SyntaxProtocol ,
106
106
with config: LookupConfig ,
@@ -162,13 +162,13 @@ extension SyntaxProtocol {
162
162
@_spi ( Experimental) extension CodeBlockSyntax : SequentialScopeSyntax {
163
163
/// Names introduced in the code block scope
164
164
/// accessible after their declaration.
165
- public var introducedNames : [ LookupName ] {
165
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
166
166
statements. flatMap { codeBlockItem in
167
167
LookupName . getNames ( from: codeBlockItem. item, accessibleAfter: codeBlockItem. endPosition)
168
168
}
169
169
}
170
170
171
- public func lookup(
171
+ @ _spi ( Experimental ) public func lookup(
172
172
for name: String ? ,
173
173
at syntax: SyntaxProtocol ,
174
174
with config: LookupConfig ,
@@ -187,7 +187,7 @@ extension SyntaxProtocol {
187
187
188
188
@_spi ( Experimental) extension ForStmtSyntax : ScopeSyntax {
189
189
/// Names introduced in the `for` body.
190
- public var introducedNames : [ LookupName ] {
190
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
191
191
LookupName . getNames ( from: pattern)
192
192
}
193
193
}
@@ -204,26 +204,20 @@ extension SyntaxProtocol {
204
204
/// ```
205
205
/// During lookup, names available at the marked place are:
206
206
/// `self`, a, b.
207
- public var introducedNames : [ LookupName ] {
207
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
208
208
let captureNames =
209
- signature? . capture? . children ( viewMode: . sourceAccurate) . flatMap { child in
210
- if let captureList = child. as ( ClosureCaptureListSyntax . self) {
211
- captureList. children ( viewMode: . sourceAccurate) . flatMap { capture in
212
- LookupName . getNames ( from: capture)
213
- }
214
- } else {
215
- LookupName . getNames ( from: child)
216
- }
209
+ signature? . capture? . items. flatMap { element in
210
+ LookupName . getNames ( from: element)
217
211
} ?? [ ]
218
212
219
213
let parameterNames =
220
214
signature? . parameterClause? . children ( viewMode: . sourceAccurate) . flatMap { parameter in
221
215
if let parameterList = parameter. as ( ClosureParameterListSyntax . self) {
222
- parameterList. children ( viewMode: . sourceAccurate) . flatMap { parameter in
216
+ return parameterList. children ( viewMode: . sourceAccurate) . flatMap { parameter in
223
217
LookupName . getNames ( from: parameter)
224
218
}
225
219
} else {
226
- LookupName . getNames ( from: parameter)
220
+ return LookupName . getNames ( from: parameter)
227
221
}
228
222
} ?? [ ]
229
223
@@ -233,7 +227,7 @@ extension SyntaxProtocol {
233
227
234
228
@_spi ( Experimental) extension WhileStmtSyntax : ScopeSyntax {
235
229
/// Names introduced by the `while` loop by its conditions.
236
- public var introducedNames : [ LookupName ] {
230
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
237
231
conditions. flatMap { element in
238
232
LookupName . getNames ( from: element. condition)
239
233
}
@@ -242,7 +236,7 @@ extension SyntaxProtocol {
242
236
243
237
@_spi ( Experimental) extension IfExprSyntax : ScopeSyntax {
244
238
/// Parent scope, omitting ancestor `if` statements if part of their `else if` clause.
245
- public var parentScope : ScopeSyntax ? {
239
+ @ _spi ( Experimental ) public var parentScope : ScopeSyntax ? {
246
240
getParent ( for: self . parent, previousIfElse: self . elseKeyword == nil )
247
241
}
248
242
@@ -278,7 +272,7 @@ extension SyntaxProtocol {
278
272
}
279
273
280
274
/// Names introduced by the `if` optional binding conditions.
281
- public var introducedNames : [ LookupName ] {
275
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
282
276
conditions. flatMap { element in
283
277
LookupName . getNames ( from: element. condition, accessibleAfter: element. endPosition)
284
278
}
@@ -296,7 +290,7 @@ extension SyntaxProtocol {
296
290
/// // <-- a is not visible here
297
291
/// }
298
292
/// ```
299
- public func lookup(
293
+ @ _spi ( Experimental ) public func lookup(
300
294
for name: String ? ,
301
295
at syntax: SyntaxProtocol ,
302
296
with config: LookupConfig ,
@@ -312,15 +306,15 @@ extension SyntaxProtocol {
312
306
313
307
@_spi ( Experimental) extension MemberBlockSyntax : ScopeSyntax {
314
308
/// All names introduced by members of this member scope.
315
- public var introducedNames : [ LookupName ] {
309
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
316
310
members. flatMap { member in
317
311
LookupName . getNames ( from: member. decl)
318
312
}
319
313
}
320
314
}
321
315
322
316
@_spi ( Experimental) extension GuardStmtSyntax : IntroducingToSequentialParentScopeSyntax {
323
- public func introducesToSequentialParent(
317
+ @ _spi ( Experimental ) public func introducesToSequentialParent(
324
318
for name: String ? ,
325
319
at syntax: SwiftSyntax . SyntaxProtocol ,
326
320
with config: LookupConfig ,
@@ -335,7 +329,7 @@ extension SyntaxProtocol {
335
329
return names. isEmpty ? [ ] : [ . fromScope( self , withNames: names) ]
336
330
}
337
331
338
- public var introducedNames : [ LookupName ] {
332
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
339
333
[ ]
340
334
}
341
335
@@ -350,7 +344,7 @@ extension SyntaxProtocol {
350
344
/// }
351
345
/// // a is visible here
352
346
/// ```
353
- public func lookup(
347
+ @ _spi ( Experimental ) public func lookup(
354
348
for name: String ? ,
355
349
at syntax: SyntaxProtocol ,
356
350
with config: LookupConfig ,
@@ -373,7 +367,7 @@ extension SyntaxProtocol {
373
367
@_spi ( Experimental) extension ExtensionDeclSyntax : TypeScopeSyntax { }
374
368
375
369
@_spi ( Experimental) extension AccessorDeclSyntax : ScopeSyntax {
376
- public var introducedNames : [ LookupName ] {
370
+ @ _spi ( Experimental ) public var introducedNames : [ LookupName ] {
377
371
if let parameters {
378
372
LookupName . getNames ( from: parameters)
379
373
} else {
0 commit comments