Search in sources :

Example 1 with SQLPartitionScanner

use of org.jkiss.dbeaver.ui.editors.sql.syntax.SQLPartitionScanner in project dbeaver by serge-rider.

the class SQLEditorBase method reloadSyntaxRules.

public void reloadSyntaxRules() {
    // Refresh syntax
    SQLDialect dialect = getSQLDialect();
    IDocument document = getDocument();
    syntaxManager.init(dialect, getActivePreferenceStore());
    SQLRuleManager ruleManager = new SQLRuleManager(syntaxManager);
    ruleManager.loadRules(getDataSource(), SQLEditorBase.isBigScript(getEditorInput()));
    ruleScanner.refreshRules(getDataSource(), ruleManager);
    parserContext = new SQLParserContext(SQLEditorBase.this, syntaxManager, ruleManager, document != null ? document : new Document());
    if (document instanceof IDocumentExtension3) {
        IDocumentPartitioner partitioner = new FastPartitioner(new SQLPartitionScanner(getDataSource(), dialect), SQLParserPartitions.SQL_CONTENT_TYPES);
        partitioner.connect(document);
        try {
            ((IDocumentExtension3) document).setDocumentPartitioner(SQLParserPartitions.SQL_PARTITIONING, partitioner);
        } catch (Throwable e) {
            // $NON-NLS-1$
            log.warn("Error setting SQL partitioner", e);
        }
        ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
        if (projectionViewer != null && projectionViewer.getAnnotationModel() != null && document.getLength() > 0) {
            // projectionViewer.getTextWidget().redraw();
            try {
                projectionViewer.reinitializeProjection();
            } catch (Throwable ex) {
                // We can catch OutOfMemory here for too big/complex documents
                // $NON-NLS-1$
                log.warn("Can't initialize SQL syntax projection", ex);
            }
        }
    }
    final IVerticalRuler verticalRuler = getVerticalRuler();
    // Update configuration
    if (getSourceViewerConfiguration() instanceof SQLEditorSourceViewerConfiguration) {
        ((SQLEditorSourceViewerConfiguration) getSourceViewerConfiguration()).onDataSourceChange();
    }
    if (verticalRuler != null) {
        verticalRuler.update();
    }
}
Also used : SQLRuleManager(org.jkiss.dbeaver.model.sql.parser.SQLRuleManager) BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) SQLPartitionScanner(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLPartitionScanner) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) SQLParserContext(org.jkiss.dbeaver.model.sql.parser.SQLParserContext)

Example 2 with SQLPartitionScanner

use of org.jkiss.dbeaver.ui.editors.sql.syntax.SQLPartitionScanner in project dbeaver by dbeaver.

the class SQLEditorBase method reloadSyntaxRules.

public void reloadSyntaxRules() {
    // Refresh syntax
    SQLDialect dialect = getSQLDialect();
    syntaxManager.init(dialect, getActivePreferenceStore());
    ruleManager.refreshRules(getDataSource(), getEditorInput());
    Document document = getDocument();
    if (document != null) {
        IDocumentPartitioner partitioner = new FastPartitioner(new SQLPartitionScanner(dialect), SQLPartitionScanner.SQL_CONTENT_TYPES);
        partitioner.connect(document);
        try {
            document.setDocumentPartitioner(SQLPartitionScanner.SQL_PARTITIONING, partitioner);
        } catch (Throwable e) {
            // $NON-NLS-1$
            log.warn("Error setting SQL partitioner", e);
        }
        ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
        if (projectionViewer != null && projectionViewer.getAnnotationModel() != null && document.getLength() > 0) {
            // projectionViewer.getTextWidget().redraw();
            try {
                projectionViewer.reinitializeProjection();
            } catch (Throwable ex) {
                // We can catch OutOfMemory here for too big/complex documents
                // $NON-NLS-1$
                log.warn("Can't initialize SQL syntax projection", ex);
            }
        }
    }
    // Update configuration
    if (getSourceViewerConfiguration() instanceof SQLEditorSourceViewerConfiguration) {
        ((SQLEditorSourceViewerConfiguration) getSourceViewerConfiguration()).onDataSourceChange();
    }
    final IVerticalRuler verticalRuler = getVerticalRuler();
    if (verticalRuler != null) {
        verticalRuler.update();
    }
}
Also used : BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) SQLPartitionScanner(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLPartitionScanner) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer)

Aggregations

FastPartitioner (org.eclipse.jface.text.rules.FastPartitioner)2 ProjectionViewer (org.eclipse.jface.text.source.projection.ProjectionViewer)2 BasicSQLDialect (org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect)2 SQLPartitionScanner (org.jkiss.dbeaver.ui.editors.sql.syntax.SQLPartitionScanner)2 SQLParserContext (org.jkiss.dbeaver.model.sql.parser.SQLParserContext)1 SQLRuleManager (org.jkiss.dbeaver.model.sql.parser.SQLRuleManager)1