public Interval runWithResult() {
                if (viewer.getDocument() == null) {
                    return null;
                }
                IDocument doc = viewer.getDocument();

                int stepsToKeep = 2;
                int startOffset = viewer.getTopIndexStartOffset();

                int firstVisibleLine = 0;
                try {
                    firstVisibleLine = doc.getLineOfOffset(startOffset);
                    int visibleLinesCount = viewer.getTextWidget().getSize().y / viewer.getTextWidget().getLineHeight();
                    int rangeStart = doc.getLineOffset(Math.max(0, firstVisibleLine - visibleLinesCount * stepsToKeep));
                    int rangeEnd = doc.getLineOffset(Math.min(doc.getNumberOfLines(), firstVisibleLine + visibleLinesCount * (stepsToKeep + 1)));
                    return new Interval(rangeStart, rangeEnd);
                } catch (BadLocationException e) {
                    int endOffset = viewer.getBottomIndexEndOffset();
                    return new Interval(startOffset, endOffset);
                }
            }
Prepare completion context for the specified position in the text
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/semantics/SQLBackgroundParsingJob.java