Updates dockerfile
All checks were successful
Build and Push / build (push) Successful in 55s

This commit is contained in:
2026-02-16 15:09:37 -05:00
parent 8346776f2a
commit d181f77fb2
14943 changed files with 2078509 additions and 16 deletions

View File

@@ -0,0 +1,6 @@
import { Document, LineCounter } from 'yaml';
import { ASTNode, YamlNode } from '../jsonASTTypes';
declare type NodeRange = [number, number, number];
export declare function convertAST(parent: ASTNode, node: YamlNode, doc: Document, lineCounter: LineCounter): ASTNode | undefined;
export declare function toOffsetLength(range: NodeRange): [number, number];
export {};

View File

@@ -0,0 +1,183 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "yaml", "./jsonParser07"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toOffsetLength = exports.convertAST = void 0;
const yaml_1 = require("yaml");
const jsonParser07_1 = require("./jsonParser07");
const maxRefCount = 1000;
let refDepth = 0;
const seenAlias = new Set();
function convertAST(parent, node, doc, lineCounter) {
if (!parent) {
// first invocation
refDepth = 0;
}
if (!node) {
return null;
}
if ((0, yaml_1.isMap)(node)) {
return convertMap(node, parent, doc, lineCounter);
}
if ((0, yaml_1.isPair)(node)) {
return convertPair(node, parent, doc, lineCounter);
}
if ((0, yaml_1.isSeq)(node)) {
return convertSeq(node, parent, doc, lineCounter);
}
if ((0, yaml_1.isScalar)(node)) {
return convertScalar(node, parent);
}
if ((0, yaml_1.isAlias)(node) && !seenAlias.has(node) && refDepth < maxRefCount) {
seenAlias.add(node);
const converted = convertAlias(node, parent, doc, lineCounter);
seenAlias.delete(node);
return converted;
}
else {
return;
}
}
exports.convertAST = convertAST;
function convertMap(node, parent, doc, lineCounter) {
let range;
if (node.flow && !node.range) {
range = collectFlowMapRange(node);
}
else {
range = node.range;
}
const result = new jsonParser07_1.ObjectASTNodeImpl(parent, node, ...toFixedOffsetLength(range, lineCounter));
for (const it of node.items) {
if ((0, yaml_1.isPair)(it)) {
result.properties.push(convertAST(result, it, doc, lineCounter));
}
}
return result;
}
function convertPair(node, parent, doc, lineCounter) {
const keyNode = node.key;
const valueNode = node.value;
const rangeStart = keyNode.range[0];
let rangeEnd = keyNode.range[1];
let nodeEnd = keyNode.range[2];
if (valueNode) {
rangeEnd = valueNode.range[1];
nodeEnd = valueNode.range[2];
}
// Pair does not return a range using the key/value ranges to fake one.
const result = new jsonParser07_1.PropertyASTNodeImpl(parent, node, ...toFixedOffsetLength([rangeStart, rangeEnd, nodeEnd], lineCounter));
if ((0, yaml_1.isAlias)(keyNode)) {
const keyAlias = new jsonParser07_1.StringASTNodeImpl(parent, keyNode, ...toOffsetLength(keyNode.range));
keyAlias.value = keyNode.source;
result.keyNode = keyAlias;
}
else {
result.keyNode = convertAST(result, keyNode, doc, lineCounter);
}
result.valueNode = convertAST(result, valueNode, doc, lineCounter);
return result;
}
function convertSeq(node, parent, doc, lineCounter) {
const result = new jsonParser07_1.ArrayASTNodeImpl(parent, node, ...toOffsetLength(node.range));
for (const it of node.items) {
if ((0, yaml_1.isNode)(it)) {
const convertedNode = convertAST(result, it, doc, lineCounter);
// due to recursion protection, convertAST may return undefined
if (convertedNode) {
result.children.push(convertedNode);
}
}
}
return result;
}
function convertScalar(node, parent) {
if (node.value === null) {
return new jsonParser07_1.NullASTNodeImpl(parent, node, ...toOffsetLength(node.range));
}
switch (typeof node.value) {
case 'string': {
const result = new jsonParser07_1.StringASTNodeImpl(parent, node, ...toOffsetLength(node.range));
result.value = node.value;
return result;
}
case 'boolean':
return new jsonParser07_1.BooleanASTNodeImpl(parent, node, node.value, ...toOffsetLength(node.range));
case 'number': {
const result = new jsonParser07_1.NumberASTNodeImpl(parent, node, ...toOffsetLength(node.range));
result.value = node.value;
result.isInteger = Number.isInteger(result.value);
return result;
}
default: {
// fail safe converting, we need to return some node anyway
const result = new jsonParser07_1.StringASTNodeImpl(parent, node, ...toOffsetLength(node.range));
result.value = node.source;
return result;
}
}
}
function convertAlias(node, parent, doc, lineCounter) {
refDepth++;
const resolvedNode = node.resolve(doc);
if (resolvedNode) {
return convertAST(parent, resolvedNode, doc, lineCounter);
}
else {
const resultNode = new jsonParser07_1.StringASTNodeImpl(parent, node, ...toOffsetLength(node.range));
resultNode.value = node.source;
return resultNode;
}
}
function toOffsetLength(range) {
return [range[0], range[1] - range[0]];
}
exports.toOffsetLength = toOffsetLength;
/**
* Convert offsets to offset+length with fix length to not include '\n' character in some cases
* @param range the yaml ast range
* @param lineCounter the line counter
* @returns the offset and length
*/
function toFixedOffsetLength(range, lineCounter) {
const start = lineCounter.linePos(range[0]);
const end = lineCounter.linePos(range[1]);
const result = [range[0], range[1] - range[0]];
// -1 as range may include '\n'
if (start.line !== end.line && (lineCounter.lineStarts.length !== end.line || end.col === 1)) {
result[1]--;
}
return result;
}
function collectFlowMapRange(node) {
let start = Number.MAX_SAFE_INTEGER;
let end = 0;
for (const it of node.items) {
if ((0, yaml_1.isPair)(it)) {
if ((0, yaml_1.isNode)(it.key)) {
if (it.key.range && it.key.range[0] <= start) {
start = it.key.range[0];
}
}
if ((0, yaml_1.isNode)(it.value)) {
if (it.value.range && it.value.range[2] >= end) {
end = it.value.range[2];
}
}
}
}
return [start, end, end];
}
});
//# sourceMappingURL=ast-converter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
import { Tags } from 'yaml';
/**
* Converts the tags from settings and adds known tags such as !include
* and returns Tags that can be used by the parser.
* @param customTags Tags for parser
*/
export declare function getCustomTags(customTags: string[]): Tags;

