@@ -21,6 +21,7 @@ import * as assert from 'node:assert';
2121import { stream } from '../utils/stream.js' ;
2222import { Disposable } from '../utils/disposable.js' ;
2323import { normalizeEOL } from '../generate/template-string.js' ;
24+ import { DocumentValidator } from '../validation/document-validator.js' ;
2425
2526export interface ParseHelperOptions extends BuildOptions {
2627 /**
@@ -550,18 +551,29 @@ export interface ValidationResult<T extends AstNode = AstNode> extends AsyncDisp
550551 document : LangiumDocument < T > ;
551552}
552553
553- export function validationHelper < T extends AstNode = AstNode > ( services : LangiumCoreServices ) : ( input : string , options ?: ParseHelperOptions ) => Promise < ValidationResult < T > > {
554+ export type ValidationHelperOptions = ParseHelperOptions & { failOnParsingErrors ?: boolean } ;
555+
556+ export function validationHelper < T extends AstNode = AstNode > ( services : LangiumCoreServices ) : ( input : string , options ?: ValidationHelperOptions ) => Promise < ValidationResult < T > > {
554557 const parse = parseHelper < T > ( services ) ;
555558 return async ( input , options ) => {
556559 const document = await parse ( input , {
557560 ...( options ?? { } ) ,
558561 validation : true
559562 } ) ;
560- return {
563+ const result = {
561564 document,
562565 diagnostics : document . diagnostics ?? [ ] ,
563566 dispose : ( ) => clearDocuments ( services , [ document ] )
564567 } ;
568+ if ( options ?. failOnParsingErrors ) {
569+ expectNoIssues ( result , {
570+ severity : DiagnosticSeverity . Error ,
571+ data : {
572+ code : DocumentValidator . ParsingError ,
573+ } ,
574+ } ) ;
575+ }
576+ return result ;
565577 } ;
566578}
567579
0 commit comments