Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function completionHelper(document: TextDocument, textDocumentPosition: Position): CompletionAdjustment {
// Get the string we are looking at via a substring
const lineNumber: number = textDocumentPosition.line;
const lineOffsets: number[] = getLineOffsets(document.getText());
const start: number = lineOffsets[lineNumber]; // Start of where the autocompletion is happening
let end = 0; // End of where the autocompletion is happening
if (lineOffsets[lineNumber + 1] !== undefined) {
end = lineOffsets[lineNumber + 1];
} else {
end = document.getText().length;
}
while (end - 1 >= start && is_EOL(document.getText().charCodeAt(end - 1))) {
end--;
}
const textLine = document.getText().substring(start, end);
// Check if the string we are looking at is a node
private findAutoCompletionProperty = (document: TextDocument, textDocumentPosition: Position, properties: { [provider: string]: string[] }): string => {
let currentLine = textDocumentPosition.line;
while (currentLine >= 0) {
const lineOffsets: number[] = getLineOffsets(document.getText());
const start: number = lineOffsets[currentLine];
var end = 0;
if (lineOffsets[currentLine + 1] !== undefined) {
end = lineOffsets[currentLine + 1];
} else {
end = document.getText().length;
}
let thisLine = document.getText().substring(start, end);
let isOtherItemInList = thisLine.match(/-\s*([-\w]+)?(\.)?([-\w]+?)?\s*$/);
if (isOtherItemInList) {
currentLine--;
continue;
}
for (var key in properties) {
if (properties[key].some(propertyName => new RegExp(`(.*)${propertyName}(:)([\s]*)([\w]*)(\s*)`).test(thisLine))) {