View File

@@ -0,0 +1,72 @@
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "yaml", "../utils/arrUtils"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCustomTags = void 0;
const yaml_1 = require("yaml");
const arrUtils_1 = require("../utils/arrUtils");
class CommonTagImpl {
constructor(tag, type) {
this.tag = tag;
this.type = type;
}
get collection() {
if (this.type === 'mapping') {
return 'map';
}
if (this.type === 'sequence') {
return 'seq';
}
return undefined;
}
resolve(value) {
if ((0, yaml_1.isMap)(value) && this.type === 'mapping') {
return value;
}
if ((0, yaml_1.isSeq)(value) && this.type === 'sequence') {
return value;
}
if (typeof value === 'string' && this.type === 'scalar') {
return value;
}
}
}
class IncludeTag {
constructor() {
this.tag = '!include';
this.type = 'scalar';
}
resolve(value, onError) {
if (value && value.length > 0 && value.trim()) {
return value;
}
onError('!include without value');
}
}
/**
* Converts the tags from settings and adds known tags such as !include
* and returns Tags that can be used by the parser.
* @param customTags Tags for parser
*/
function getCustomTags(customTags) {
const tags = [];
const filteredTags = (0, arrUtils_1.filterInvalidCustomTags)(customTags);
for (const tag of filteredTags) {
const typeInfo = tag.split(' ');
const tagName = typeInfo[0];
const tagType = (typeInfo[1] && typeInfo[1].toLowerCase()) || 'scalar';
tags.push(new CommonTagImpl(tagName, tagType));
}
tags.push(new IncludeTag());
return tags;
}
exports.getCustomTags = getCustomTags;
});
//# sourceMappingURL=custom-tag-provider.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"custom-tag-provider.js","sourceRoot":"","sources":["../../../../src/languageservice/parser/custom-tag-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,+BAA4D;IAC5D,gDAA4D;IAE5D,MAAM,aAAa;QAIjB,YAAY,GAAW,EAAE,IAAY;YACnC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;QACD,IAAI,UAAU;YACZ,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;gBAC3B,OAAO,KAAK,CAAC;aACd;YACD,IAAI,I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YACvE,IAAI,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;SAChD;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAXD,sCAWC"}

