Skip to content

Commit 293308e

Browse files
committed
Exclude expected completions for underscored attributes
Don't check completions for e.g `@_spi` or its arguments.
1 parent d4e1543 commit 293308e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

SourceKitStressTester/Sources/StressTester/ActionGenerators.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,32 @@ private struct ActionToken {
503503
return nil
504504
}
505505
}
506+
507+
// Avoid matching for underscored attributes since we hide completions for
508+
// those.
509+
do {
510+
var parent = parent
511+
if let label = parent.as(LabeledExprSyntax.self),
512+
let labelParent = label.parent, label.label == token {
513+
parent = labelParent
514+
} else if let nextParent = parent.parent {
515+
parent = nextParent
516+
if let label = parent.as(LabeledExprSyntax.self),
517+
let labelParent = label.parent {
518+
parent = labelParent
519+
}
520+
}
521+
if let exprList = parent.as(LabeledExprListSyntax.self),
522+
let listParent = exprList.parent {
523+
parent = listParent
524+
}
525+
if let attr = parent.as(AttributeSyntax.self),
526+
let ident = attr.attributeName.as(IdentifierTypeSyntax.self),
527+
ident.name.text.hasPrefix("_") {
528+
return nil
529+
}
530+
}
531+
506532
if let parent = parent.as(DeclReferenceExprSyntax.self), parent.baseName == token {
507533
if let refArgs = parent.argumentNames {
508534
let name = SwiftName(base: token.text, labels: refArgs.arguments.map{ $0.name.text })

SourceKitStressTester/Tests/StressTesterToolTests/ActionGeneratorTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ class ActionGeneratorTests: XCTestCase {
9797

9898
// FIXME: completion doesn't suggest anonymous closure params (e.g. $0)
9999
(#line, "$0.first", [/*"$0",*/ "first"]),
100-
(#line, "[1,2,4].filter{ $0 == 4 }", ["call:filter"/*, "$0"*/])
100+
(#line, "[1,2,4].filter{ $0 == 4 }", ["call:filter"/*, "$0"*/]),
101+
102+
// We don't include completions for underscored attributes.
103+
(#line, "@_underscored(a: Foo)", []),
104+
(#line, "@_spi(Foo)", []),
101105
]
102106

103107
for test in cases {

0 commit comments

Comments
 (0)