Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions language-service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

#### 0.5.5
Better handling of YAML structure errors

#### 0.5.4
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)

Expand Down
2 changes: 1 addition & 1 deletion language-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion language-service/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "azure-pipelines-language-service",
"description": "Azure Pipelines language service",
"version": "0.5.4",
"version": "0.5.5",
"author": "Microsoft",
"license": "MIT",
"main": "./lib/src/index.js",
Expand Down
31 changes: 29 additions & 2 deletions language-service/src/services/yamlValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { JSONSchemaService } from './jsonSchemaService';
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types';
import { PromiseConstructor, Thenable, LanguageSettings} from '../yamlLanguageService';
import { TextDocument } from "vscode-languageserver-types";
import { TextDocument, Position } from "vscode-languageserver-types";
import { YAMLDocument, SingleYAMLDocument } from "../parser/yamlParser";
import { IProblem, ProblemSeverity } from '../parser/jsonParser';

Expand Down Expand Up @@ -45,6 +45,33 @@ export class YAMLValidation {
}

if (yamlDocument.documents.length > 1) {
//The YAML parser is a little over-eager to call things different documents
// see https://github.com/Microsoft/azure-pipelines-vscode/issues/219
//so search for a specific error so that we can offer the user better guidance
for (let document of yamlDocument.documents) {
for (let docError of document.errors) {
if (docError.getMessage().includes("end of the stream or a document separator is expected")) {
const docErrorPosition : Position = textDocument.positionAt(docError.start);
const errorLine: number = (docErrorPosition.line > 0) ? docErrorPosition.line - 1 : docErrorPosition.line;

return this.promise.resolve([{
severity: DiagnosticSeverity.Error,
range: {
start: {
line: errorLine,
character: 0
},
end: {
line: errorLine + 1,
character: 0
}
},
message: localize('documentFormatError', 'Invalid YAML structure')
}]);
}
}
}

return this.promise.resolve([{
severity: DiagnosticSeverity.Error,
range: {
Expand All @@ -55,7 +82,7 @@ export class YAMLValidation {
end: textDocument.positionAt(textDocument.getText().length)
},
message: localize('multiDocumentError', 'Only single-document files are supported')
}])
}]);
}

const translateSeverity = (problemSeverity: ProblemSeverity): DiagnosticSeverity => {
Expand Down