View File

@@ -0,0 +1,4 @@
import { TextDocument } from 'vscode-languageserver-textdocument';
import * as Parser from './jsonParser07';
export declare function setKubernetesParserOption(jsonDocuments: Parser.JSONDocument[], option: boolean): void;
export declare function isKubernetesAssociatedDocument(textDocument: TextDocument, paths: string[]): boolean;

View File

@@ -0,0 +1,32 @@
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "../services/yamlSchemaService"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isKubernetesAssociatedDocument = exports.setKubernetesParserOption = void 0;
const yamlSchemaService_1 = require("../services/yamlSchemaService");
function setKubernetesParserOption(jsonDocuments, option) {
for (const jsonDoc of jsonDocuments) {
jsonDoc.isKubernetes = option;
}
}
exports.setKubernetesParserOption = setKubernetesParserOption;
function isKubernetesAssociatedDocument(textDocument, paths) {
for (const path in paths) {
const globPath = paths[path];
const fpa = new yamlSchemaService_1.FilePatternAssociation(globPath);
if (fpa.matchesPattern(textDocument.uri)) {
return true;
}
}
return false;
}
exports.isKubernetesAssociatedDocument = isKubernetesAssociatedDocument;
});
//# sourceMappingURL=isKubernetes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"isKubernetes.js","sourceRoot":"","sources":["../../../../src/languageservice/parser/isKubernetes.ts"],"names":[],"mappings":";;;;;;;;;;;;IAKA,qEAAuE;IAGvE,SAAgB,yBAAyB,CAAC,aAAoC,EAAE,MAAe;QAC7F,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE;YACnC,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC;SAC/B;IACH,CAAC;IAJD,8DAIC;IAED,SAAgB,8BAA8B,CAAC,YAA0B,EAAE,KAAe;QACxF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;YAC7B,MAAM,GAAG,GAAG,IAAI,0CAAsB,CAAC,QAAQ,CAAC,CAAC;YAEjD,IAAI,GAAG,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE;gBACxC,OAAO,IAAI,CAAC;aACb;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAVD,wEAUC"}

View File

