Skip to content

Commit dc908a6

Browse files
committed
Add editor place holder type
1 parent 0bd5eef commit dc908a6

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

Sources/SwiftParser/Types.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,9 @@ extension Parser {
938938

939939
extension Parser {
940940
mutating func parseResultType() -> RawTypeSyntax {
941-
if self.at(prefix: "<") {
941+
if self.currentToken.isEditorPlaceholder {
942+
return self.parseTypeIdentifier()
943+
} else if self.at(prefix: "<") {
942944
let generics = self.parseGenericParameters()
943945
let baseType = self.parseType()
944946
return RawTypeSyntax(

Tests/SwiftParserTest/LexerTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,16 @@ public class LexerTests: ParserTestCase {
846846
LexemeSpec(.identifier, text: "<##>", trailing: "", diagnostic: "editor placeholder in source file")
847847
]
848848
)
849+
850+
assertLexemes(
851+
"let 1️⃣<#name#> = 2️⃣<#value#>",
852+
lexemes: [
853+
LexemeSpec(.keyword, text: "let", trailing: " "),
854+
LexemeSpec(.identifier, text: "<#name#>", trailing: " ", errorLocationMarker: "1️⃣", diagnostic: "editor placeholder in source file"),
855+
LexemeSpec(.equal, text: "=", trailing: " "),
856+
LexemeSpec(.identifier, text: "<#value#>", errorLocationMarker: "2️⃣", diagnostic: "editor placeholder in source file"),
857+
]
858+
)
849859
}
850860

851861
func testCommentAttribution() {

Tests/SwiftParserTest/TypeTests.swift

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,92 @@ final class TypeTests: ParserTestCase {
216216
substructureAfterMarker: "1️⃣"
217217
)
218218
}
219+
220+
func testTypeWithPlaceholder() {
221+
assertParse(
222+
"let a: 1️⃣<#T#> = x",
223+
substructure: VariableDeclSyntax(
224+
bindingSpecifier: .keyword(.let),
225+
bindings: [
226+
PatternBindingSyntax(
227+
pattern: IdentifierPatternSyntax(identifier: .identifier("a")),
228+
typeAnnotation: TypeAnnotationSyntax(
229+
type: IdentifierTypeSyntax(
230+
name: .identifier("<#T#>")
231+
)
232+
),
233+
initializer: InitializerClauseSyntax(
234+
value: DeclReferenceExprSyntax(
235+
baseName: .identifier("x")
236+
)
237+
)
238+
)
239+
]
240+
),
241+
diagnostics: [
242+
DiagnosticSpec(message: "editor placeholder in source file")
243+
]
244+
)
245+
246+
assertParse(
247+
"let a: 1️⃣<#T#><Foo> = x",
248+
substructure: VariableDeclSyntax(
249+
bindingSpecifier: .keyword(.let),
250+
bindings: [
251+
PatternBindingSyntax(
252+
pattern: IdentifierPatternSyntax(identifier: .identifier("a")),
253+
typeAnnotation: TypeAnnotationSyntax(
254+
type: IdentifierTypeSyntax(
255+
name: .identifier("<#T#>"),
256+
genericArgumentClause: GenericArgumentClauseSyntax(
257+
arguments: GenericArgumentListSyntax([
258+
GenericArgumentSyntax(
259+
argument: IdentifierTypeSyntax(
260+
name: .identifier("Foo")
261+
)
262+
)
263+
])
264+
)
265+
)
266+
),
267+
initializer: InitializerClauseSyntax(
268+
value: DeclReferenceExprSyntax(
269+
baseName: .identifier("x")
270+
)
271+
)
272+
)
273+
]
274+
),
275+
diagnostics: [
276+
DiagnosticSpec(message: "editor placeholder in source file")
277+
]
278+
)
279+
280+
assertParse(
281+
"let a: [1️⃣<#T#>] = x",
282+
substructure: VariableDeclSyntax(
283+
bindingSpecifier: .keyword(.let),
284+
bindings: [
285+
PatternBindingSyntax(
286+
pattern: IdentifierPatternSyntax(identifier: .identifier("a")),
287+
typeAnnotation: TypeAnnotationSyntax(
288+
type: ArrayTypeSyntax(
289+
element: IdentifierTypeSyntax(
290+
name: .identifier("<#T#>")
291+
)
292+
)
293+
),
294+
initializer: InitializerClauseSyntax(
295+
value: DeclReferenceExprSyntax(
296+
baseName: .identifier("x")
297+
)
298+
)
299+
)
300+
]
301+
),
302+
diagnostics: [
303+
DiagnosticSpec(message: "editor placeholder in source file")
304+
]
305+
)
306+
}
219307
}

0 commit comments

Comments
 (0)