private Set<QueryHelpType> getHelpTypes(final TokenType lastKeyword,
                                            final List<TokenType> lastKeywordSequence,
                                            final boolean includeStructure) {
        // Easier to include structure even if we know it is not required, then remove later
        final int count = lastKeywordSequence.size();
        final Set<QueryHelpType> queryHelpTypes;
        if (count == 1) {
            queryHelpTypes = EnumSet.of(QueryHelpType.STRUCTURE);
        } else {
            queryHelpTypes = switch (lastKeyword) {
                case FROM -> count >= 4
                        // 'from xxx '
                        ? EnumSet.of(QueryHelpType.STRUCTURE)
                        : QueryHelpType.NO_TYPES;
                case WHERE -> count > 2
                        ? EnumSet.of(QueryHelpType.QUERYABLE_FIELD, QueryHelpType.FUNCTION, QueryHelpType.STRUCTURE)
                        : EnumSet.of(QueryHelpType.QUERYABLE_FIELD);
                case LIMIT -> count > 3
                        // LIMIT only allows numbers/strings
                        ? EnumSet.of(QueryHelpType.STRUCTURE)
                        : QueryHelpType.NO_TYPES;
                case EVAL -> { // 'eval x = z'
                    if (TokenType.haveSeen(
                            lastKeywordSequence,
                            true,
                            TokenType.EQUALS, TokenType.WHITESPACE)) {
                        yield count > 7
                                ? EnumSet.of(QueryHelpType.FIELD, QueryHelpType.FUNCTION, QueryHelpType.STRUCTURE)
                                : EnumSet.of(QueryHelpType.FIELD, QueryHelpType.FUNCTION);
                    } else {
                        yield QueryHelpType.NO_TYPES;
                    }
                }
                case GROUP, SORT -> count > 4
                        // 'GROUP BY '
                        ? EnumSet.of(QueryHelpType.FIELD, QueryHelpType.STRUCTURE)
                        : EnumSet.of(QueryHelpType.STRUCTURE);
                case SHOW -> count > 3
                        ? EnumSet.of(QueryHelpType.FIELD)
                        : EnumSet.of(QueryHelpType.VISUALISATION);
                default -> {
                    if (count >= 4) {
                        // 'select x '
                        yield EnumSet.of(QueryHelpType.FIELD, QueryHelpType.FUNCTION, QueryHelpType.STRUCTURE);
                    } else if (count >= 2) {
                        // 'select ' or 'select xxx'
                        yield EnumSet.of(QueryHelpType.FIELD, QueryHelpType.FUNCTION);
                    } else {
                        yield QueryHelpType.NO_TYPES;
                    }
                }
            };
        }

        // Need to remove structure in various instances
        if (queryHelpTypes.contains(QueryHelpType.STRUCTURE)) {
            final TokenType lastToken = lastKeywordSequence.getLast();
            boolean doRemove = false;
            if (!includeStructure) {
                // Structure is not valid here,
                doRemove = true;
            } else if (lastToken == TokenType.COMMENT || lastToken == TokenType.BLOCK_COMMENT) {
                doRemove = true;
            } else if (lastToken == TokenType.COMMA
                       || TokenType.haveSeenLast(lastKeywordSequence, TokenType.COMMA, TokenType.WHITESPACE)) {
                doRemove = true;
            } else if (TokenType.ALL_CONDITIONS.contains(lastToken)) {
                doRemove = true;
            } else if (TokenType.ALL_BODMAS.contains(lastToken)) {
                doRemove = true;
            } else if (lastToken == TokenType.OPEN_BRACKET) {
                doRemove = true;
            }

            if (doRemove) {
                final EnumSet<QueryHelpType> copy = EnumSet.copyOf(queryHelpTypes);
                copy.remove(QueryHelpType.STRUCTURE);
                return copy;
            } else {
                return queryHelpTypes;
            }
        } else {
            return queryHelpTypes;
        }
    }
Here to help testing, so we don't have to work out the row/col postitions
stroom-query/stroom-query-impl/src/main/java/stroom/query/impl/QueryServiceImpl.java