@@ -0,0 +1,185 @@
import { JSONSchema, JSONSchemaRef } from '../jsonSchema';
import { ASTNode, ObjectASTNode, ArrayASTNode, BooleanASTNode, NumberASTNode, StringASTNode, NullASTNode, PropertyASTNode, YamlNode } from '../jsonASTTypes';
import { ErrorCode } from 'vscode-json-languageservice';
import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver-types';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { Node, Pair } from 'yaml';
export interface IRange {
offset: number;
length: number;
}
export declare const formats: {
'color-hex': {
errorMessage: string;
pattern: RegExp;
};
'date-time': {
errorMessage: string;
pattern: RegExp;
};
date: {
errorMessage: string;
pattern: RegExp;
};
time: {
errorMessage: string;
pattern: RegExp;
};
email: {
errorMessage: string;
pattern: RegExp;
};
ipv4: {
errorMessage: string;
pattern: RegExp;
};
ipv6: {
errorMessage: string;
pattern: RegExp;
};
};
export declare const YAML_SOURCE = "YAML";
export declare enum ProblemType {
missingRequiredPropWarning = "missingRequiredPropWarning",
typeMismatchWarning = "typeMismatchWarning",
constWarning = "constWarning"
}
export declare const ProblemTypeMessages: Record<ProblemType, string>;
export interface IProblem {
location: IRange;
severity: DiagnosticSeverity;
code?: ErrorCode;
message: string;
source?: string;
problemType?: ProblemType;
problemArgs?: string[];
schemaUri?: string[];
data?: Record<string, unknown>;
}
export declare abstract class ASTNodeImpl {
abstract readonly type: 'object' | 'property' | 'array' | 'number' | 'boolean' | 'null' | 'string';
offset: number;
length: number;
readonly parent: ASTNode;
location: string;
readonly internalNode: YamlNode;
constructor(parent: ASTNode, internalNode: YamlNode, offset: number, length?: number);
getNodeFromOffsetEndInclusive(offset: number): ASTNode;
get children(): ASTNode[];
toString(): string;
}
export declare class NullASTNodeImpl extends ASTNodeImpl implements NullASTNode {
type: 'null';
value: any;
constructor(parent: ASTNode, internalNode: Node, offset: number, length?: number);
}
export declare class BooleanASTNodeImpl extends ASTNodeImpl implements BooleanASTNode {
type: 'boolean';
value: boolean;
constructor(parent: ASTNode, internalNode: Node, boolValue: boolean, offset: number, length?: number);
}
export declare class ArrayASTNodeImpl extends ASTNodeImpl implements ArrayASTNode {
type: 'array';
items: ASTNode[];
constructor(parent: ASTNode, internalNode: Node, offset: number, length?: number);
get children(): ASTNode[];
}
export declare class NumberASTNodeImpl extends ASTNodeImpl implements NumberASTNode {
type: 'number';
isInteger: boolean;
value: number;
constructor(parent: ASTNode, internalNode: Node, offset: number, length?: number);
}
export declare class StringASTNodeImpl extends ASTNodeImpl implements StringASTNode {
type: 'string';
value: string;
constructor(parent: ASTNode, internalNode: Node, offset: number, length?: number);
}
export declare class PropertyASTNodeImpl extends ASTNodeImpl implements PropertyASTNode {
type: 'property';
keyNode: StringASTNode;
valueNode: ASTNode;
colonOffset: number;
constructor(parent: ObjectASTNode, internalNode: Pair, offset: number, length?: number);
get children(): ASTNode[];
}
export declare class ObjectASTNodeImpl extends ASTNodeImpl implements ObjectASTNode {
type: 'object';
properties: PropertyASTNode[];
constructor(parent: ASTNode, internalNode: Node, offset: number, length?: number);
get children(): ASTNode[];
}
export declare function asSchema(schema: JSONSchemaRef): JSONSchema | undefined;
export interface JSONDocumentConfig {
collectComments?: boolean;
}
export interface IApplicableSchema {
node: ASTNode;
inverted?: boolean;
schema: JSONSchema;
}
export declare enum EnumMatch {
Key = 0,
Enum = 1
}
export interface ISchemaCollector {
schemas: IApplicableSchema[];
add(schema: IApplicableSchema): void;
merge(other: ISchemaCollector): void;
include(node: ASTNode): boolean;
newSub(): ISchemaCollector;
}
export declare class ValidationResult {
problems: IProblem[];
propertiesMatches: number;
propertiesValueMatches: number;
primaryValueMatches: number;
enumValueMatch: boolean;
enumValues: any[];
constructor(isKubernetes: boolean);
hasProblems(): boolean;
mergeAll(validationResults: ValidationResult[]): void;
merge(validationResult: ValidationResult): void;
mergeEnumValues(validationResult: ValidationResult): void;
/**
* Merge multiple warnings with same problemType together
* @param subValidationResult another possible result
*/
mergeWarningGeneric(subValidationResult: ValidationResult, problemTypesToMerge: ProblemType[]): void;
mergePropertyMatch(propertyValidationResult: ValidationResult): void;
private mergeSources;
compareGeneric(other: ValidationResult): number;
compareKubernetes(other: ValidationResult): number;
}
export declare function newJSONDocument(root: ASTNode, diagnostics?: Diagnostic[]): JSONDocument;
export declare function getNodeValue(node: ASTNode): any;
export declare function contains(node: ASTNode, offset: number, includeRightBound?: boolean): boolean;
export declare function findNodeAtOffset(node: ASTNode, offset: number, includeRightBound: boolean): ASTNode;
export declare class JSONDocument {
readonly root: ASTNode;
readonly syntaxErrors: Diagnostic[];
readonly comments: Range[];
isKubernetes: boolean;
disableAdditionalProperties: boolean;
uri: string;
constructor(root: ASTNode, syntaxErrors?: Diagnostic[], comments?: Range[]);
getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
getNodeFromOffsetEndInclusive(offset: number): ASTNode;
visit(visitor: (node: ASTNode) => boolean): void;
validate(textDocument: TextDocument, schema: JSONSchema): Diagnostic[];
/**
* This method returns the list of applicable schemas
*
* currently used @param didCallFromAutoComplete flag to differentiate the method call, when it is from auto complete
* then user still types something and skip the validation for timebeing untill completed.
* On https://github.com/redhat-developer/yaml-language-server/pull/719 the auto completes need to populate the list of enum string which matches to the enum
* and on https://github.com/redhat-developer/vscode-yaml/issues/803 the validation should throw the error based on the enum string.
*
* @param schema schema
* @param focusOffset offsetValue
* @param exclude excluded Node
* @param didCallFromAutoComplete true if method called from AutoComplete
* @returns array of applicable schemas
*/
getMatchingSchemas(schema: JSONSchema, focusOffset?: number, exclude?: ASTNode, didCallFromAutoComplete?: boolean): IApplicableSchema[];
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
/**
* Parse a boolean according to the specification
*
* Return:
* true if its a true value
* false if its a false value
*/
export declare function parseYamlBoolean(input: string): boolean;

View File

@@ -0,0 +1,31 @@
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseYamlBoolean = void 0;
/**
* Parse a boolean according to the specification
*
* Return:
* true if its a true value
* false if its a false value
*/
function parseYamlBoolean(input) {
if (['true', 'True', 'TRUE', 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON'].lastIndexOf(input) >= 0) {
return true;
}
else if (['false', 'False', 'FALSE', 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'].lastIndexOf(input) >= 0) {
return false;
}
throw `Invalid boolean "${input}"`;
}
exports.parseYamlBoolean = parseYamlBoolean;
});
//# sourceMappingURL=scalar-type.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"scalar-type.js","sourceRoot":"","sources":["../../../../src/languageservice/parser/scalar-type.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA;;;;;;OAMG;IACH,SAAgB,gBAAgB,CAAC,KAAa;QAC5C,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YACrG,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YAC/G,OAAO,KAAK,CAAC;SACd;QACD,MAAM,oBAAoB,KAAK,GAAG,CAAC;IACrC,CAAC;IAPD,4CAOC"}

View File

@@ -0,0 +1,71 @@
import { TextDocument } from 'vscode-languageserver-textdocument';
import { JSONDocument } from './jsonParser07';
import { Document, LineCounter } from 'yaml';
import { ASTNode, YamlNode } from '../jsonASTTypes';
import { ParserOptions } from './yamlParser07';
import { YAMLDocDiagnostic } from '../utils/parseUtils';
import { TextBuffer } from '../utils/textBuffer';
import { Token } from 'yaml/dist/parse/cst';
/**
* These documents are collected into a final YAMLDocument
* and passed to the `parseYAML` caller.
*/
export declare class SingleYAMLDocument extends JSONDocument {
private lineCounter;
private _internalDocument;
root: ASTNode;
currentDocIndex: number;
private _lineComments;
constructor(lineCounter?: LineCounter);
/**
* Create a deep copy of this document
*/
clone(): SingleYAMLDocument;
private collectLineComments;
/**
* Updates the internal AST tree of the object
* from the internal node. This is call whenever the
* internalDocument is set but also can be called to
* reflect any changes on the underlying document
* without setting the internalDocument explicitly.
*/
updateFromInternalDocument(): void;
set internalDocument(document: Document);
get internalDocument(): Document;
get lineComments(): string[];
set lineComments(val: string[]);
get errors(): YAMLDocDiagnostic[];
get warnings(): YAMLDocDiagnostic[];
getNodeFromPosition(positionOffset: number, textBuffer: TextBuffer, configuredIndentation?: number): [YamlNode | undefined, boolean];
findClosestNode(offset: number, textBuffer: TextBuffer, configuredIndentation?: number): YamlNode;
private getProperParentByIndentation;
getParent(node: YamlNode): YamlNode | undefined;
}
/**
* Contains the SingleYAMLDocuments, to be passed
* to the `parseYAML` caller.
*/
export declare class YAMLDocument {
documents: SingleYAMLDocument[];
tokens: Token[];
private errors;
private warnings;
constructor(documents: SingleYAMLDocument[], tokens: Token[]);
}
export declare class YamlDocuments {
private cache;
/**
* Get cached YAMLDocument
* @param document TextDocument to parse
* @param parserOptions YAML parserOptions
* @param addRootObject if true and document is empty add empty object {} to force schema usage
* @returns the YAMLDocument
*/
getYamlDocument(document: TextDocument, parserOptions?: ParserOptions, addRootObject?: boolean): YAMLDocument;
/**
* For test purpose only!
*/
clear(): void;
private ensureCache;
}
export declare const yamlDocumentsCache: YamlDocuments;

View File

@@ -0,0 +1,274 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./jsonParser07", "yaml", "./yamlParser07", "vscode-json-languageservice", "./ast-converter", "../utils/arrUtils", "../utils/astUtils", "../utils/strings"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.yamlDocumentsCache = exports.YamlDocuments = exports.YAMLDocument = exports.SingleYAMLDocument = void 0;
const jsonParser07_1 = require("./jsonParser07");
const yaml_1 = require("yaml");
const yamlParser07_1 = require("./yamlParser07");
const vscode_json_languageservice_1 = require("vscode-json-languageservice");
const ast_converter_1 = require("./ast-converter");
const arrUtils_1 = require("../utils/arrUtils");
const astUtils_1 = require("../utils/astUtils");
const strings_1 = require("../utils/strings");
/**
* These documents are collected into a final YAMLDocument
* and passed to the `parseYAML` caller.
*/
class SingleYAMLDocument extends jsonParser07_1.JSONDocument {
constructor(lineCounter) {
super(null, []);
this.lineCounter = lineCounter;
}
/**
* Create a deep copy of this document
*/
clone() {
const copy = new SingleYAMLDocument(this.lineCounter);
copy.isKubernetes = this.isKubernetes;
copy.disableAdditionalProperties = this.disableAdditionalProperties;
copy.uri = this.uri;
copy.currentDocIndex = this.currentDocIndex;
copy._lineComments = this.lineComments.slice();
// this will re-create root node
copy.internalDocument = this._internalDocument.clone();
return copy;
}
collectLineComments() {
this._lineComments = [];
if (this._internalDocument.commentBefore) {
const comments = this._internalDocument.commentBefore.split('\n');
comments.forEach((comment) => this._lineComments.push(`#${comment}`));
}
(0, yaml_1.visit)(this.internalDocument, (_key, node) => {
if (node?.commentBefore) {
const comments = node?.commentBefore.split('\n');
comments.forEach((comment) => this._lineComments.push(`#${comment}`));
}
if (node?.comment) {
this._lineComments.push(`#${node.comment}`);
}
});
if (this._internalDocument.comment) {
this._lineComments.push(`#${this._internalDocument.comment}`);
}
}
/**
* Updates the internal AST tree of the object
* from the internal node. This is call whenever the
* internalDocument is set but also can be called to
* reflect any changes on the underlying document
* without setting the internalDocument explicitly.
*/
updateFromInternalDocument() {
this.root = (0, ast_converter_1.convertAST)(null, this._internalDocument.contents, this._internalDocument, this.lineCounter);
}
set internalDocument(document) {
this._internalDocument = document;
this.updateFromInternalDocument();
}
get internalDocument() {
return this._internalDocument;
}
get lineComments() {
if (!this._lineComments) {
this.collectLineComments();
}
return this._lineComments;
}
set lineComments(val) {
this._lineComments = val;
}
get errors() {
return this.internalDocument.errors.map(YAMLErrorToYamlDocDiagnostics);
}
get warnings() {
return this.internalDocument.warnings.map(YAMLErrorToYamlDocDiagnostics);
}
getNodeFromPosition(positionOffset, textBuffer, configuredIndentation) {
const position = textBuffer.getPosition(positionOffset);
const lineContent = textBuffer.getLineContent(position.line);
if (lineContent.trim().length === 0) {
return [this.findClosestNode(positionOffset, textBuffer, configuredIndentation), true];
}
const textAfterPosition = lineContent.substring(position.character);
const spacesAfterPositionMatch = textAfterPosition.match(/^([ ]+)\n?$/);
const areOnlySpacesAfterPosition = !!spacesAfterPositionMatch;
const countOfSpacesAfterPosition = spacesAfterPositionMatch?.[1].length;
let closestNode;
(0, yaml_1.visit)(this.internalDocument, (key, node) => {
if (!node) {
return;
}
const range = node.range;
if (!range) {
return;
}
const isNullNodeOnTheLine = () => areOnlySpacesAfterPosition &&
positionOffset + countOfSpacesAfterPosition === range[2] &&
(0, yaml_1.isScalar)(node) &&
node.value === null;
if ((range[0] <= positionOffset && range[1] >= positionOffset) || isNullNodeOnTheLine()) {
closestNode = node;
}
else {
return yaml_1.visit.SKIP;
}
});
return [closestNode, false];
}
findClosestNode(offset, textBuffer, configuredIndentation) {
let offsetDiff = this.internalDocument.range[2];
let maxOffset = this.internalDocument.range[0];
let closestNode;
(0, yaml_1.visit)(this.internalDocument, (key, node) => {
if (!node) {
return;
}
const range = node.range;
if (!range) {
return;
}
const diff = range[1] - offset;
if (maxOffset <= range[0] && diff <= 0 && Math.abs(diff) <= offsetDiff) {
offsetDiff = Math.abs(diff);
maxOffset = range[0];
closestNode = node;
}
});
const position = textBuffer.getPosition(offset);
const lineContent = textBuffer.getLineContent(position.line);
const indentation = (0, strings_1.getIndentation)(lineContent, position.character);
if ((0, yaml_1.isScalar)(closestNode) && closestNode.value === null) {
return closestNode;
}
if (indentation === position.character) {
closestNode = this.getProperParentByIndentation(indentation, closestNode, textBuffer, '', configuredIndentation);
}
return closestNode;
}
getProperParentByIndentation(indentation, node, textBuffer, currentLine, configuredIndentation, rootParent) {
if (!node) {
return this.internalDocument.contents;
}
configuredIndentation = !configuredIndentation ? 2 : configuredIndentation;
if ((0, yaml_1.isNode)(node) && node.range) {
const position = textBuffer.getPosition(node.range[0]);
const lineContent = textBuffer.getLineContent(position.line);
currentLine = currentLine === '' ? lineContent.trim() : currentLine;
if (currentLine.startsWith('-') && indentation === configuredIndentation && currentLine === lineContent.trim()) {
position.character += indentation;
}
if (position.character > indentation && position.character > 0) {
const parent = this.getParent(node);
if (parent) {
return this.getProperParentByIndentation(indentation, parent, textBuffer, currentLine, configuredIndentation, rootParent);
}
}
else if (position.character < indentation) {
const parent = this.getParent(node);
if ((0, yaml_1.isPair)(parent) && (0, yaml_1.isNode)(parent.value)) {
return parent.value;
}
else if ((0, yaml_1.isPair)(rootParent) && (0, yaml_1.isNode)(rootParent.value)) {
return rootParent.value;
}
}
else {
return node;
}
}
else if ((0, yaml_1.isPair)(node)) {
rootParent = node;
const parent = this.getParent(node);
return this.getProperParentByIndentation(indentation, parent, textBuffer, currentLine, configuredIndentation, rootParent);
}
return node;
}
getParent(node) {
return (0, astUtils_1.getParent)(this.internalDocument, node);
}
}
exports.SingleYAMLDocument = SingleYAMLDocument;
/**
* Contains the SingleYAMLDocuments, to be passed
* to the `parseYAML` caller.
*/
class YAMLDocument {
constructor(documents, tokens) {
this.documents = documents;
this.tokens = tokens;
this.errors = [];
this.warnings = [];
}
}
exports.YAMLDocument = YAMLDocument;
class YamlDocuments {
constructor() {
// a mapping of URIs to cached documents
this.cache = new Map();
}
/**
* Get cached YAMLDocument
* @param document TextDocument to parse
* @param parserOptions YAML parserOptions
* @param addRootObject if true and document is empty add empty object {} to force schema usage
* @returns the YAMLDocument
*/
getYamlDocument(document, parserOptions, addRootObject = false) {
this.ensureCache(document, parserOptions ?? yamlParser07_1.defaultOptions, addRootObject);
return this.cache.get(document.uri).document;
}
/**
* For test purpose only!
*/
clear() {
this.cache.clear();
}
ensureCache(document, parserOptions, addRootObject) {
const key = document.uri;
if (!this.cache.has(key)) {
this.cache.set(key, { version: -1, document: new YAMLDocument([], []), parserOptions: yamlParser07_1.defaultOptions });
}
const cacheEntry = this.cache.get(key);
if (cacheEntry.version !== document.version ||
(parserOptions.customTags && !(0, arrUtils_1.isArrayEqual)(cacheEntry.parserOptions.customTags, parserOptions.customTags))) {
let text = document.getText();
// if text is contains only whitespace wrap all text in object to force schema selection
if (addRootObject && !/\S/.test(text)) {
text = `{${text}}`;
}
const doc = (0, yamlParser07_1.parse)(text, parserOptions, document);
cacheEntry.document = doc;
cacheEntry.version = document.version;
cacheEntry.parserOptions = parserOptions;
}
}
}
exports.YamlDocuments = YamlDocuments;
exports.yamlDocumentsCache = new YamlDocuments();
function YAMLErrorToYamlDocDiagnostics(error) {
return {
message: error.message,
location: {
start: error.pos[0],
end: error.pos[1],
toLineEnd: true,
},
severity: 1,
code: vscode_json_languageservice_1.ErrorCode.Undefined,
};
}
});
//# sourceMappingURL=yaml-documents.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
import { YAMLDocument, SingleYAMLDocument } from './yaml-documents';
import { TextDocument } from 'vscode-languageserver-textdocument';
export { YAMLDocument, SingleYAMLDocument };
export declare type YamlVersion = '1.1' | '1.2';
export interface ParserOptions {
customTags: string[];
yamlVersion: YamlVersion;
}
export declare const defaultOptions: ParserOptions;
/**
* `yaml-ast-parser-custom-tags` parses the AST and
* returns YAML AST nodes, which are then formatted
* for consumption via the language server.
*/
export declare function parse(text: string, parserOptions?: ParserOptions, document?: TextDocument): YAMLDocument;

