Access node groups during code analysis for autocompletion

I have a custom grammar for a language that is a subset of Ruby, for which I have defined a group called Expression:

expression[@isGroup=Expression] {
  Number |
  String |
  VariableName |
  @specialize[@name=BooleanLiteral]<identifier, "true" | "false"> |
  ArrayExpression { "[" commaSep<expression> "]" } |
  UnaryExpression |
  ParenthesizedExpression |
  BinaryExpression |

  CallExpression {
    FunctionName !call ArgList
  }
}

Now I’m building an autocompletion provider for this language and I want to be able to autocomplete operators. This means detecting when the cursor is outside of a VariableName and is preceded by an Expression:

const tree = syntaxTree(context.state);
const inner = tree.resolveInner(context.pos, -1);

const isWord =
  inner.name === "VariableName" ||
  (inner.to - inner.from < 20 &&
    Identifier.test(context.state.sliceDoc(inner.from, inner.to)));

const treeCursor = tree.cursorAt(context.pos, -1);
const isOperator =
  // Pseudo-code, doesn't work
  inner.name === "Program" && treeCursor.prev() && treeCursor.type.props.includes("Expression");

I found a GitHub issue that was probably the closest to what I want to accomplish, but the OP had a different use case, and I don’t think I can apply their solution: Question: How to query "syntax tags" for a given Node/NodeType? · Issue #29 · lezer-parser/lezer · GitHub.

How can I tell whether a node is an expression during code analysis?

With that @isGroup, node.is("Expression") should work.

Yes, thanks, that’s it! I missed that method. One correction though — this method is on NodeType, so the check should be node.type.is("Expression").