@@ -155,12 +155,14 @@ func (validator *JSONSchemaValidator) ValidateWithJSONSchema(rootNode *sitter.No
155155 return []protocol.Diagnostic {utils .CreateErrorDiagnosticFromNode (rootNode , err .Error ())}
156156 }
157157
158+ jsonSchemaDiags := []protocol.Diagnostic {}
159+
158160 if ! result .Valid () {
159161 for _ , resErr := range result .Errors () {
160162 fields := strings .Split (resErr .Field (), "." )
161163 if len (fields ) == 1 && fields [0 ] == "(root)" {
162164 diagnostic := utils .CreateErrorDiagnosticFromNode (rootNode , resErr .Description ())
163- diagnostics = append (diagnostics , diagnostic )
165+ jsonSchemaDiags = append (jsonSchemaDiags , diagnostic )
164166 } else {
165167 node , err := FindDeepestNode (rootNode , content , fields )
166168 if err != nil {
@@ -172,11 +174,14 @@ func (validator *JSONSchemaValidator) ValidateWithJSONSchema(rootNode *sitter.No
172174 }
173175
174176 diagnostic := utils .CreateErrorDiagnosticFromNode (node , resErr .Description ())
175- diagnostics = append (diagnostics , diagnostic )
177+ jsonSchemaDiags = append (jsonSchemaDiags , diagnostic )
176178 }
177179 }
178180 }
179181
182+ jsonSchemaDiags = removeUselessMustValidateError (jsonSchemaDiags )
183+ diagnostics = append (diagnostics , jsonSchemaDiags ... )
184+
180185 return diagnostics
181186}
182187
@@ -209,3 +214,33 @@ func (validator *JSONSchemaValidator) doesNodeUseParameter(node *sitter.Node) bo
209214
210215 return false
211216}
217+ func removeUselessMustValidateError (diags []protocol.Diagnostic ) []protocol.Diagnostic {
218+ resDiags := []protocol.Diagnostic {}
219+ for i , diag := range diags {
220+ if diag .Message == "Must validate one and only one schema (oneOf)" {
221+ if hasAnotherDiagInsideRange (diags , diag .Range ) {
222+ continue
223+ }
224+ resDiags = append (resDiags , utils .CreateDiagnosticFromRange (
225+ diag .Range ,
226+ diag .Severity ,
227+ "Invalid structure" ,
228+ []protocol.CodeAction {},
229+ ))
230+ } else {
231+ resDiags = append (resDiags , diags [i ])
232+ }
233+ }
234+
235+ return resDiags
236+ }
237+
238+ func hasAnotherDiagInsideRange (diags []protocol.Diagnostic , rangeToCheck protocol.Range ) bool {
239+ for _ , diag := range diags {
240+ if utils .PosInRange (rangeToCheck , diag .Range .Start ) {
241+ return true
242+ }
243+ }
244+
245+ return false
246+ }
0 commit comments