View File

@@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Copyright (c) Adam Voss. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "yaml", "./yaml-documents", "./custom-tag-provider", "../utils/textBuffer"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = exports.defaultOptions = exports.SingleYAMLDocument = exports.YAMLDocument = void 0;
const yaml_1 = require("yaml");
const yaml_documents_1 = require("./yaml-documents");
Object.defineProperty(exports, "YAMLDocument", { enumerable: true, get: function () { return yaml_documents_1.YAMLDocument; } });
Object.defineProperty(exports, "SingleYAMLDocument", { enumerable: true, get: function () { return yaml_documents_1.SingleYAMLDocument; } });
const custom_tag_provider_1 = require("./custom-tag-provider");
const textBuffer_1 = require("../utils/textBuffer");
exports.defaultOptions = {
customTags: [],
yamlVersion: '1.2',
};
/**
* `yaml-ast-parser-custom-tags` parses the AST and
* returns YAML AST nodes, which are then formatted
* for consumption via the language server.
*/
function parse(text, parserOptions = exports.defaultOptions, document) {
const options = {
strict: false,
customTags: (0, custom_tag_provider_1.getCustomTags)(parserOptions.customTags),
version: parserOptions.yamlVersion ?? exports.defaultOptions.yamlVersion,
keepSourceTokens: true,
};
const composer = new yaml_1.Composer(options);
const lineCounter = new yaml_1.LineCounter();
let isLastLineEmpty = false;
if (document) {
const textBuffer = new textBuffer_1.TextBuffer(document);
const position = textBuffer.getPosition(text.length);
const lineContent = textBuffer.getLineContent(position.line);
isLastLineEmpty = lineContent.trim().length === 0;
}
const parser = isLastLineEmpty ? new yaml_1.Parser() : new yaml_1.Parser(lineCounter.addNewLine);
const tokens = parser.parse(text);
const tokensArr = Array.from(tokens);
const docs = composer.compose(tokensArr, true, text.length);
// Generate the SingleYAMLDocs from the AST nodes
const yamlDocs = Array.from(docs, (doc) => parsedDocToSingleYAMLDocument(doc, lineCounter));
// Consolidate the SingleYAMLDocs
return new yaml_documents_1.YAMLDocument(yamlDocs, tokensArr);
}
exports.parse = parse;
function parsedDocToSingleYAMLDocument(parsedDoc, lineCounter) {
const syd = new yaml_documents_1.SingleYAMLDocument(lineCounter);
syd.internalDocument = parsedDoc;
return syd;
}
});
//# sourceMappingURL=yamlParser07.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"yamlParser07.js","sourceRoot":"","sources":["../../../../src/languageservice/parser/yamlParser07.ts"],"names":[],"mappings":"AAAA;;;;gGAIgG;;;;;;;;;;;;;IAEhG,+BAA6G;IAC7G,qDAAoE;IAK3D,6FALA,6BAAY,OAKA;IAAE,mGALA,mCAAkB,OAKA;IAJzC,+DAAsD;IAEtD,oDAAiD;IASpC,QAAA,cAAc,GAAkB;QAC3C,UAAU,EAAE,EAAE;QACd,WAAW,EAAE,KAAK;KACnB,CAAC;IACF;;;;OAIG;IACH,SAAgB,KAAK,CAAC,IAAY,EAAE,gBAA+B,sBAAc,EAAE,QAAuB;QACxG,MAAM,OAAO,GAAmD;YAC9D,MAAM,EAAE,KAAK;YACb,UAA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