Skip to content

Commit 9ec658a

Browse files
author
Nathan Hawes
authored
Merge pull request swiftlang#10289 from nathawes/rdar32148117-multiline-syntax-coloring-issues
[syntax-coloring] Rework the syntax map to use offset + length and simplify the delta logic
2 parents f86212c + 3791e12 commit 9ec658a

21 files changed

+1352
-229
lines changed

lib/IDE/SyntaxModel.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ SyntaxModelContext::SyntaxModelContext(SourceFile &SrcFile)
206206
break;
207207
}
208208

209+
case tok::unknown: {
210+
if (Tok.getRawText().startswith("\"")) {
211+
// This is an invalid string literal
212+
Kind = SyntaxNodeKind::String;
213+
break;
214+
}
215+
continue;
216+
}
217+
209218
default:
210219
continue;
211220
}

test/IDE/coloring.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ func f(x: Int) -> Int {
227227
// CHECK: <str>"This is string </str>\<anchor>(</anchor>genFn({(a:<type>Int</type> -> <type>Int</type>) <kw>in</kw> a})<anchor>)</anchor><str> interpolation"</str>
228228
"This is string \(genFn({(a:Int -> Int) in a})) interpolation"
229229

230+
// CHECK: <str>"This is unterminated</str>
231+
"This is unterminated
232+
233+
// CHECK: <str>"This is unterminated with ignored \(interpolation) in it</str>
234+
"This is unterminated with ignored \(interpolation) in it
235+
236+
// CHECK: <str>"This is terminated with invalid \(interpolation" + "in it"</str>
237+
"This is terminated with invalid \(interpolation" + "in it"
238+
230239
// CHECK: <str>"""
231240
// CHECK-NEXT: This is a multiline string.
232241
// CHECK-NEXT: """</str>
@@ -236,9 +245,19 @@ func f(x: Int) -> Int {
236245

237246
// CHECK: <str>"""
238247
// CHECK-NEXT: This is a multiline</str>\<anchor>(</anchor> <str>"interpolated"</str> <anchor>)</anchor><str>string
248+
// CHECK-NEXT: </str>\<anchor>(</anchor>
249+
// CHECK-NEXT: <str>"""
250+
// CHECK-NEXT: inner
251+
// CHECK-NEXT: """</str>
252+
// CHECK-NEXT: <anchor>)</anchor><str>
239253
// CHECK-NEXT: """</str>
240254
"""
241255
This is a multiline\( "interpolated" )string
256+
\(
257+
"""
258+
inner
259+
"""
260+
)
242261
"""
243262
}
244263

test/IDE/unterminated_multiline.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-ide-test -syntax-coloring -source-filename %s | %FileCheck %s
2+
// RUN: %target-swift-ide-test -syntax-coloring -typecheck -source-filename %s | %FileCheck %s
3+
4+
// CHECK: <kw>let</kw> x = <str>"""
5+
// CHECK-NEXT: This is an unterminated
6+
// CHECK-NEXT: \( "multiline" )
7+
// CHECK-NEXT: string followed by code
8+
// CHECK-NEXT: ""
9+
// CHECK-NEXT: func foo() {}
10+
// CHECK-NEXT: </str>
11+
let x = """
12+
This is an unterminated
13+
\( "multiline" )
14+
string followed by code
15+
""
16+
func foo() {}

test/SourceKit/DocumentStructure/mark_edit.swift.response

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
]
1414
}
1515
{
16-
key.offset: 0,
17-
key.length: 3,
1816
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
1917
key.substructure: [
2018
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
let x = /*
3+
4+
*/ 2
5+
func foo() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let y = /*
2+
3+
*// /*
4+
5+
*/ 2
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let a = "value"
2+
let x = """
3+
4+
\(
5+
a
6+
)
7+
8+
9+
10+
func foo () -> String {
11+
return "foo"
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// This function does stuff
2+
///
3+
/// - parameter first: The first parameter
4+
///
5+
/// - returns: The return value
6+
func foo(first: Int) -> String {
7+
return ""
8+
}
9+
10+
let x = "Changing this string should only affect this line"
11+
12+
/// This function does other stuff
13+
///
14+
/// - parameter first: The first parameter
15+
///
16+
/// - returns: The return value
17+
func bar(first: Int) -> String {
18+
return ""
19+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let l = 2
2+
l
3+
\( 56
4+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
/// A comment
3+
/// - Note: important things
4+
let x = 42
5+
6+
struct Point {
7+
let x: Int = x
8+
let y: Int = x
9+
10+
func mag2() {
11+
return x*x + y*y;
12+
}
13+
}
14+

0 commit comments

Comments
 (0)