Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(contents, row, col) {
this.ast = loadYaml(contents)
let lines = this.lines = contents.split(/\n/g, -1)
this._index = {
range: new IntervalTree(),
nodePos: [],
nodePath: {},
posToRow: [],
}
// create index of pos to row,col
let pos = 0
for (let s = 0, len=lines.length; s < len; ++s) {
this._index.posToRow.push([pos, lines[s].length])
pos += lines[s].length + 1
}
this.visit(this.ast)
var offset = positionOffset || 0;
lineColumnFinder = lineColumnFinder || lineColumn(inYaml);
if (!inYaml) {
return [noDocError(inYaml)];
}
var root;
try {
root = yaml.safeLoad(inYaml);
}
catch (err) {
return [loadYamlError(err, inYaml, lineColumnFinder, offset)];
}
if (!root) {
return [noDocError(inYaml)];
}
var yamlAST = ast.safeLoad(inYaml, null);
if (_.isEmpty(rules)) {
return [];
}
var ruleTriggers = [];
_.forEach(rules, function (rule) {
var result = rule.test.test(root);
if (result.matched) {
var positions = _.flatMap(result.paths, function (path) { return ast_1.astPosition(yamlAST, path, lineColumnFinder, offset); });
if (_.isEmpty(positions)) {
var shorterPaths = _.map(result.paths, function (p) { return p.split(".").slice(0, -1).join("."); });
positions = _.flatMap(shorterPaths, function (path) { return ast_1.astPosition(yamlAST, path, lineColumnFinder, offset); });
}
ruleTriggers.push({
type: rule.type,
rule: rule.name,
received: _.map(result.paths, function (p) { return _.get(root, p); })[0],
function parseDoc(cm) {
const doc = cm.getDoc();
const content = doc.getValue();
doc.yamlNodes = findAnchorRefParents(YAML.safeLoad(content));
}
async provideDocumentSymbolsImpl(document: vscode.TextDocument, _token: vscode.CancellationToken): Promise {
const fakeText = document.getText().replace(/{{[^}]*}}/g, (s) => encodeWithTemplateMarkers(s));
const root = yp.safeLoad(fakeText);
const syms: vscode.SymbolInformation[] = [];
walk(root, '', document, document.uri, syms);
return syms;
}
}
export function ParseToAst(rawYaml: string): YAMLNode {
return yamlAst.safeLoad(rawYaml, null) as YAMLNode;
}
async provideDocumentSymbolsImpl(document: vscode.TextDocument, _token: vscode.CancellationToken): Promise {
const fakeText1 = document.getText();
const fakeText2 = substituteStatements(fakeText1);
const fakeText3 = substituteExpressions(fakeText2);
const root = yp.safeLoad(fakeText3);
const syms: vscode.SymbolInformation[] = [];
walk(root, '', document, document.uri, syms);
return syms;
}
}
createMarkers = (fileToView) => {
if (this.aceEditorBase) {
let markers = [];
const loadedAst = ast.safeLoad(fileToView.baseContent, null);
this.createMarkersRec(loadedAst, [], markers);
return markers;
}
}