Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const offset = scanner.getTokenOffset();
const length = scanner.getTokenLength();
const value = text.substr(offset, length);
return [ token, value ];
}
let [firstToken, firstTokenValue] = scanNext();
let secondToken: SyntaxKind;
let secondTokenValue: string;
let result = '';
while (firstToken !== SyntaxKind.EOF) {
[secondToken, secondTokenValue] = scanNext();
switch (firstToken) {
case SyntaxKind.OpenBraceToken:
result += ResponseFormatUtility.jsonSpecialTokenMapping[firstToken];
if (secondToken !== SyntaxKind.CloseBraceToken) {
indentLevel++;
result += newLineAndIndent();
}
break;
case SyntaxKind.OpenBracketToken:
result += ResponseFormatUtility.jsonSpecialTokenMapping[firstToken];
if (secondToken !== SyntaxKind.CloseBracketToken) {
indentLevel++;
result += newLineAndIndent();
}
break;
case SyntaxKind.CloseBraceToken:
case SyntaxKind.CloseBracketToken:
case SyntaxKind.NullKeyword:
let stack: FoldingRange[] = [];
let prevStart = -1;
let scanner = createScanner(document.getText(), false);
let token = scanner.scan();
function addRange(range: FoldingRange) {
ranges.push(range);
nestingLevels.push(stack.length);
}
while (token !== SyntaxKind.EOF) {
switch (token) {
case SyntaxKind.OpenBraceToken:
case SyntaxKind.OpenBracketToken: {
let startLine = document.positionAt(scanner.getTokenOffset()).line;
let range = { startLine, endLine: startLine, kind: token === SyntaxKind.OpenBraceToken ? 'object' : 'array' };
stack.push(range);
break;
}
case SyntaxKind.CloseBraceToken:
case SyntaxKind.CloseBracketToken: {
let kind = token === SyntaxKind.CloseBraceToken ? 'object' : 'array';
if (stack.length > 0 && stack[stack.length - 1].kind === kind) {
let range = stack.pop();
let line = document.positionAt(scanner.getTokenOffset()).line;
if (range && line > range.startLine + 1 && prevStart !== range.startLine) {
range.endLine = line - 1;
addRange(range);
prevStart = range.startLine;
}
}
break;
public getCursorPositionInConfigurationsArray(document: TextDocument, position: Position): PositionOfCursor | undefined {
if (this.isConfigurationArrayEmpty(document)) {
return 'InsideEmptyArray';
}
const scanner = createScanner(document.getText(), true);
scanner.setPosition(document.offsetAt(position));
const nextToken = scanner.scan();
if (nextToken === SyntaxKind.CommaToken || nextToken === SyntaxKind.CloseBracketToken) {
return 'AfterItem';
}
if (nextToken === SyntaxKind.OpenBraceToken) {
return 'BeforeItem';
}
}
public isConfigurationArrayEmpty(document: TextDocument): boolean {