Skip to content

Commit 939af6a

Browse files
committed
Ignore matching file and line argument labels
We don't provide default argument completions for `#file` and `#line`, for now let's skip matching `file` and `line` as argument labels.
1 parent 3f5f866 commit 939af6a

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

SourceKitStressTester/Sources/StressTester/SourceKitDocument.swift

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,22 @@ public struct CompletionMatcher {
718718
private func matchesCall(paramLabels: [String]) -> Bool {
719719
var remainingArgLabels = expected.name.argLabels[...]
720720

721+
func skippingIgnorableArgLabels(skipEmpty: Bool = false) -> ArraySlice<String> {
722+
var remainingArgLabels = remainingArgLabels
723+
if skipEmpty || remainingArgLabels.count < expected.name.argLabels.count {
724+
// If previous param was matched, allow consuming unlabeled args to
725+
// handle variadic cases.
726+
remainingArgLabels = remainingArgLabels.drop { $0.isEmpty }
727+
}
728+
// Ignore `file` and `line` since we don't include `#file` and `#line`
729+
// default args for completion.
730+
// FIXME: We ought to have this be configurable and enable it for the stress
731+
// tester.
732+
return remainingArgLabels.drop { $0 == "file" || $0 == "line" }
733+
}
734+
721735
guard !paramLabels.isEmpty else {
722-
return remainingArgLabels.allSatisfy { $0.isEmpty }
736+
return skippingIgnorableArgLabels(skipEmpty: true).isEmpty
723737
}
724738
for nextParamLabel in paramLabels {
725739
if nextParamLabel.isEmpty {
@@ -732,12 +746,9 @@ public struct CompletionMatcher {
732746
continue
733747
}
734748
} else {
735-
// Has param label
736-
if remainingArgLabels.count < expected.name.argLabels.count {
737-
// A previous param was matched, so assume it was variadic and consume
738-
// any leading unlabelled args so the next arg is labelled
739-
remainingArgLabels = remainingArgLabels.drop{ $0.isEmpty }
740-
}
749+
// Has param label, skip any ignorable labels before matching.
750+
remainingArgLabels = skippingIgnorableArgLabels()
751+
741752
guard let nextArgLabel = remainingArgLabels.first else {
742753
// Assume any unprocessed parameters are defaulted
743754
return true
@@ -750,9 +761,6 @@ public struct CompletionMatcher {
750761
// Else assume this param was defaulted and skip it.
751762
}
752763
}
753-
// If at least one arglabel was matched, allow for it being variadic
754-
let hadMatch = remainingArgLabels.count < expected.name.argLabels.count
755-
return remainingArgLabels.isEmpty || hadMatch &&
756-
remainingArgLabels.allSatisfy { $0.isEmpty }
764+
return skippingIgnorableArgLabels().isEmpty
757765
}
758766
}

SourceKitStressTester/Tests/StressTesterToolTests/ActionGeneratorTests.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,17 @@ class ActionGeneratorTests: XCTestCase {
153153
(match: .pattern, of: "first(_:z:)", against: "first(x:y:)", ignoreArgs: false, result: false),
154154
(match: .pattern, of: "first(_:)", against: "first", ignoreArgs: false, result: false),
155155
(match: .pattern, of: "first(_:)", against: "first()", ignoreArgs: false, result: true),
156-
(match: .pattern, of: "first(_:_:)", against: "first()", ignoreArgs: false, result: true)
156+
(match: .pattern, of: "first(_:_:)", against: "first()", ignoreArgs: false, result: true),
157+
158+
// We don't do matching for `file` and `line`.
159+
(match: .call, of: "foo(x:file:line:)", against: "foo(x:)", ignoreArgs: false, result: true),
160+
(match: .call, of: "foo(x:file:line:)", against: "foo(x:file:line:)", ignoreArgs: false, result: true),
161+
(match: .call, of: "foo(x:file:line:y:)", against: "foo(x:y:)", ignoreArgs: false, result: true),
162+
(match: .call, of: "foo(file:line:y:)", against: "foo(file:line:x:y:z:)", ignoreArgs: false, result: true),
163+
(match: .call, of: "foo(x:file:line:y:)", against: "foo(x:y:z:)", ignoreArgs: false, result: true),
164+
(match: .call, of: "foo(file:line:y:)", against: "foo(x:y:)", ignoreArgs: false, result: true),
165+
(match: .call, of: "foo(file:line:)", against: "foo(_:)", ignoreArgs: false, result: true),
166+
(match: .call, of: "foo(file:line:)", against: "foo()", ignoreArgs: false, result: true),
157167
]
158168

159169
for test in cases {

0 commit comments

Comments
 (0)