Repository navigation
Description
Before you start
- I searched the existing issues and the roadmap and did not find a duplicate request.
What problem does this solve?
One expression language now serves Select By Attributes, Definition Query, display filters, label classes, attribute constraints and rules, reports, Calculate Field and symbols by expression (grammar). Nowhere it is typed offers any help with it:
- In the Script pane, completion stops at the edge of an expression: inside
"where": "…"nothing is offered (scriptcomplete.rstests:labels.style {"where": "gives no offer). Fields, functions, keywords and variables must be typed from memory, and a field with spaces must be written as\"Pop Est\"inside the JSON string. - The dialogs and panes that take an expression show at most a line of help text (Calculate Field), with no completion and no function signatures.
There is also no single list of what the language accepts: functions are in a private table (FUNCS in crates/data/src/query.rs) without signatures or descriptions, variables are match arms in the parser, and keywords are scattered through eat_kw calls. Any completion built today would need its own copy of the vocabulary, and that copy would fall behind each time the language grows.
Proposed solution
Build the shared piece once: a completion engine below the UI that reads only what the parser itself uses, so a new function, variable or keyword is offered as soon as the parser accepts it, and a new command or tool parameter that takes an expression gets completion with no UI change.
Where the values come from
| Vocabulary | Source | Grows by itself because |
|---|---|---|
| Functions | FUNCS extended with signature and description, exposed as functions() |
the parser resolves calls through it; a Func missing from it cannot be called |
| Variables | new VARS table (name, aliases, Var, description) |
the parser resolves @…/$… through it, replacing the literal match |
| Keywords and operators | new KEYWORDS table (operators apart from CASE words) |
the parser reads its constants |
| Fields, layers, values | the Session, at the moment of typing |
already live, as script completion reads them today |
| Where expressions are typed | an Expression parameter kind in ParamSpec / CommandSpec |
the UI asks the model, not a list of key names |
Guards in CI: every Func has a catalog entry with a signature and description (exhaustive match), the function table in docs/user-guide/expressions.md matches the catalog, and everything in the catalogs parses.
Descriptions stay in English in data and are shown through tl!(…) in the UI, as tool names and summaries already are. Function names, keywords and variables are syntax and are never translated.
Plan (one PR each)
- PR 0 —
data: catalogs as the single source.FuncSpecwith signature, description and example (functions()),VARS, keywords as aKwenum; the parser consumes them; coverage and docs tests. A refactor with no change in behaviour. refactor(data): expression functions, variables and keywords in catalogs the parser reads (#1240) #1957 - PR 1 —
ui-egui: Functions and Variables menus beside the field buttons, in Select By Attributes, the Layer Properties Query tab and the Labeling SQL class, listed from the catalogs. feat(ui): Functions and Variables menus beside the clause buttons, from the expression catalogs (#1240) #1983 - PR 2 —
data:complete_at(text, cursor). It reads a partial expression with the real lexer and tolerates unfinished input. It returns the word being typed, what is expected there (an operand: field, function, variable, literal; an operator; the nextCASEword; nothing inside'text'), the open function and argument index (for its signature), and the field of a comparison. Unit tests only, hostile input included (lengths, nesting). feat(data): complete_at reads what may come next at a point of an expression, from the parser itself (#1240) #1999 - PR 3 —
ui-egui: a reusableexpr_editwidget. It has the popup list, the open function's signature, fields quoted when needed (spaces, punctuation, keyword names), and closing(and'. The popup and keyboard handling are moved out ofscriptcompleteinto a shared module. The first use is Calculate Field. The menus of PR 1 take the shared popup's look, and the two rows of field and operator buttons (dialogs::field_chips,sqlbox::chips) become one. - PR 4 — Script pane. Inside a JSON string whose key takes an expression (by a new
Expressionparameter kind), the cursor maps to the unescaped expression and accepted items are escaped back (\"Pop Est\"). - PR 5 — The other places. Select By Attributes, Definition Query, display filters, label classes, symbols by expression, attribute constraints and rules, reports.
- PR 6 — Field values. After
field = 'orfield IN (, the field's distinct values. Streamed layers give a bounded sample, and the list says so (values from a sample of N).
Question for the maintainer
Should the function catalog stay static (const, behind functions()), or become a registry in the Session so plugins could add expression functions? Starting static behind functions() lets a registry replace it later without changing callers. A registry means parse and eval take it as an argument.
Estimated scope
Wishlist: a larger or longer-term idea
Alternatives considered
- A tokenizer of its own in
ui-egui: no change todata, but a second grammar that falls behind the real one. - Prefix matching only, no context: cheap, but it offers
ANDwhere a field goes and fields after a complete comparison. - Completion in the Script pane only: smaller, but the dialogs, where most expressions are typed, would still have none, and a later widget would duplicate it.
Activity
jgregoriorincon commentedon Nov 1, 2026
@giswqs I'd like to take this one, one PR at a time as in the checklist above.
Before I start PR 0 (the catalogs in
data), one decision is yours: should the function catalog stay static (aconsttable behindfunctions()), or become a registry in theSessionso plugins could add expression functions later?My suggestion is static behind
functions()for now. It keepsparseandevalas they are, and a registry can replace it later without changing any caller. If you'd rather have the registry from the start, I'll plan PR 0 around it.Anything else in the plan you'd change (the order, or the
Expressionparameter kind inParamSpec/CommandSpec), I'm happy to adjust before writing code.jgregoriorincon commentedon Nov 13, 2026
lds up better than when I asked:
parseandevaltake it as an argument, which touches about 20 callers acrossengine,map,analysisandui-egui.A registry can still replace it later behind
functions()without changing callers.Since this issue was opened the language has grown (
area(),perimeter()andline_length()with units,$area,$perimeterand$length, dates), and so have the places where expressions are typed (label text, size, colour and angle, Unique Values by expression, the Query tab in Layer Properties). None of them offers any help yet.Keeping the catalogs current. The parser reads the catalogs, so nothing can be added to the language without them:
FuncSpecwith signature, description and an example, all required, and an exhaustivematchfromFuncto its entry: a newFuncdoesn't compile without one.VARSinstead of match arms; keywords through aKwenum andKEYWORDSinstead ofeat_kw("…")strings.docs/user-guide/expressions.mdname the same functions, variables, keywords and units; command and tool parameters named like expressions (where,expression,filter…) are declared asExpression, with a list of exceptions.AGENTS.mdsaying where a new function, variable or keyword goes.One change to the plan. Select By Attributes and the Query tab already share buttons for fields and operators. A list of functions and variables next to them (click to insert, with signature and description) makes the catalogs useful right after PR 0, before the completion engine:
complete_at(text, cursor).expr_editwidget, first in Calculate Field.I'll update the checklist in the issue body to match. If you'd rather have the registry from the start, or a different order, let me know before PR 0 lands.
refactor(data): expression functions, variables and keywords in catal…
refactor(data): expression functions, variables and keywords in catal…
docs: the Functions and Variables menus add, in both guides; tests pi…
feat(ui): Functions and Variables menus beside the clause buttons, fr…
docs(data): complete_at gives nothing for text that can't be read int…
fix(data): complete_at reads doubled quotes in the prefix, says nothi…
feat(data): complete_at reads what may come next at a point of an exp…
fix(ui): the shared completion list opens no empty list and takes no …
test(ui): the shared completion list leaves keys to the box and opens…
test(ui): name the box in the empty-offer test, and give its list a c…
refactor(ui): the Script's completion list and its help move to a sha…
40 remaining items
feat(script): a step's params offer the values its command takes (ope…
Mavrick-F commentedon Nov 19, 2026
A request building on the Calculate Field work here (#2040, #2092, #2113): show what the expression gives while it's typed. A line under the box would show the result for the first three selected rows, or the first three rows when nothing is selected. Calculate Field runs on those same rows, so the preview matches what will be written. Today you run the expression, check the table, then undo and try again. This would mostly remove that loop for the most common edit.
Details I'd suggest:
Invalid:line does, once no suggestion is open. It reuses the sameCalculationthatcheck_calculationalready parses, so there's no second evaluator.Other places where expressions are typed (label text, symbols by expression) could use the same line later through
expr_edit. Filters are a different case: a count of matches grows with the layer size, so it would need its own design and isn't part of this.I can implement this myself in its own PR under this issue, or leave it as a design proposal to stay out of people's way.
feat(ui): say when a function gives null in its help, keep an express…
docs(ui): an attribute rule's expression is applied by Add; no length…
feat(ui): suggest as an expression is typed in the By Expression, rep…
fix(ui): a label class's SQL box holds back a Check error too while a…
feat(ui): suggest as a clause is typed in Select By Attributes, the Q…
fix(ui): a quick tap on a Display Filters suggestion past the menu's …
feat(ui): Display Filters suggests as a clause is typed, its list dra…
fix(ui): values offered follow rows edited in place; whole numbers pa…
fix(ui): no value with % or _ offered in a LIKE pattern, no number wr…
fix(ui): no value offered just before one already written; -0 written…
feat(ui): expression boxes suggest a field's values where one is comp…
jgregoriorincon commentedon Nov 23, 2026
The plan in this issue is complete, so I'm closing it.
complete_at: feat(data): complete_at reads what may come next at a point of an expression, from the parser itself (#1240) #1999expr_editin Calculate Field and the shared popup: refactor(ui): the Script's completion list and its help move to a shared module (#1240) #2016, feat(ui): Calculate Field suggests fields, functions, variables and keywords as the expression is typed (#1240) #2040, feat(ui): Calculate Field shows the signature of the call being typed, its argument marked (#1240) #2092, feat(ui): brackets and quotes close themselves in Calculate Field's expression (#1240) #2113, fix(ui): accepting a function in Calculate Field stays within the expression's length limit (#1240) #2168, fix(ui): one row of clause buttons, quoting the field names that need it (#1240) #2267, feat(ui): the Functions and Variables menus are suggestion lists with their help (#1240) #2306, feat(ui): say when a function gives null in its help, keep an expression's error in view under its signature (#1240) #2515, and feat(ui): expression menus share completion rows and help #2302 by @deniial00, who gave the menus the shared row style and help panelFollow-ups found along the way were done in their own issues (#2343, #2618, #2619, #2631, #2697, #2718).
@Mavrick-F's proposal above, a preview of Calculate Field's result on the first rows while the expression is typed, is now #2817, with credit to them.