Autocomplete for boolean values?

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

There’s no boolean value in the code you’re showing. There’s no reason to assume the identifier isBoolean is being treated differently than other identifier.

Your code may work better if you pass -1 as second argument to cursorAt, so that you get the node before the cursor, rather than the node around it.

There’s no boolean value in the code you’re showing.

You’re right.

There is no boolean, but it will be here

{
  "someProp": {
    "isBoolean": true
  }
}

For other usecases, we mostly have strings so there it works fine.

E.g.

{
  "someProp": {
    "someProp": "|" <--- let's say cursor is here between ""
  }
}

in this case if the code above runs, it will properly reach "someProp" first because it will be treated as child of type PropertyName.

So I suspect it could also be that if there is nothing after : yet, the node on the left of : is not treated like PropertyName and is instead just part of a bigger node of type Object. But I couldn’t find a way to confirm it yet