Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function hintList(editor, options, cursor, token, list) {
var hints = filterAndSortList(list, normalizeText(token.string));
if (!hints) {
return;
}
var tokenStart = token.type === null ? token.end :
/\w/.test(token.string[0]) ? token.start :
token.start + 1;
var results = {
list: hints,
from: CodeMirror.Pos(cursor.line, tokenStart),
to: CodeMirror.Pos(cursor.line, token.end),
};
// GraphiQL displays the custom typeahead which appends information to the
// end of the UI.
if (options.displayInfo) {
var wrapper;
var information;
// When a hint result is selected, we touch the UI.
CodeMirror.on(results, 'select', (ctx, el) => {
// Only the first time (usually when the hint UI is first displayed)
// do we create the wrapping node.
if (!wrapper) {
// Wrap the existing hint UI, so we have a place to put information.
var hintsUl = el.parentNode;
var container = hintsUl.parentNode;
CodeMirror.registerHelper('lint', 'yaml', text => {
const found = [];
try {
safeLoad(text);
} catch (e) {
const loc = e.mark;
found.push({
from: CodeMirror.Pos(loc.line, loc.column),
to: CodeMirror.Pos(loc.line, loc.column),
message: e.message
});
}
return found;
});
this.cm.operation(() => {
let lastLine = doc.lastLine();
let pos = CodeMirror.Pos(lastLine + 1, 0);
if(doc.getLine(lastLine) !== "") {
let cursor = doc.getCursor();
doc.replaceRange("\n", pos, pos, "+normalize");
doc.setCursor(cursor);
}
});
parser.parseError = function(str, hash) {
var loc = hash.loc;
found.push({
from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
message: str
});
};
try {
function getHints(cm) {
let cursor = cm.getCursor();
let start = cursor.ch, end = cursor.ch;
return {
list: [ "command", "block", "wait", "trigger" ],
from: CodeMirror.Pos(cursor.line, start),
to: CodeMirror.Pos(cursor.line, end)
};
}
function getPos (error, from) {
let line = error.line - 2
let ch = (from ? error.column : error.column + 1) - 2
if (error.node && error.node.loc) {
line = (from ? error.node.loc.start.line - 1 : error.node.loc.end.line - 1) - 1
ch = (from ? error.node.loc.start.column : error.node.loc.end.column) - 2
}
return CodeMirror.Pos(line, ch)
}
function getLocation(source, position) {
var line = 0;
var column = position;
var lineRegexp = /\r\n|[\n\r]/g;
var match;
while ((match = lineRegexp.exec(source)) && match.index < position) {
line += 1;
column = position - (match.index + match[0].length);
}
return CodeMirror.Pos(line, column);
}
function collapseSingle(cm: CodeMirror.Editor, from: number, to: number): {mark: CodeMirror.TextMarker, clear: () => void} {
cm.addLineClass(from, 'wrap', 'CodeMirror-merge-collapsed-line');
let widget = document.createElement('span');
widget.className = 'CodeMirror-merge-collapsed-widget';
widget.title = 'Identical text collapsed. Click to expand.';
let mark = cm.getDoc().markText(
CodeMirror.Pos(from, 0), CodeMirror.Pos(to - 1),
{
inclusiveLeft: true,
inclusiveRight: true,
replacedWith: widget,
clearOnEnter: true
}
);
function clear() {
mark.clear();
cm.removeLineClass(from, 'wrap', 'CodeMirror-merge-collapsed-line');
}
CodeMirror.on(widget, 'click', clear);
return {mark: mark, clear: clear};
}
function collapseSingle(cm: CodeMirror.Editor, from: number, to: number): {mark: CodeMirror.TextMarker, clear: () => void} {
cm.addLineClass(from, 'wrap', 'CodeMirror-merge-collapsed-line');
let widget = document.createElement('span');
widget.className = 'CodeMirror-merge-collapsed-widget';
widget.title = 'Identical text collapsed. Click to expand.';
let mark = cm.getDoc().markText(
CodeMirror.Pos(from, 0), CodeMirror.Pos(to - 1),
{
inclusiveLeft: true,
inclusiveRight: true,
replacedWith: widget,
clearOnEnter: true
}
);
function clear() {
mark.clear();
cm.removeLineClass(from, 'wrap', 'CodeMirror-merge-collapsed-line');
}
CodeMirror.on(widget, 'click', clear);
return {mark: mark, clear: clear};
}
try {
const parser: FreemarkerParser = new FreemarkerParser();
const result: any = parser.parse(text);
if (result.ast && result.ast.errors) {
for (const error of result.ast.errors) {
const startLine =
error.loc.start.line > 0 ? error.loc.start.line - 1 : 0;
const startCol =
error.loc.start.column > 0 ? error.loc.start.column - 1 : 0;
const endLine = error.loc.end.line > 0 ? error.loc.end.line - 1 : 0;
const endCol =
error.loc.end.column > 0 ? error.loc.end.column - 1 : 0;
errors.push({
from: CodeMirror.Pos(startLine, startCol),
message: error.message,
severity: 'error',
to: CodeMirror.Pos(endLine, endCol),
});
}
}
let totalSymbols = 0;
for (const token of result.tokens) {
if (token.type === 'Interpolation') {
totalSymbols++;
}
}
if (totalSymbols === 0) {
const msg = 'linter-no-symbols';