You can get the rule index prior to calling `getSemanticContextDisplayString` via the following expression:

```java
previewState.parsingResult.parser.getATN().decisionToState.get(pred.decision).ruleIndex
```