Skip to content

Commit cee43a8

Browse files
authored
fix for 219 (#58)
1 parent 46dffd3 commit cee43a8

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

language-service/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
#### 0.5.5
3+
Better handling of YAML structure errors
4+
25
#### 0.5.4
36
Change schema service to use a schema object instead of a JSON string [#PR-53](https://github.com/Microsoft/azure-pipelines-language-server/pull/53)
47

language-service/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

language-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "azure-pipelines-language-service",
33
"description": "Azure Pipelines language service",
4-
"version": "0.5.4",
4+
"version": "0.5.5",
55
"author": "Microsoft",
66
"license": "MIT",
77
"main": "./lib/src/index.js",

language-service/src/services/yamlValidation.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { JSONSchemaService } from './jsonSchemaService';
99
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types';
1010
import { PromiseConstructor, Thenable, LanguageSettings} from '../yamlLanguageService';
11-
import { TextDocument } from "vscode-languageserver-types";
11+
import { TextDocument, Position } from "vscode-languageserver-types";
1212
import { YAMLDocument, SingleYAMLDocument } from "../parser/yamlParser";
1313
import { 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

Comments
 (0)