mirror of
https://github.com/danbulant/monaco-yaml
synced 2026-06-19 14:31:13 +00:00
fix: fix error type issues
This commit is contained in:
parent
cb10912b7e
commit
1e0e5ebb54
4 changed files with 40 additions and 31 deletions
|
|
@ -9,7 +9,7 @@
|
|||
"watch": "tsc -p ./src --watch",
|
||||
"prepublish": "rimraf ./out && rimraf ./release && yarn compile:umd && node ./scripts/bundle && mcopy ./src/monaco.d.ts ./release/monaco.d.ts",
|
||||
"lint": "prettier \"{src,test}/**/*.{json,scss,html,ts}\" --write",
|
||||
"test": "jest"
|
||||
"test": "jest --verbose"
|
||||
},
|
||||
"author": "Kevin Decker <kpdecker@gmail.com> (http://incaseofstairs.com)",
|
||||
"maintainers": [
|
||||
|
|
@ -51,14 +51,11 @@
|
|||
},
|
||||
"lint-staged": {
|
||||
"linters": {
|
||||
"*.{json,scss,html}": [
|
||||
"*.{json,scss,html,ts}": [
|
||||
"prettier --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"ignore": [
|
||||
"src/backend/vendor/**/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
StringASTNodeImpl,
|
||||
} from './jsonParser';
|
||||
import { parseYamlBoolean } from './scalar-type';
|
||||
import { DiagnosticSeverity } from 'vscode-languageserver-types';
|
||||
|
||||
function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
||||
if (!node) {
|
||||
|
|
@ -99,10 +100,10 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
|||
const itemNode =
|
||||
item === null
|
||||
? new NullASTNodeImpl(
|
||||
parent,
|
||||
instance.startPosition,
|
||||
instance.endPosition - instance.startPosition
|
||||
)
|
||||
parent,
|
||||
instance.startPosition,
|
||||
instance.endPosition - instance.startPosition
|
||||
)
|
||||
: recursivelyBuildAst(result, item);
|
||||
|
||||
result.items.push(itemNode);
|
||||
|
|
@ -225,10 +226,16 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
|||
function convertError(e: Yaml.Error) {
|
||||
return {
|
||||
message: `${e.reason}`,
|
||||
// TODO: YAML ast parser does not give a length for validation error,
|
||||
// TODO: thus we treat the range from line start to the target position.
|
||||
location: {
|
||||
offset: e.mark.position,
|
||||
code: ErrorCode.Undefined,
|
||||
offset: e.mark.position - e.mark.column,
|
||||
length: e.mark.column,
|
||||
},
|
||||
code: ErrorCode.Undefined,
|
||||
severity: e.isWarning
|
||||
? DiagnosticSeverity.Warning
|
||||
: DiagnosticSeverity.Error,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -248,14 +255,18 @@ function createJSONDocument(
|
|||
'Expected a YAML object, array or literal'
|
||||
),
|
||||
code: ErrorCode.Undefined,
|
||||
location: { start: yamlDoc.startPosition, end: yamlDoc.endPosition },
|
||||
location: {
|
||||
offset: yamlDoc.startPosition,
|
||||
length: yamlDoc.endPosition - yamlDoc.startPosition,
|
||||
},
|
||||
severity: DiagnosticSeverity.Error,
|
||||
});
|
||||
}
|
||||
|
||||
const duplicateKeyReason = 'duplicate key';
|
||||
|
||||
// Patch ontop of yaml-ast-parser to disable duplicate key message on merge key
|
||||
const isDuplicateAndNotMergeKey = function (
|
||||
const isDuplicateAndNotMergeKey = function(
|
||||
error: Yaml.Error,
|
||||
yamlText: string
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { DiagnosticSeverity, TextDocument } from 'vscode-languageserver-types';
|
||||
import { DiagnosticSeverity, TextDocument, Diagnostic } from 'vscode-languageserver-types';
|
||||
import { LanguageSettings } from '../yamlLanguageService';
|
||||
import { YAMLDocument } from '../yamlLanguageTypes';
|
||||
import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService';
|
||||
import { Thenable } from '../jsonLanguageTypes';
|
||||
|
||||
export class YAMLValidation {
|
||||
private validationEnabled: boolean;
|
||||
|
|
@ -22,14 +23,14 @@ export class YAMLValidation {
|
|||
}
|
||||
}
|
||||
|
||||
public doValidation(textDocument: TextDocument, yamlDocument: YAMLDocument) {
|
||||
public doValidation(textDocument: TextDocument, yamlDocument: YAMLDocument): Thenable<Diagnostic[]> {
|
||||
if (!this.validationEnabled) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
return this.jsonSchemaService
|
||||
.getSchemaForResource(textDocument.uri)
|
||||
.then(function(schema) {
|
||||
const diagnostics = [];
|
||||
.then(function (schema) {
|
||||
const diagnostics: Diagnostic[] = [];
|
||||
const added = {};
|
||||
let newSchema = schema;
|
||||
if (schema) {
|
||||
|
|
@ -53,10 +54,11 @@ export class YAMLValidation {
|
|||
const curDiagnostic = diagnostics[diag];
|
||||
currentDoc.errors.push({
|
||||
location: {
|
||||
start: curDiagnostic.range.start,
|
||||
end: curDiagnostic.range.end,
|
||||
offset: textDocument.offsetAt(curDiagnostic.range.start),
|
||||
length: textDocument.offsetAt(curDiagnostic.range.end) - textDocument.offsetAt(curDiagnostic.range.start),
|
||||
},
|
||||
message: curDiagnostic.message,
|
||||
severity: curDiagnostic.severity,
|
||||
});
|
||||
}
|
||||
documentIndex++;
|
||||
|
|
@ -84,26 +86,25 @@ export class YAMLValidation {
|
|||
const currentDoc = yamlDocument.documents[currentYAMLDoc];
|
||||
currentDoc.errors
|
||||
.concat(currentDoc.warnings)
|
||||
.forEach(function(error, idx) {
|
||||
.forEach(function (error, idx) {
|
||||
// remove duplicated messages
|
||||
const signature =
|
||||
error.location.start +
|
||||
error.location.offset +
|
||||
' ' +
|
||||
error.location.end +
|
||||
error.location.length +
|
||||
' ' +
|
||||
error.message;
|
||||
if (!added[signature]) {
|
||||
added[signature] = true;
|
||||
const range = {
|
||||
start: textDocument.positionAt(error.location.start),
|
||||
end: textDocument.positionAt(error.location.end),
|
||||
};
|
||||
diagnostics.push({
|
||||
severity:
|
||||
idx >= currentDoc.errors.length
|
||||
? DiagnosticSeverity.Warning
|
||||
: DiagnosticSeverity.Error,
|
||||
range,
|
||||
range: {
|
||||
start: textDocument.positionAt(error.location.offset),
|
||||
end: textDocument.positionAt(error.location.offset + error.location.length),
|
||||
},
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { ASTNode } from './jsonLanguageTypes';
|
||||
import { JSONDocument } from './parser/jsonParser';
|
||||
import { JSONDocument, IProblem } from './parser/jsonParser';
|
||||
|
||||
export class SingleYAMLDocument extends JSONDocument {
|
||||
public lines;
|
||||
public errors;
|
||||
public warnings;
|
||||
public errors: IProblem[];
|
||||
public warnings: IProblem[];
|
||||
|
||||
constructor(lines: number[]) {
|
||||
super(null, []);
|
||||
|
|
|
|||
Loading…
Reference in a new issue