-
Notifications
You must be signed in to change notification settings - Fork 0
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.
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 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.
| 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 |
The completion engine uses a multi-tier approach to reliably determine context even when the query is syntactically incomplete:
- Parse-tree analysis — traverses the partial parse tree to find the exact grammar rule at the caret position
- Token stream analysis — fallback that scans the token stream when the parse tree is ambiguous
- 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.
| 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 |
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 is available for block structures such as multi-statement queries, allowing you to collapse sections you are not currently working on.
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.
Select one or more lines and toggle line comments (-- for SQL) on or off with a single keyboard shortcut.
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.
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.
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.
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.
| Object Type | Actions |
|---|---|
| Table, View, Synonym |
Describe — runs sp_help or equivalent; Top 500 — SELECT TOP 500 * FROM …; Count — SELECT COUNT(*) FROM …
|
| Procedure, Function, Trigger | Definition To Text — retrieves the object definition and opens it in the editor |
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)
-
Trigger —
LINK(Ctrl+click) orCONTEXT_MENU(right-click), or both -
Target — open the result in the
TEXT_EDITORor navigate to the object in theNAVIGATION_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.
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.
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
- 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.columnnotation
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.