Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 4bdbb5e

Browse files
authored
Fix string concatenation spacing (#144)
1 parent 22944ac commit 4bdbb5e

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/Analysis/Engine/Test/LineFormatterTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,19 @@ public void CommentAfterOperator() {
390390
AssertSingleLineFormat("a+# comment\nb", "a + # comment");
391391
}
392392

393+
[DataRow("'a''b'", "'a' 'b'")]
394+
[DataRow("'a' 'b'", "'a' 'b'")]
395+
[DataRow("'''a''''''b'''", "'''a''' '''b'''")]
396+
[DataRow("'''a'''r'''b'''", "'''a''' r'''b'''")]
397+
[DataRow("\"a\"\"b\"", "\"a\" \"b\"")]
398+
[DataRow("\"a\" \"b\"", "\"a\" \"b\"")]
399+
[DataRow("\"\"\"a\"\"\"\"\"\"b\"\"\"", "\"\"\"a\"\"\" \"\"\"b\"\"\"")]
400+
[DataRow("\"\"\"a\"\"\"r\"\"\"b\"\"\"", "\"\"\"a\"\"\" r\"\"\"b\"\"\"")]
401+
[DataTestMethod, Priority(0)]
402+
public void StringConcat(string code, string expected) {
403+
AssertSingleLineFormat(code, expected);
404+
}
405+
393406

394407
[TestMethod, Priority(0)]
395408
public void GrammarFile() {

src/LanguageServer/Impl/Implementation/LineFormatter.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,15 @@ public TextEdit[] FormatLine(int line) {
287287
builder.EnsureEndsWithSpace();
288288
break;
289289

290-
case TokenKind.Name:
291290
case TokenKind.Constant:
291+
if (token.IsString && next != null && next.IsString) {
292+
builder.Append(token);
293+
builder.EnsureEndsWithSpace();
294+
break;
295+
}
296+
goto case TokenKind.Name;
297+
298+
case TokenKind.Name:
292299
case TokenKind.KeywordFalse:
293300
case TokenKind.KeywordTrue:
294301
case TokenKind.Ellipsis: // Ellipsis is a value
@@ -410,19 +417,9 @@ public bool MatchesClose(TokenExt other) {
410417

411418
public bool IsKeyword => (Kind >= TokenKind.FirstKeyword && Kind <= TokenKind.LastKeyword) || Kind == TokenKind.KeywordAsync || Kind == TokenKind.KeywordAwait;
412419

413-
public bool IsMultilineString {
414-
get {
415-
if (Span.Start.Line == Span.End.Line) {
416-
return false;
417-
}
420+
public bool IsString => Kind == TokenKind.Constant && Token != Tokens.NoneToken && (Token.Value is string || Token.Value is AsciiString);
418421

419-
if (Kind != TokenKind.Constant || Token == Tokens.NoneToken) {
420-
return false;
421-
}
422-
423-
return Token.Value is string || Token.Value is AsciiString;
424-
}
425-
}
422+
public bool IsMultilineString => Span.Start.Line != Span.End.Line && IsString;
426423

427424
public bool IsSimpleSliceToLeft {
428425
get {

0 commit comments

Comments
 (0)