Skip to content

Commit d4e1543

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 d4e1543

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

SourceKitStressTester/Sources/StressTester/SourceKitDocument.swift

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

721+
func skipIgnorableArgLabels(skipEmpty: Bool = false) {
722+
if skipEmpty || remainingArgLabels.count < expected.name.argLabels.count {
723+
// If previous param was matched, allow consuming unlabeled args to
724+
// handle variadic cases.
725+
remainingArgLabels = remainingArgLabels.drop { $0.isEmpty }
726+
}
727+
// Ignore `file` and `line` since we don't include `#file` and `#line`
728+
// default args for completion.
729+
// FIXME: We ought to have this be configurable and enable it for the stress
730+
// tester.
731+
remainingArgLabels = remainingArgLabels.drop {
732+
$0 == "file" || $0 == "line"
733+
}
734+
}
735+
721736
guard !paramLabels.isEmpty else {
722-
return remainingArgLabels.allSatisfy { $0.isEmpty }
737+
skipIgnorableArgLabels(skipEmpty: true)
738+
return remainingArgLabels.isEmpty
723739
}
724740
for nextParamLabel in paramLabels {
725741
if nextParamLabel.isEmpty {
@@ -732,12 +748,9 @@ public struct CompletionMatcher {
732748
continue
733749
}
734750
} 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-
}
751+
// Has param label, skip any ignorable labels before matching.
752+
skipIgnorableArgLabels()
753+
741754
guard let nextArgLabel = remainingArgLabels.first else {
742755
// Assume any unprocessed parameters are defaulted
743756
return true
@@ -750,9 +763,7 @@ public struct CompletionMatcher {
750763
// Else assume this param was defaulted and skip it.
751764
}
752765
}
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 }
766+
skipIgnorableArgLabels()
767+
return remainingArgLabels.isEmpty
757768
}
758769
}

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)