in Sources/SwiftDocC/Infrastructure/Diagnostics/ParseDirectiveArguments.swift [17:90]
func arguments(problems: inout [Problem]) -> [String: Markdown.DirectiveArgument] {
var parseErrors = [DirectiveArgumentText.ParseError]()
let parsedArguments = self.argumentText.parseNameValueArguments(parseErrors: &parseErrors)
problems.append(contentsOf: parseErrors.compactMap { error -> Problem? in
switch error {
case let .duplicateArgument(name, firstLocation, duplicateLocation):
// If we already emitted a diagnostic for the original argument we don't do that a second time.
// Additionally we search the existing problems in reverse order to find more recent ones faster.
guard !problems.reversed().contains(where: { problem -> Bool in
return problem.diagnostic.identifier == "org.swift.docc.Directive.DuplicateArgument" && problem.diagnostic.range?.lowerBound == firstLocation
}) else {
return nil
}
return Problem(
diagnostic: Diagnostic(
source: duplicateLocation.source,
severity: .warning,
range: duplicateLocation..<duplicateLocation,
identifier: "org.swift.docc.Directive.DuplicateArgument",
summary: "Duplicate argument for \(name.singleQuoted)"
),
possibleSolutions: []
)
case let .missingExpectedCharacter(character, location):
// We search the existing problems in reverse order to find more recent ones faster.
guard !problems.reversed().contains(where: { problem -> Bool in
return problem.diagnostic.identifier == "org.swift.docc.Directive.MissingExpectedCharacter" && problem.diagnostic.range?.lowerBound == location
}) else {
return nil
}
return Problem(
diagnostic: Diagnostic(
source: location.source,
severity: .warning,
range: location..<location,
identifier: "org.swift.docc.Directive.MissingExpectedCharacter",
summary: "Missing expected character '\(character)'",
explanation: "Arguments that use special characters or spaces should be wrapped in '\"' quotes"
),
possibleSolutions: [
Solution(summary: "Insert a '\(character) character", replacements: [
Replacement(range: location..<location, replacement: String(character))
])
])
case let .unexpectedCharacter(character, location):
// We search the existing problems in reverse order to find more recent ones faster.
guard !problems.reversed().contains(where: { problem -> Bool in
return problem.diagnostic.identifier == "org.swift.docc.Directive.UnexpectedCharacter" && problem.diagnostic.range?.lowerBound == location
}) else {
return nil
}
return Problem(
diagnostic: Diagnostic(
source: location.source,
severity: .warning,
range: location..<location,
identifier: "org.swift.docc.Directive.UnexpectedCharacter",
summary: "Unexpected character '\(character)'",
explanation: "Arguments that use special characters or spaces should be wrapped in '\"' quotes"
), possibleSolutions: [
Solution(summary: "Remove the '\(character) character", replacements: [
Replacement(range: location..<SourceLocation(line: location.line, column: location.column+1, source: location.source), replacement: "")
])
])
}
})
var arguments = [String: Markdown.DirectiveArgument]()
for argument in parsedArguments {
arguments[argument.name] = argument
}
return arguments
}