Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,31 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
node.closeQuote.id,
].compactMap { $0 }
)
} else if node.openQuote.presence == .missing,
node.unexpectedBetweenOpenDelimiterAndOpenQuote == nil,
node.closeQuote.presence == .missing,
node.unexpectedBetweenCloseQuoteAndCloseDelimiter == nil,
!node.segments.isMissingAllTokens
{
addDiagnostic(
node,
MissingBothStringQuotesOfStringSegments(stringSegments: node.segments),
fixIts: [
FixIt(
message: InsertTokenFixIt(missingNodes: [Syntax(node.openQuote), Syntax(node.closeQuote)]),
changes: [
.makePresent(node.openQuote),
.makePresent(node.closeQuote),
]
)
],
handledNodes: [
node.openQuote.id,
node.closeQuote.id,
]
)
}

for (diagnostic, handledNodes) in MultiLineStringLiteralIndentatinDiagnosticsGenerator.diagnose(node) {
addDiagnostic(diagnostic, handledNodes: handledNodes)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ public struct MissingAttributeArgument: ParserError {
}
}

public struct MissingBothStringQuotesOfStringSegments: ParserError {
public let stringSegments: StringLiteralSegmentsSyntax

public var message: String {
return #"expected \#(stringSegments.shortSingleLineContentDescription) to be surrounded by '"'"#
}
}

public struct MissingConditionInStatement: ParserError {
let node: SyntaxProtocol

Expand Down
26 changes: 8 additions & 18 deletions Tests/SwiftParserTest/AttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,14 @@ final class AttributeTests: XCTestCase {

assertParse(
"""
@_expose(Cxx, 1️⃣baz2️⃣) func foo() {}
@_expose(Cxx, 1️⃣baz) func foo() {}
""",
diagnostics: [
DiagnosticSpec(
locationMarker: "1️⃣",
message: #"expected '"' in string literal"#,
fixIts: [#"insert '"'"#]
),
DiagnosticSpec(
locationMarker: "2️⃣",
message: #"expected '"' to end string literal"#,
fixIts: [#"insert '"'"#]
),
message: #"expected code 'baz' to be surrounded by '"'"#,
fixIts: [#"insert '"' and '"'"#]
)
],
fixedSource: """
@_expose(Cxx, "baz") func foo() {}
Expand Down Expand Up @@ -543,20 +538,15 @@ final class AttributeTests: XCTestCase {

assertParse(
"""
@_unavailableFromAsync(message: 1️⃣abc2️⃣)
@_unavailableFromAsync(message: 1️⃣abc)
func foo() {}
""",
diagnostics: [
DiagnosticSpec(
locationMarker: "1️⃣",
message: #"expected '"' in string literal"#,
fixIts: [#"insert '"'"#]
),
DiagnosticSpec(
locationMarker: "2️⃣",
message: #"expected '"' to end string literal"#,
fixIts: [#"insert '"'"#]
),
message: #"expected code 'abc' to be surrounded by '"'"#,
fixIts: [#"insert '"' and '"'"#]
)
],
fixedSource: """
@_unavailableFromAsync(message: "abc")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,8 @@ final class OriginalDefinedInAttrTests: XCTestCase {
),
DiagnosticSpec(
locationMarker: "1️⃣",
message: #"expected '"' in string literal"#,
fixIts: [#"insert '"'"#]
),
DiagnosticSpec(
locationMarker: "2️⃣",
message: #"expected '"' to end string literal"#,
fixIts: [#"insert '"'"#]
message: #"expected code 'OSX' to be surrounded by '"'"#,
fixIts: [#"insert '"' and '"'"#]
),
DiagnosticSpec(
locationMarker: "2️⃣",
Expand Down