How to use the jsonc-parser.visit function in jsonc-parser

To help you get started, we’ve selected a few jsonc-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / vscode / extensions / vscode-colorize-tests / src / colorizerTestMain.ts View on Github external
if (tokenType === -1) {
						tokenType = 0;
					}

					let tokenModifiers = 0;
					for (let i = 0; i < modifiers.length; i++) {
						const index = legend.tokenModifiers.indexOf(modifiers[i]);
						if (index !== -1) {
							tokenModifiers = tokenModifiers | 1 << index;
						}
					}

					builder.push(startLine, startCharacter, length, tokenType, tokenModifiers);
				}
			};
			jsoncParser.visit(document.getText(), visitor);

			return new vscode.SemanticTokens(builder.build());
		}
	};
github eclipse-theia / theia / packages / debug / src / browser / debug-monaco-contribution.ts View on Github external
}
        const children: monaco.languages.DocumentSymbol[] = [];
        const result: monaco.languages.DocumentSymbol = {
            name: 'Launch Configurations',
            detail: '',
            kind: monaco.languages.SymbolKind.Object,
            range: new monaco.Range(0, 0, 0, 0),
            selectionRange: new monaco.Range(0, 0, 0, 0),
            children
        };
        let name: string = '';
        let lastProperty = '';
        let startOffset = 0;
        let depthInObjects = 0;

        visit(model.getValue(), {
            onObjectProperty: (property, _offset, _length) => {
                lastProperty = property;
            },
            onLiteralValue: (value: any, _offset: number, _length: number) => {
                if (lastProperty === 'name') {
                    name = value;
                }
            },
            onObjectBegin: (offset: number, _length: number) => {
                depthInObjects++;
                if (depthInObjects === 2) {
                    startOffset = offset;
                }
            },
            onObjectEnd: (offset: number, _length: number) => {
                if (name && depthInObjects === 2) {
github eclipse-theia / theia / packages / debug / src / browser / debug-configuration-manager.ts View on Github external
async addConfiguration(): Promise {
        const { model } = this;
        if (!model) {
            return;
        }
        const widget = await this.doOpen(model);
        if (!(widget.editor instanceof MonacoEditor)) {
            return;
        }
        const editor = widget.editor.getControl();
        const { commandService } = widget.editor;
        let position: monaco.Position | undefined;
        let depthInArray = 0;
        let lastProperty = '';
        visit(editor.getValue(), {
            onObjectProperty: property => {
                lastProperty = property;
            },
            onArrayBegin: offset => {
                if (lastProperty === 'configurations' && depthInArray === 0) {
                    position = editor.getModel()!.getPositionAt(offset + 1);
                }
                depthInArray++;
            },
            onArrayEnd: () => {
                depthInArray--;
            }
        });
        if (!position) {
            return;
        }