From 8132596db8f514aff9e5eed7155586788d4671a0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 18 Feb 2022 10:34:07 -0800 Subject: [PATCH 1/2] Improve json error message in particular case --- .../Json/CSharpJsonParserTests_BasicTests.cs | 10 +++++----- .../EmbeddedLanguages/Json/JsonParser.cs | 18 +++++++++++++++++- .../Core/Portable/FeaturesResources.resx | 3 +++ .../Core/Portable/xlf/FeaturesResources.cs.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.de.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.es.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.fr.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.it.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.ja.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.ko.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.pl.xlf | 5 +++++ .../Portable/xlf/FeaturesResources.pt-BR.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.ru.xlf | 5 +++++ .../Core/Portable/xlf/FeaturesResources.tr.xlf | 5 +++++ .../Portable/xlf/FeaturesResources.zh-Hans.xlf | 5 +++++ .../Portable/xlf/FeaturesResources.zh-Hant.xlf | 5 +++++ 16 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src/EditorFeatures/CSharpTest2/EmbeddedLanguages/Json/CSharpJsonParserTests_BasicTests.cs b/src/EditorFeatures/CSharpTest2/EmbeddedLanguages/Json/CSharpJsonParserTests_BasicTests.cs index 84db8de6c6532..350f9bdec9ddd 100644 --- a/src/EditorFeatures/CSharpTest2/EmbeddedLanguages/Json/CSharpJsonParserTests_BasicTests.cs +++ b/src/EditorFeatures/CSharpTest2/EmbeddedLanguages/Json/CSharpJsonParserTests_BasicTests.cs @@ -1168,7 +1168,7 @@ public void TestMissingColon() ", @" - + ", @" @@ -1328,10 +1328,10 @@ public void TestNestedPropertyMissingColon() ", @" - + ", @" - + "); } @@ -1367,10 +1367,10 @@ public void TestMissingColon2() ", @" - + ", @" - + "); } diff --git a/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonParser.cs b/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonParser.cs index 9f61c82948ba6..ba00428e86e0a 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonParser.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonParser.cs @@ -213,6 +213,7 @@ private JsonTree ParseTree(JsonOptions options) var diagnostic = node.Kind switch { JsonKind.Array => CheckArray((JsonArrayNode)node), + JsonKind.Object => CheckObject((JsonObjectNode)node), _ => null, }; @@ -246,7 +247,22 @@ private JsonTree ParseTree(JsonOptions options) } } - return CheckChildren(node); + return null; + } + + static EmbeddedDiagnostic? CheckObject(JsonObjectNode node) + { + foreach (var child in node.Sequence) + { + if (child is JsonLiteralNode { LiteralToken.Kind: JsonKind.StringToken }) + { + return new EmbeddedDiagnostic( + FeaturesResources.Property_name_must_be_followed_by_a_colon, + child.GetSpan()); + } + } + + return null; } } diff --git a/src/Features/Core/Portable/FeaturesResources.resx b/src/Features/Core/Portable/FeaturesResources.resx index 0b3f3598cc546..2ded6207f80f8 100644 --- a/src/Features/Core/Portable/FeaturesResources.resx +++ b/src/Features/Core/Portable/FeaturesResources.resx @@ -3082,6 +3082,9 @@ Zero-width positive lookbehind assertions are typically used at the beginning of Property name must be a string + + Property name must be followed by a ':' + Strings must start with " not ' diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf index b17d57b131e40..8292c84c09cb9 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf @@ -1220,6 +1220,11 @@ Ujistěte se, že specifikátor tt použijete pro jazyky, pro které je nezbytn Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated Odkaz na vlastnost se nedá aktualizovat. diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf index d8eba792ed050..9b9d7171f0d41 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf @@ -1220,6 +1220,11 @@ Stellen Sie sicher, dass Sie den Bezeichner "tt" für Sprachen verwenden, für d Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated Der Eigenschaftenverweis kann nicht aktualisiert werden. diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf index 7833a29910cae..fca888dc734b0 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf @@ -1220,6 +1220,11 @@ Asegúrese de usar el especificador "tt" para los idiomas para los que es necesa Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated No se puede actualizar la referencia de propiedad diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf index 7e28c69e6e8c5..1fe750400d573 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf @@ -1220,6 +1220,11 @@ Veillez à utiliser le spécificateur "tt" pour les langues où il est nécessai Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated La référence de propriété ne peut pas être mise à jour diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf index 1b07cde1483b7..8802fa66e1cc4 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf @@ -1220,6 +1220,11 @@ Assicurarsi di usare l'identificatore "tt" per le lingue per le quali è necessa Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated Non è possibile aggiornare il riferimento alla proprietà diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf index 3518e47ac51d7..ffad8467d62c0 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf @@ -1220,6 +1220,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated プロパティ参照を更新できません diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf index d5cd4943a0a70..49c0f7158674e 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf @@ -1220,6 +1220,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated 속성 참조를 업데이트할 수 없습니다. diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf index 50a84b6da2dfa..a5ad926f8fb34 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf @@ -1220,6 +1220,11 @@ Pamiętaj, aby nie używać specyfikatora „tt” dla wszystkich języków, w k Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated Nie można zaktualizować referencji właściwości diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf index fa5d7ad61c39c..37314d6f58b0c 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf @@ -1220,6 +1220,11 @@ Verifique se o especificador "tt" foi usado para idiomas para os quais é necess Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated A referência de propriedade não pode ser atualizada diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf index 3476b7e7900b7..64b532d087a02 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf @@ -1220,6 +1220,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated Не удается обновить ссылку на свойство diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf index 1922e8a8861e3..b63f182a925fe 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf @@ -1220,6 +1220,11 @@ AM ve PM arasındaki farkın korunmasının gerekli olduğu diller için "tt" be Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated Özellik başvurusu güncelleştirilemiyor diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf index 385cee9491017..9a4298a456241 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf @@ -1220,6 +1220,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated 无法更新属性引用 diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf index fdfb9cf7132b8..6e6011af9b13e 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf @@ -1220,6 +1220,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma Property name must be a string + + Property name must be followed by a ':' + Property name must be followed by a ':' + + Property reference cannot be updated 無法更新屬性參考 From ded237d5824d86f1ed7a92e567ca2792e4de269b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 18 Feb 2022 12:55:07 -0800 Subject: [PATCH 2/2] Update tests --- .../Json/CSharpJsonParserTests_NstTests.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/EditorFeatures/CSharpTest2/EmbeddedLanguages/Json/CSharpJsonParserTests_NstTests.cs b/src/EditorFeatures/CSharpTest2/EmbeddedLanguages/Json/CSharpJsonParserTests_NstTests.cs index 579cc5e8eb4b9..673578b9e7e0a 100644 --- a/src/EditorFeatures/CSharpTest2/EmbeddedLanguages/Json/CSharpJsonParserTests_NstTests.cs +++ b/src/EditorFeatures/CSharpTest2/EmbeddedLanguages/Json/CSharpJsonParserTests_NstTests.cs @@ -3028,10 +3028,10 @@ public void n_object_comma_instead_of_colon_json() ", @" - + ", @" - + "); } @@ -3188,10 +3188,10 @@ public void n_object_missing_colon_json() ", @" - + ", @" - + "); } @@ -3250,10 +3250,10 @@ public void n_object_missing_semicolon_json() ", @" - + ", @" - + "); } @@ -3308,10 +3308,10 @@ public void n_object_no_colon_json() ", @" - + ", @" - + "); } @@ -3762,10 +3762,10 @@ public void n_object_with_single_string_json() ", @" - + ", @" - + "); } @@ -5299,10 +5299,10 @@ public void n_structure_open_object_string_with_apostrophes_json() ", @" - + ", @" - + "); }