Given a json like this
{
"someProp": {
"isBoolean": | <--- cursor
}
}
is there any way to make it treat the json above properly and be able to get isBoolean as PropertyName?
I need to build an array with properties names up to cursor. So in this case it hsould be [‘someProp’, ‘isBoolean’]
I am using
import { autocompletion, startCompletion } from '@codemirror/autocomplete';
and the logic to get the path is like this
const tree = syntaxTree(context.state);
const cursor = tree.cursorAt(context.pos);
const pathToPropertyName: (string | number)[] = [];
while (cursor.parent()) {
if (cursor.name === 'Property') {
const keyNode = cursor.node.getChild('PropertyName');
if (keyNode) {
const matchingPropertyName = context.state.sliceDoc(keyNode.from, keyNode.to).replace(/"/g, '');
pathToPropertyName.unshift(matchingPropertyName);
}
}
}
The problem is that it doesn’t work for boolean values. It doesn’t seem to treat isBoolean as PropertyName