Skip to content

Text Editor

Marcus Henriksson edited this page Apr 2, 2026 · 2 revisions

Text Editor

Queryeer's editor is built on RSyntaxTextArea and extended with a custom ANTLR-based parsing and completion engine. It supports syntax highlighting, grammar-aware code completion, multi-caret editing, and more.


Syntax Highlighting

The editor provides syntax highlighting for SQL and query languages. Colors and styles are theme-aware and update automatically when you switch themes.

Supported dialects with full syntax highlighting:

  • T-SQL (SQL Server) — keywords, built-in functions, operators, string literals, comments
  • Payloadbuilder — the built-in query language

Code Completion

Code completion is grammar-aware, powered by ANTLR 4 and the antlr4-c3 (Code Completion Core) library. The engine parses the query up to the current caret position, determines the completion context, and suggests relevant items.

What Gets Suggested

Context Suggestions
Table position Table and view names from the connected catalog
Column position Column names relevant to the tables in the current query
Function call Built-in functions for the current SQL dialect
JOIN condition Foreign key join conditions (high priority, shown first)
Procedure call Stored procedure parameter names
INSERT / UPDATE / DELETE Target table columns
IN (...) list Clipboard content parsed as an IN-list

Completion Mechanics

The completion engine uses a multi-tier approach to reliably determine context even when the query is syntactically incomplete:

  1. Parse-tree analysis — traverses the partial parse tree to find the exact grammar rule at the caret position
  2. Token stream analysis — fallback that scans the token stream when the parse tree is ambiguous
  3. Mini-parse recovery — isolates the current statement and re-parses it in recovery mode to handle syntax errors gracefully

Results are cached at multiple levels (token offsets, alias maps, mini-parse results, C3 candidates) to keep completion fast even on large query files.

Performance Caching

Cache Layer What Is Cached
Token offset cache Token boundaries for the current document version
Alias collection cache Table alias → table name mappings per statement
Mini-parse cache Isolated re-parse results for the current statement
C3 candidate cache Grammar rule completion candidates
ATN shortcut memoization ANTLR transition lookups

Multi-Caret Editing

The editor supports placing multiple carets in the document simultaneously. All carets accept the same keystrokes, letting you make identical edits in multiple locations at once. Secondary carets are painted with a distinct color so they are easy to spot.


Code Folding

Code folding is available for block structures such as multi-statement queries, allowing you to collapse sections you are not currently working on.


Find & Replace

A standard Find/Replace toolbar is available in the editor. You can search by literal text or regular expression, with options for case-sensitive matching.


Comment Toggle

Select one or more lines and toggle line comments (-- for SQL) on or off with a single keyboard shortcut.


Query Shortcuts

Custom keyboard shortcuts can be configured in the Options dialog under Editor → Query Shortcuts. A shortcut can be bound to insert a text snippet or trigger a specific action, allowing you to build a personal library of commonly used query fragments.


Caret Position Display

The current line and column number are displayed in the status bar and update live as you move the caret. This is useful when referencing error messages that cite line numbers.


Text Selection API

The editor exposes a TextSelection object that represents the current selection. Other components (such as output panels and AI context pickers) can read the selection to include selected query text in their operations.


Link Actions (Ctrl+Click)

Holding Ctrl and hovering over a recognized token in the editor triggers a link action. The text becomes underlined and the cursor changes to a hand pointer. Clicking opens a small popup menu with the available actions for that token.

Link actions are defined per query engine. The JDBC engine ships with a default set and allows full customization through Options → JDBC → Query Actions.

Built-in JDBC Link Actions

Object Type Actions
Table, View, Synonym Describe — runs sp_help or equivalent; Top 500SELECT TOP 500 * FROM …; CountSELECT COUNT(*) FROM …
Procedure, Function, Trigger Definition To Text — retrieves the object definition and opens it in the editor

Configuring Link Actions

Custom link actions are defined in a configuration file (com.queryeer.jdbc.QueryActions.cfg) editable through the Options dialog. Each action specifies:

  • Object types it applies to (table, view, procedure, function, trigger, synonym)
  • TriggerLINK (Ctrl+click) or CONTEXT_MENU (right-click), or both
  • Target — open the result in the TEXT_EDITOR or navigate to the object in the NAVIGATION_TREE
  • SQL template — the query to execute, with the object name substituted in

Database-specific overrides can be defined to use different SQL for different server types.

Extension Point

Plugins can provide link actions for their own query engines by implementing supportsLinkActions() and getLinkAction(int offset) on ITextEditorDocumentParser. The returned LinkAction contains the character offsets of the link in the document and the list of Swing Actions to show in the popup.


Document Highlights

Ranges of text can be highlighted with color overlays. This is used by features such as:

  • Error markers showing which part of a query failed
  • Query plan node highlighting

Dialect-Specific Features

T-SQL (SQL Server)

  • Full T-SQL keyword set recognized
  • Built-in function completion (string, date, aggregate, system functions)
  • Procedure parameter completion after EXEC
  • INSERT/UPDATE/DELETE target column completion
  • Dotted qualifier fallback for schema.table.column notation

Adding New Dialects

New SQL dialects can be added via the plugin system by extending the abstract AntlrDocumentParser base class and providing an ANTLR grammar. The shared completion infrastructure (C3 integration, caching, context resolution) is reused automatically.