88import { JSONSchemaService } from './jsonSchemaService' ;
99import { Diagnostic , DiagnosticSeverity } from 'vscode-languageserver-types' ;
1010import { PromiseConstructor , Thenable , LanguageSettings } from '../yamlLanguageService' ;
11- import { TextDocument } from "vscode-languageserver-types" ;
11+ import { TextDocument , Position } from "vscode-languageserver-types" ;
1212import { YAMLDocument , SingleYAMLDocument } from "../parser/yamlParser" ;
1313import { IProblem , ProblemSeverity } from '../parser/jsonParser' ;
1414
@@ -45,6 +45,33 @@ export class YAMLValidation {
4545 }
4646
4747 if ( yamlDocument . documents . length > 1 ) {
48+ //The YAML parser is a little over-eager to call things different documents
49+ // see https://github.com/Microsoft/azure-pipelines-vscode/issues/219
50+ //so search for a specific error so that we can offer the user better guidance
51+ for ( let document of yamlDocument . documents ) {
52+ for ( let docError of document . errors ) {
53+ if ( docError . getMessage ( ) . includes ( "end of the stream or a document separator is expected" ) ) {
54+ const docErrorPosition : Position = textDocument . positionAt ( docError . start ) ;
55+ const errorLine : number = ( docErrorPosition . line > 0 ) ? docErrorPosition . line - 1 : docErrorPosition . line ;
56+
57+ return this . promise . resolve ( [ {
58+ severity : DiagnosticSeverity . Error ,
59+ range : {
60+ start : {
61+ line : errorLine ,
62+ character : 0
63+ } ,
64+ end : {
65+ line : errorLine + 1 ,
66+ character : 0
67+ }
68+ } ,
69+ message : localize ( 'documentFormatError' , 'Invalid YAML structure' )
70+ } ] ) ;
71+ }
72+ }
73+ }
74+
4875 return this . promise . resolve ( [ {
4976 severity : DiagnosticSeverity . Error ,
5077 range : {
@@ -55,7 +82,7 @@ export class YAMLValidation {
5582 end : textDocument . positionAt ( textDocument . getText ( ) . length )
5683 } ,
5784 message : localize ( 'multiDocumentError' , 'Only single-document files are supported' )
58- } ] )
85+ } ] ) ;
5986 }
6087
6188 const translateSeverity = ( problemSeverity : ProblemSeverity ) : DiagnosticSeverity => {
0 commit comments