Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. line numbers + editing query consuming more than screen space
  2. autopairing[6] for single quote, sql identifier quote, square and round brackets could be turn on/off via property
    (requires update at least till 3.13.3) 
  3. Enabling/Disabling description for completion candidates via property. An example how it looks like is here [7]

Implementation Details

The main idea is to extend existing org.apache.flink.table.client.cli.SqlMultiLineParser . => No need to use Flink SQL parser
It should check the input if all quotes, comments, hints, brackets (square and round) are closed otherwise it throws new EOFError  - normal behavior in jline in case input should be continued on a new line.
During need to keep track of cursor states if it is a comment, keyword, quoted string.
Also during this parse it is required to split input into words and pass these words further to jline according to contract. (Jline will use these words also to evaluate completion candidates)
This track could be used to answer a question at what state parser by the end of a query.
Also such track, if there is recorded state for every cursor position, could be used to do highlighting.

To do highlighting it is necessary to implement  org.jline.reader.impl.DefaultHighlighter.
From parser it could receive a track of state for each position and do highlighting.
Colors for different states are going to be defined in a separate SyntaxHighlightStyle class.

Code Block
java
java
private final AttributedStyle blockCommentStyle;
    private final AttributedStyle lineCommentStyle;
    private final AttributedStyle hintStyle;
    private final AttributedStyle defaultStyle;
    private final AttributedStyle keywordStyle;
    private final AttributedStyle numberStyle;
    private final AttributedStyle singleQuotedStyle;
    private final AttributedStyle sqlIdentifierStyle;

    public SyntaxHighlightStyle(
            AttributedStyle blockCommentStyle,
            AttributedStyle lineCommentStyle,
            AttributedStyle hintStyle,
            AttributedStyle defaultStyle,
            AttributedStyle keywordStyle,
            AttributedStyle singleQuotedStyle,
            AttributedStyle sqlIdentifierStyle) {
        this.blockCommentStyle = blockCommentStyle;
        this.lineCommentStyle = lineCommentStyle;
        this.hintStyle = hintStyle;
        this.defaultStyle = defaultStyle;
        this.keywordStyle = keywordStyle;
        this.singleQuotedStyle = singleQuotedStyle;
        this.sqlIdentifierStyle = sqlIdentifierStyle;
    }


At the same time there could be enum of this styles and that will allow to add more styles for highlighting e.g.

Code Block
java
java
public enum BuiltInStyle {
        DEFAULT(null, null, null, null, null, null, null, null),
        DARK(BOLD_BLUE, WHITE, ITALIC_GREEN, ITALIC_GREEN, BOLD_GREEN, YELLOW, RED, MAGENTA),
        LIGHT(BOLD_RED, WHITE, ITALIC_CYAN, ITALIC_CYAN, BOLD_CYAN, YELLOW, GREEN, MAGENTA);
        private final SyntaxHighlightStyle style;

        BuiltInStyle(
                AttributedStyle keywordStyle,
                AttributedStyle defaultStyle,
                AttributedStyle blockCommentStyle,
                AttributedStyle lineCommentStyle,
                AttributedStyle hintStyle,
                AttributedStyle numberStyle,
                AttributedStyle singleQuotedStyle,
                AttributedStyle sqlIdentifierStyle) {
            style =
                    new SyntaxHighlightStyle(
                            blockCommentStyle,
                            lineCommentStyle,
                            hintStyle,
                            defaultStyle,
                            keywordStyle,
                            numberStyle,
                            singleQuotedStyle,
                            sqlIdentifierStyle);
        }

Summary

After this FLIP finishes, the sql client will have the options.

...