Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// range without ", [ or {
const cStart = node.offset + 1, cEnd = node.offset + node.length - 1;
if (cStart < cEnd && offset >= cStart && offset <= cEnd) {
result.push(newRange(cStart, cEnd));
}
result.push(newRange(node.offset, node.offset + node.length));
break;
case 'number':
case 'boolean':
case 'null':
case 'property':
result.push(newRange(node.offset, node.offset + node.length));
break;
}
if (node.type === 'property' || node.parent && node.parent.type === 'array') {
const afterCommaOffset = getOffsetAfterNextToken(node.offset + node.length, SyntaxKind.CommaToken);
if (afterCommaOffset !== -1) {
result.push(newRange(node.offset, afterCommaOffset));
}
}
node = node.parent;
}
let current: SelectionRange | undefined = undefined;
for (let index = result.length - 1; index >= 0; index--) {
current = SelectionRange.create(result[index], current);
}
if (!current) {
current = SelectionRange.create(Range.create(position, position));
}
return current;
}
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 {
import { createScanner, SyntaxKind } from 'jsonc-parser';
import * as os from 'os';
import { window } from 'vscode';
import { MimeUtility } from './mimeUtility';
import { isJSONString } from './misc';
const pd = require('pretty-data').pd;
export class ResponseFormatUtility {
private static readonly jsonSpecialTokenMapping = {
[SyntaxKind.OpenBraceToken]: '{',
[SyntaxKind.CloseBraceToken]: '}',
[SyntaxKind.OpenBracketToken]: '[',
[SyntaxKind.CloseBracketToken]: ']',
[SyntaxKind.ColonToken]: ':',
[SyntaxKind.CommaToken]: ',',
[SyntaxKind.NullKeyword]: 'null',
[SyntaxKind.TrueKeyword]: 'true',
[SyntaxKind.FalseKeyword]: 'false'
};
public static formatBody(body: string, contentType: string | undefined, suppressValidation: boolean): string {
if (contentType) {
if (MimeUtility.isJSON(contentType)) {
if (isJSONString(body)) {
body = ResponseFormatUtility.jsonPrettify(body);
} else if (!suppressValidation) {
window.showWarningMessage('The content type of response is application/json, while response body is not a valid json string');
}
} else if (MimeUtility.isXml(contentType)) {
body = pd.xml(body);
} else if (MimeUtility.isCSS(contentType)) {