From 67b13402158a209ec0f4226594a58b4450476825 Mon Sep 17 00:00:00 2001 From: Jessica He Date: Wed, 10 Aug 2022 18:03:29 -0400 Subject: [PATCH] Improve readability of the first line in error messages. Signed-off-by: Jessica He --- .../xerces/LSPMessageFormatter.java | 6 +---- .../XMLSchemaMessagesReformatted.properties | 6 ++--- .../XMLSchemaDiagnosticsTest.java | 22 +++++++++---------- .../commands/XMLValidationCommandTest.java | 4 ++-- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xerces/LSPMessageFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xerces/LSPMessageFormatter.java index 524724ec3..84cec033c 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xerces/LSPMessageFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xerces/LSPMessageFormatter.java @@ -137,9 +137,6 @@ public static Object[] reformatSchemaArguments(XMLSchemaErrorCode code, Object[] return cvc_2_4_b_solution(arguments); case cvc_enumeration_valid: return enumeration_valid_solution(arguments); - case cvc_complex_type_4: - arguments[1] = "- " + arguments[1]; - arguments[0] = "- " + arguments[0]; default: return arguments; } @@ -237,7 +234,6 @@ private static Object[] cvc_2_4_a_solution(Object[] arguments) { schema = "{the schema}"; validNames = reformatElementNames(getString(arguments[1])); } - name = "- " + name; return new Object[] { name, validNames, schema }; } @@ -272,7 +268,7 @@ private static Object[] cvc_2_4_b_solution(Object[] arguments) { missingChildElements = reformatElementNames(getString(arguments[1])); schema = "{the schema}"; } - element = "- " + getString(arguments[0]); + element = getString(arguments[0]); return new Object[] { element, missingChildElements, schema }; } diff --git a/org.eclipse.lemminx/src/main/resources/XMLSchemaMessagesReformatted.properties b/org.eclipse.lemminx/src/main/resources/XMLSchemaMessagesReformatted.properties index 6b1df9118..76c402379 100644 --- a/org.eclipse.lemminx/src/main/resources/XMLSchemaMessagesReformatted.properties +++ b/org.eclipse.lemminx/src/main/resources/XMLSchemaMessagesReformatted.properties @@ -25,11 +25,11 @@ # changed cvc-complex-type.2.3 = Element ''{0}'' cannot contain text content.\nThe content type is defined as element-only.\n\nCode: # changed - cvc-complex-type.2.4.a = Invalid element name:\n {0}\n\nOne of the following is expected:\n{1}\nError indicated by:\n {2}\nwith code: + cvc-complex-type.2.4.a = Element name ''{0}'' is invalid.\n\nOne of the following is expected:\n{1}\nError indicated by:\n {2}\nwith code: # changed - cvc-complex-type.2.4.b = Child elements are missing from element:\n {0}\n\nThe following elements are expected:\n{1}\nError indicated by\n {2}\nwith code: + cvc-complex-type.2.4.b = Child elements are missing from element ''{0}''.\n\nThe following elements are expected:\n{1}\nError indicated by:\n {2}\nwith code: # changed - cvc-complex-type.4 = Attribute:\n {1}\nis required in element:\n {0}\n\nCode: + cvc-complex-type.4 = Attribute ''{1}'' is missing from element ''{0}''.\n\nCode: # changed cvc-datatype-valid.1.2.1 = Content of type ''{1}'' is expected.\n\nThe following content is not a valid type:\n ''{0}''\n\nCode: # changed diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java index afbeb863f..60b01cc1f 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java @@ -92,7 +92,7 @@ public void cvc_complex_type_4() throws Exception { " \r\n" + // ""; Diagnostic d = d(3, 3, 3, 11, XMLSchemaErrorCode.cvc_complex_type_4, - "Attribute:\n - name\nis required in element:\n - property\n\nCode:"); + "Attribute 'name' is missing from element 'property'.\n\nCode:"); testDiagnosticsWithCatalogFor(xml, d); testCodeActionsFor(xml, d, ca(d, te(3, 11, 3, 11, " name=\"\""))); } @@ -112,9 +112,9 @@ public void cvc_type_4_Multiple_attributes() throws Exception { " \r\n" + // ""; Diagnostic d2 = d(6, 4, 6, 11, XMLSchemaErrorCode.cvc_complex_type_4, - "Attribute:\n - description\nis required in element:\n - product\n\nCode:"); + "Attribute 'description' is missing from element 'product'.\n\nCode:"); Diagnostic d1 = d(6, 4, 6, 11, XMLSchemaErrorCode.cvc_complex_type_4, - "Attribute:\n - price\nis required in element:\n - product\n\nCode:"); + "Attribute 'price' is missing from element 'product'.\n\nCode:"); testDiagnosticsFor(xml, d1, d2); testCodeActionsFor(xml, d1, ca(d1, te(6, 11, 6, 11, " price=\"\" description=\"\""))); @@ -129,7 +129,7 @@ public void cvc_complex_type_2_4_a() throws Exception { " \r\n" + // <- error ""; - String message = "Invalid element name:\n - XXX\n\nOne of the following is expected:\n - modelVersion\n - parent\n - groupId\n - artifactId\n - version\n - packaging\n - name\n - description\n - url\n - inceptionYear\n - organization\n - licenses\n - developers\n - contributors\n - mailingLists\n - prerequisites\n - modules\n - scm\n - issueManagement\n - ciManagement\n - distributionManagement\n - properties\n - dependencyManagement\n - dependencies\n - repositories\n - pluginRepositories\n - build\n - reports\n - reporting\n - profiles\n\nError indicated by:\n {http://maven.apache.org/POM/4.0.0}\nwith code:"; + String message = "Element name 'XXX' is invalid.\n\nOne of the following is expected:\n - modelVersion\n - parent\n - groupId\n - artifactId\n - version\n - packaging\n - name\n - description\n - url\n - inceptionYear\n - organization\n - licenses\n - developers\n - contributors\n - mailingLists\n - prerequisites\n - modules\n - scm\n - issueManagement\n - ciManagement\n - distributionManagement\n - properties\n - dependencyManagement\n - dependencies\n - repositories\n - pluginRepositories\n - build\n - reports\n - reporting\n - profiles\n\nError indicated by:\n {http://maven.apache.org/POM/4.0.0}\nwith code:"; testDiagnosticsWithCatalogFor(xml, d(3, 2, 3, 5, XMLSchemaErrorCode.cvc_complex_type_2_4_a, message)); } @@ -581,7 +581,7 @@ public void issue217() { " \r\n" + // ""; Diagnostic d = d(1, 1, 1, 10, XMLSchemaErrorCode.cvc_complex_type_2_4_b, - "Child elements are missing from element:\n - edmx:Edmx\n\nThe following elements are expected:\n - Reference\n - DataServices\n\nError indicated by\n {http://docs.oasis-open.org/odata/ns/edmx\":Reference, \"http://docs.oasis-open.org/odata/ns/edmx}\nwith code:"); + "Child elements are missing from element 'edmx:Edmx'.\n\nThe following elements are expected:\n - Reference\n - DataServices\n\nError indicated by:\n {http://docs.oasis-open.org/odata/ns/edmx\":Reference, \"http://docs.oasis-open.org/odata/ns/edmx}\nwith code:"); testDiagnosticsWithCatalogFor(xml, d); } @@ -682,7 +682,7 @@ public void fuzzyElementNameCodeActionTest() throws Exception { " \r\n" + // ""; Diagnostic diagnostic = d(4, 7, 4, 13, XMLSchemaErrorCode.cvc_complex_type_2_4_a, - "Invalid element name:\n - bodule\n\nOne of the following is expected:\n - module\n\nError indicated by:\n {http://maven.apache.org/POM/4.0.0}\nwith code:"); + "Element name 'bodule' is invalid.\n\nOne of the following is expected:\n - module\n\nError indicated by:\n {http://maven.apache.org/POM/4.0.0}\nwith code:"); testDiagnosticsWithCatalogFor(xml, diagnostic); testCodeActionsWithCatalogFor(xml, diagnostic, @@ -706,8 +706,7 @@ public void fuzzyElementNamesWithOtherOptionsCodeActionTest() throws Exception { " \r\n" + // ""; Diagnostic diagnostic = d(4, 7, 4, 16, XMLSchemaErrorCode.cvc_complex_type_2_4_a, // - "Invalid element name:\n" + // - " - XXXXXXXXX\n\n" + // + "Element name 'XXXXXXXXX' is invalid.\n\n" + // "One of the following is expected:\n" + // " - system\n" + // " - url\n" + // @@ -733,8 +732,7 @@ public void elementFormDefaultUnqualified() throws Exception { " \r\n" + // ""; Diagnostic diagnostic = d(1, 2, 1, 5, XMLSchemaErrorCode.cvc_complex_type_2_4_a, // - "Invalid element name:\n" + // - " - bar\n\n" + // + "Element name 'bar' is invalid.\n\n" + // "One of the following is expected:\n" + // " - bar\n\n" + // "Error indicated by:\n" + // @@ -1128,7 +1126,7 @@ public void diagnosticRelatedInformationWithXMLModelSchemaProblem() throws Excep diagnostic.getRelatedInformation().add(new DiagnosticRelatedInformation(l(xsdFileURI, r(1, 71, 1, 73)), "")); Diagnostic diagnosticBasedOnXSD = new Diagnostic(r(2, 2, 2, 6), - "Invalid element name:\n - barX\n\nOne of the following is expected:\n - bar\n\nError indicated by:\n {the schema}\nwith code:", + "Element name 'barX' is invalid.\n\nOne of the following is expected:\n - bar\n\nError indicated by:\n {the schema}\nwith code:", DiagnosticSeverity.Error, "xml", XMLSchemaErrorCode.cvc_complex_type_2_4_a.getCode()); XMLLanguageService xmlLanguageService = new XMLLanguageService(); @@ -1160,7 +1158,7 @@ public void diagnosticRelatedInformationWithNoNamespaceSchemaLocationSchemaProbl diagnostic.getRelatedInformation().add(new DiagnosticRelatedInformation(l(xsdFileURI, r(1, 71, 1, 73)), "")); Diagnostic diagnosticBasedOnXSD = new Diagnostic(r(2, 2, 2, 6), - "Invalid element name:\n - barX\n\nOne of the following is expected:\n - bar\n\nError indicated by:\n {the schema}\nwith code:", + "Element name 'barX' is invalid.\n\nOne of the following is expected:\n - bar\n\nError indicated by:\n {the schema}\nwith code:", DiagnosticSeverity.Error, "xml", XMLSchemaErrorCode.cvc_complex_type_2_4_a.getCode()); XMLLanguageService xmlLanguageService = new XMLLanguageService(); diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/commands/XMLValidationCommandTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/commands/XMLValidationCommandTest.java index fd71854f6..44b070f5d 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/commands/XMLValidationCommandTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/commands/XMLValidationCommandTest.java @@ -107,7 +107,7 @@ public void validationFileCommand() throws Exception { "cvc-elt.1.a: Cannot find the declaration of element 'root'.", "xml", DiagnosticSeverity.Error)), // pd(xmlIdentifier.getUri(), d(4, 3, 4, 7, XMLSchemaErrorCode.cvc_complex_type_2_4_a, - "Invalid element name:\n - tags\n\nOne of the following is expected:\n - tag\n\nError indicated by:\n {the schema}\nwith code:", + "Element name 'tags' is invalid.\n\nOne of the following is expected:\n - tag\n\nError indicated by:\n {the schema}\nwith code:", "xml", DiagnosticSeverity.Error) )); @@ -262,7 +262,7 @@ public void validationAllFilesCommand() throws Exception { "cvc-elt.1.a: Cannot find the declaration of element 'root'.", "xml", DiagnosticSeverity.Error)), // pd(xml1Identifier.getUri(), d(4, 3, 4, 7, XMLSchemaErrorCode.cvc_complex_type_2_4_a, - "Invalid element name:\n - tags\n\nOne of the following is expected:\n - tag\n\nError indicated by:\n {the schema}\nwith code:", + "Element name 'tags' is invalid.\n\nOne of the following is expected:\n - tag\n\nError indicated by:\n {the schema}\nwith code:", "xml", DiagnosticSeverity.Error)), // pd(xml2Identifier.getUri(), d(1, 23, 1, 53, ExternalResourceErrorCode.DownloadingResource,