sqllens 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -74
- package/THIRD-PARTY-NOTICES.md +50 -5
- package/dist/api.d.ts +5 -3
- package/dist/api.js +11 -4
- package/dist/bigquery/behavior.d.ts +2 -0
- package/dist/bigquery/behavior.js +20 -0
- package/dist/bigquery/dot-path.d.ts +0 -2
- package/dist/bigquery/dot-path.js +0 -1
- package/dist/bigquery/fold.d.ts +8 -0
- package/dist/bigquery/fold.js +39 -0
- package/dist/bigquery/index.d.ts +7 -0
- package/dist/bigquery/index.js +10 -0
- package/dist/{infer/bigquery.d.ts → bigquery/infer.d.ts} +2 -2
- package/dist/{infer/bigquery.js → bigquery/infer.js} +4 -3
- package/dist/bigquery/lower.js +35 -12
- package/dist/bigquery/signatures.generated.d.ts +6 -0
- package/dist/bigquery/signatures.generated.js +1068 -0
- package/dist/completion/atn-walk.d.ts +13 -2
- package/dist/completion/atn-walk.js +13 -10
- package/dist/completion/complete.d.ts +4 -3
- package/dist/completion/complete.js +101 -45
- package/dist/completion/jinja-slot.d.ts +24 -0
- package/dist/completion/jinja-slot.js +126 -0
- package/dist/completion/parser-factory.d.ts +13 -1
- package/dist/completion/parser-factory.js +12 -0
- package/dist/databricks/behavior.d.ts +2 -0
- package/dist/databricks/behavior.js +19 -0
- package/dist/databricks/fold.d.ts +8 -0
- package/dist/databricks/fold.js +27 -0
- package/dist/databricks/index.d.ts +7 -0
- package/dist/databricks/index.js +10 -0
- package/dist/databricks/infer.d.ts +6 -0
- package/dist/databricks/infer.js +638 -0
- package/dist/databricks/signatures.generated.d.ts +6 -0
- package/dist/databricks/signatures.generated.js +1745 -0
- package/dist/dialect-behavior/behavior.d.ts +26 -0
- package/dist/dialect-behavior/behavior.js +1 -0
- package/dist/dialect-behavior/carrier.d.ts +5 -0
- package/dist/dialect-behavior/carrier.js +5 -0
- package/dist/dialect-behavior/coerce-rules.d.ts +7 -0
- package/dist/dialect-behavior/coerce-rules.js +69 -0
- package/dist/dialect-behavior/public-fold.d.ts +6 -0
- package/dist/dialect-behavior/public-fold.js +9 -0
- package/dist/dialect-behavior/registry.d.ts +6 -0
- package/dist/dialect-behavior/registry.js +34 -0
- package/dist/dialect-symbols.js +16 -19
- package/dist/document/document.d.ts +1 -1
- package/dist/document/document.js +8 -7
- package/dist/duckdb/behavior.d.ts +2 -0
- package/dist/duckdb/behavior.js +21 -0
- package/dist/duckdb/fold.d.ts +8 -0
- package/dist/duckdb/fold.js +29 -0
- package/dist/duckdb/index.d.ts +7 -0
- package/dist/duckdb/index.js +10 -0
- package/dist/{infer/duckdb.d.ts → duckdb/infer.d.ts} +2 -2
- package/dist/{infer/duckdb.js → duckdb/infer.js} +4 -3
- package/dist/duckdb/lower.js +47 -15
- package/dist/duckdb/signatures.generated.d.ts +6 -0
- package/dist/duckdb/signatures.generated.js +1072 -0
- package/dist/generated/bigquery/GoogleSQLParser.js +0 -7060
- package/dist/generated/databricks/DatabricksParser.js +0 -4800
- package/dist/generated/duckdb/DuckdbParser.js +0 -9100
- package/dist/generated/minijinja/MinijinjaParser.js +0 -380
- package/dist/generated/mysql/MysqlParser.js +0 -6330
- package/dist/generated/postgres/PostgresParser.js +0 -8530
- package/dist/generated/redshift/RedshiftParser.js +0 -10970
- package/dist/generated/snowflake/SnowflakeParser.js +0 -7320
- package/dist/generated/sqlite/SqliteParser.js +0 -1150
- package/dist/generated/trino/TrinoParser.js +0 -3770
- package/dist/generated/tsql/TSqlParser.js +0 -8420
- package/dist/ident/fold.d.ts +24 -15
- package/dist/ident/fold.js +12 -194
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -8
- package/dist/infer/functions.d.ts +22 -11
- package/dist/infer/functions.js +26 -888
- package/dist/infer/infer.js +16 -14
- package/dist/infer/nullability.js +3 -4
- package/dist/infer/types.d.ts +1 -1
- package/dist/infer/types.js +7 -7
- package/dist/ir/ir.d.ts +26 -17
- package/dist/ir/span.js +0 -2
- package/dist/ir/walk.js +3 -3
- package/dist/lineage/hops.js +13 -10
- package/dist/lineage/lineage.js +10 -7
- package/dist/minijinja/apply-tags.d.ts +14 -7
- package/dist/minijinja/apply-tags.js +66 -121
- package/dist/minijinja/parse.js +5 -5
- package/dist/minijinja/tag-ast.d.ts +29 -36
- package/dist/minijinja/tag-ast.js +210 -90
- package/dist/mysql/behavior.d.ts +2 -0
- package/dist/mysql/behavior.js +21 -0
- package/dist/mysql/fold.d.ts +8 -0
- package/dist/mysql/fold.js +49 -0
- package/dist/mysql/index.d.ts +7 -0
- package/dist/mysql/index.js +10 -0
- package/dist/{infer/mysql.d.ts → mysql/infer.d.ts} +2 -2
- package/dist/{infer/mysql.js → mysql/infer.js} +3 -2
- package/dist/mysql/signatures.generated.d.ts +6 -0
- package/dist/mysql/signatures.generated.js +508 -0
- package/dist/postgres/behavior.d.ts +2 -0
- package/dist/postgres/behavior.js +19 -0
- package/dist/postgres/fold.d.ts +8 -0
- package/dist/postgres/fold.js +30 -0
- package/dist/postgres/index.d.ts +7 -0
- package/dist/postgres/index.js +10 -0
- package/dist/{infer/postgres.d.ts → postgres/infer.d.ts} +2 -2
- package/dist/{infer/postgres.js → postgres/infer.js} +4 -3
- package/dist/postgres/lower.js +2 -2
- package/dist/postgres/signatures.generated.d.ts +6 -0
- package/dist/postgres/signatures.generated.js +2973 -0
- package/dist/qualify/check-calls.js +80 -161
- package/dist/qualify/qualify.js +16 -14
- package/dist/qualify/schema-provider.js +2 -2
- package/dist/qualify/schema.js +3 -3
- package/dist/qualify/template-provider.d.ts +45 -12
- package/dist/qualify/template-provider.js +69 -38
- package/dist/redshift/behavior.d.ts +2 -0
- package/dist/redshift/behavior.js +19 -0
- package/dist/redshift/fold.d.ts +8 -0
- package/dist/redshift/fold.js +31 -0
- package/dist/redshift/index.d.ts +7 -0
- package/dist/redshift/index.js +10 -0
- package/dist/{infer/redshift.d.ts → redshift/infer.d.ts} +2 -2
- package/dist/{infer/redshift.js → redshift/infer.js} +4 -3
- package/dist/redshift/lower.js +2 -2
- package/dist/redshift/signatures.generated.d.ts +6 -0
- package/dist/redshift/signatures.generated.js +757 -0
- package/dist/references/references.js +17 -12
- package/dist/scope/like-pattern.d.ts +2 -0
- package/dist/scope/like-pattern.js +15 -0
- package/dist/scope/scope.d.ts +5 -5
- package/dist/scope/scope.js +48 -42
- package/dist/sema/resolve.js +17 -12
- package/dist/session.d.ts +2 -2
- package/dist/signature/signature.d.ts +14 -6
- package/dist/signature/signature.js +30 -22
- package/dist/signature/signatures.d.ts +14 -12
- package/dist/signature/signatures.js +42 -721
- package/dist/snowflake/behavior.d.ts +2 -0
- package/dist/snowflake/behavior.js +22 -0
- package/dist/snowflake/fold.d.ts +8 -0
- package/dist/snowflake/fold.js +25 -0
- package/dist/snowflake/index.d.ts +7 -0
- package/dist/snowflake/index.js +10 -0
- package/dist/{infer/snowflake.d.ts → snowflake/infer.d.ts} +2 -2
- package/dist/{infer/snowflake.js → snowflake/infer.js} +4 -3
- package/dist/snowflake/lower.js +59 -19
- package/dist/snowflake/signatures.generated.d.ts +6 -0
- package/dist/snowflake/signatures.generated.js +2080 -0
- package/dist/sqlite/behavior.d.ts +2 -0
- package/dist/sqlite/behavior.js +19 -0
- package/dist/sqlite/fold.d.ts +8 -0
- package/dist/sqlite/fold.js +41 -0
- package/dist/sqlite/index.d.ts +7 -0
- package/dist/sqlite/index.js +10 -0
- package/dist/{infer/sqlite.d.ts → sqlite/infer.d.ts} +2 -2
- package/dist/{infer/sqlite.js → sqlite/infer.js} +4 -3
- package/dist/sqlite/signatures.generated.d.ts +6 -0
- package/dist/sqlite/signatures.generated.js +277 -0
- package/dist/symbols/symbols.js +14 -12
- package/dist/trino/behavior.d.ts +2 -0
- package/dist/trino/behavior.js +21 -0
- package/dist/trino/fold.d.ts +8 -0
- package/dist/trino/fold.js +39 -0
- package/dist/trino/index.d.ts +7 -0
- package/dist/trino/index.js +10 -0
- package/dist/{infer/trino.d.ts → trino/infer.d.ts} +2 -2
- package/dist/{infer/trino.js → trino/infer.js} +4 -3
- package/dist/trino/lower.js +5 -5
- package/dist/trino/signatures.generated.d.ts +6 -0
- package/dist/trino/signatures.generated.js +968 -0
- package/dist/tsql/behavior.d.ts +2 -0
- package/dist/tsql/behavior.js +20 -0
- package/dist/tsql/fold.d.ts +8 -0
- package/dist/tsql/fold.js +34 -0
- package/dist/tsql/index.d.ts +7 -0
- package/dist/tsql/index.js +10 -0
- package/dist/tsql/infer.d.ts +16 -0
- package/dist/tsql/infer.js +289 -0
- package/dist/tsql/lower.js +4 -4
- package/dist/tsql/signatures.generated.d.ts +6 -0
- package/dist/tsql/signatures.generated.js +640 -0
- package/package.json +5 -10
- package/dist/generated/bigquery/GoogleSQLLexer.d.ts +0 -407
- package/dist/generated/bigquery/GoogleSQLParser.d.ts +0 -9558
- package/dist/generated/bigquery/GoogleSQLParserListener.d.ts +0 -7777
- package/dist/generated/bigquery/GoogleSQLParserListener.js +0 -7070
- package/dist/generated/databricks/DatabricksLexer.d.ts +0 -566
- package/dist/generated/databricks/DatabricksParser.d.ts +0 -7771
- package/dist/generated/databricks/DatabricksParserListener.d.ts +0 -5737
- package/dist/generated/databricks/DatabricksParserListener.js +0 -5256
- package/dist/generated/duckdb/DuckdbLexer.d.ts +0 -691
- package/dist/generated/duckdb/DuckdbParser.d.ts +0 -13932
- package/dist/generated/duckdb/DuckdbParserListener.d.ts +0 -10049
- package/dist/generated/duckdb/DuckdbParserListener.js +0 -9138
- package/dist/generated/minijinja/MinijinjaLexer.d.ts +0 -108
- package/dist/generated/minijinja/MinijinjaParser.d.ts +0 -604
- package/dist/generated/minijinja/MinijinjaParserListener.d.ts +0 -449
- package/dist/generated/minijinja/MinijinjaParserListener.js +0 -410
- package/dist/generated/mysql/MysqlLexer.d.ts +0 -1198
- package/dist/generated/mysql/MysqlParser.d.ts +0 -10992
- package/dist/generated/mysql/MysqlParserListener.d.ts +0 -7592
- package/dist/generated/mysql/MysqlParserListener.js +0 -6958
- package/dist/generated/postgres/PostgresLexer.d.ts +0 -663
- package/dist/generated/postgres/PostgresParser.d.ts +0 -12963
- package/dist/generated/postgres/PostgresParserListener.d.ts +0 -9408
- package/dist/generated/postgres/PostgresParserListener.js +0 -8554
- package/dist/generated/redshift/RedshiftLexer.d.ts +0 -954
- package/dist/generated/redshift/RedshiftParser.d.ts +0 -16939
- package/dist/generated/redshift/RedshiftParserListener.d.ts +0 -12092
- package/dist/generated/redshift/RedshiftParserListener.js +0 -10994
- package/dist/generated/snowflake/SnowflakeLexer.d.ts +0 -1046
- package/dist/generated/snowflake/SnowflakeParser.d.ts +0 -14196
- package/dist/generated/snowflake/SnowflakeParserListener.d.ts +0 -8063
- package/dist/generated/snowflake/SnowflakeParserListener.js +0 -7330
- package/dist/generated/sqlite/SqliteLexer.d.ts +0 -210
- package/dist/generated/sqlite/SqliteParser.d.ts +0 -2115
- package/dist/generated/sqlite/SqliteParserListener.d.ts +0 -1276
- package/dist/generated/sqlite/SqliteParserListener.js +0 -1160
- package/dist/generated/trino/TrinoLexer.d.ts +0 -381
- package/dist/generated/trino/TrinoParser.d.ts +0 -5340
- package/dist/generated/trino/TrinoParserListener.d.ts +0 -4704
- package/dist/generated/trino/TrinoParserListener.js +0 -4326
- package/dist/generated/tsql/TSqlLexer.d.ts +0 -1278
- package/dist/generated/tsql/TSqlParser.d.ts +0 -17267
- package/dist/generated/tsql/TSqlParserListener.d.ts +0 -9697
- package/dist/generated/tsql/TSqlParserListener.js +0 -8854
- package/dist/infer/dialect.d.ts +0 -21
- package/dist/infer/dialect.js +0 -100
- package/dist/infer/literals.d.ts +0 -6
- package/dist/infer/literals.js +0 -44
- package/dist/signature/generated/tsql.d.ts +0 -3
- package/dist/signature/generated/tsql.js +0 -260
package/README.md
CHANGED
|
@@ -15,9 +15,7 @@ Athena, Fabric, and MariaDB (see [Dialects](#dialects)).
|
|
|
15
15
|
|
|
16
16
|
The front end is error-tolerant and token-first, so the library drives editor
|
|
17
17
|
features (completion, hover, diagnostics, go-to-definition) over incomplete,
|
|
18
|
-
mid-edit text. See [Editor / language tooling](#editor--language-tooling).
|
|
19
|
-
(Language Server Protocol) server built on it lives in the repo, but it is
|
|
20
|
-
experimental and not part of the published package.
|
|
18
|
+
mid-edit text. See [Editor / language tooling](#editor--language-tooling).
|
|
21
19
|
|
|
22
20
|
```bash
|
|
23
21
|
npm install sqllens
|
|
@@ -208,7 +206,7 @@ import { parse, qualify, lineage, deriveSymbols, toScopes, Schema } from "sqllen
|
|
|
208
206
|
const { ast, errors, cst } = parse("SELECT a, b FROM t", "snowflake");
|
|
209
207
|
// ast = dialect-neutral IR (frozen); cst = the raw antlr tree (escape hatch)
|
|
210
208
|
|
|
211
|
-
const scopes = toScopes(ast
|
|
209
|
+
const scopes = toScopes(ast); // idempotent lift
|
|
212
210
|
qualify(scopes, schema); // reuses scopes — never re-parses or re-resolves
|
|
213
211
|
lineage(scopes, schema); // safe on the same scopes, in any order
|
|
214
212
|
deriveSymbols(scopes); // independent results
|
|
@@ -381,76 +379,6 @@ doc.tokenAt(7); // token under an offset
|
|
|
381
379
|
const next = doc.withText("SELECT amount, id FROM sales", 2); // immutable edit → new doc
|
|
382
380
|
```
|
|
383
381
|
|
|
384
|
-
## Language server (experimental)
|
|
385
|
-
|
|
386
|
-
An LSP (Language Server Protocol) server built on the library lives in `src/lsp/`.
|
|
387
|
-
It is experimental and **not part of the published npm package**: the package ships
|
|
388
|
-
the library only, and the server is source you run from the repo. It holds one
|
|
389
|
-
`SqlDocument` per open file (rebuilt on edit) and reaches the library only through
|
|
390
|
-
the public API, and adds no analysis of its own beyond protocol translation.
|
|
391
|
-
|
|
392
|
-
A SQL server needs only a subset of LSP's ~30 request types: some don't apply to
|
|
393
|
-
SQL (type hierarchy, document color, monikers), and a few are deferred (formatting,
|
|
394
|
-
project-wide navigation). Where the server stands today, feature by feature:
|
|
395
|
-
|
|
396
|
-
### Language features
|
|
397
|
-
|
|
398
|
-
| Feature | Status |
|
|
399
|
-
| --- | --- |
|
|
400
|
-
| Completion (+ resolve) | ✅ |
|
|
401
|
-
| Hover | ✅ |
|
|
402
|
-
| Hover — nullability | ✅ (` — not null` / ` — nullable` suffix when provable) |
|
|
403
|
-
| Signature help | ✅ |
|
|
404
|
-
| Go to definition | ✅ |
|
|
405
|
-
| Find references | ✅ |
|
|
406
|
-
| Document highlight | ✅ |
|
|
407
|
-
| Document symbols | ✅ |
|
|
408
|
-
| Folding range | ✅ |
|
|
409
|
-
| Selection range | ✅ |
|
|
410
|
-
| Semantic tokens (full / range / delta) | ✅ all three |
|
|
411
|
-
| Inlay hints | ✅ (no resolve) |
|
|
412
|
-
| Code lens | ✅ (no resolve) |
|
|
413
|
-
| Go to declaration | ◻️ not yet |
|
|
414
|
-
| Go to type definition | ◻️ not yet |
|
|
415
|
-
| Go to implementation | ◻️ not yet — name → its defining query (view / model); needs the project model |
|
|
416
|
-
| Call hierarchy | ◻️ not yet — the CTE / view / model dependency graph |
|
|
417
|
-
| Document link | ◻️ not yet |
|
|
418
|
-
| Linked editing range | ◻️ not yet — live alias / name sync-edit |
|
|
419
|
-
| Code action (quick fixes) | ◻️ next phase |
|
|
420
|
-
| Rename (+ prepare) | ◻️ next phase |
|
|
421
|
-
| Formatting / range / on-type | ◻️ deferred (external formatter) |
|
|
422
|
-
| Inline values | ◻️ debugger surface |
|
|
423
|
-
| Type hierarchy | — n/a — SQL has no type-inheritance relation |
|
|
424
|
-
| Document color | — n/a — no color literals |
|
|
425
|
-
| Moniker | — n/a — LSIF / cross-repo indexing concern |
|
|
426
|
-
|
|
427
|
-
### Diagnostics & document sync
|
|
428
|
-
|
|
429
|
-
| Feature | Status |
|
|
430
|
-
| --- | --- |
|
|
431
|
-
| Diagnostics — push (`publishDiagnostics`) | ✅ |
|
|
432
|
-
| Diagnostics — call signature (arity / argument type) | ✅ (curated tables; never-wrong, per-dialect coercion) |
|
|
433
|
-
| Diagnostics — pull (document) | ✅ |
|
|
434
|
-
| Diagnostics — pull (workspace) | ◻️ not yet |
|
|
435
|
-
| Text sync — open / change / close | ✅ (full-document) |
|
|
436
|
-
| Incremental sync | ◻️ full-document only (fine at SQL file sizes) |
|
|
437
|
-
| Save notifications (`didSave` / `willSave`) | ◻️ not yet |
|
|
438
|
-
| Notebook document sync | ◻️ not yet |
|
|
439
|
-
|
|
440
|
-
### Workspace features
|
|
441
|
-
|
|
442
|
-
| Feature | Status |
|
|
443
|
-
| --- | --- |
|
|
444
|
-
| Workspace symbols | ◻️ needs a project / multi-file model |
|
|
445
|
-
| Execute command | ◻️ not yet |
|
|
446
|
-
| Configuration / watched-files | ◻️ not yet (protocol config; file-based `.sqllens.json` config exists) |
|
|
447
|
-
| File operations (create / rename / delete) | ◻️ not yet |
|
|
448
|
-
|
|
449
|
-
Legend: ✅ implemented · ◻️ not yet / deferred · — not applicable to SQL. The
|
|
450
|
-
deferred items are tracked work: rename and
|
|
451
|
-
code actions are the next LSP phase, workspace symbols need the project model,
|
|
452
|
-
and formatting is expected to wrap an existing external formatter.
|
|
453
|
-
|
|
454
382
|
## How sqllens compares
|
|
455
383
|
|
|
456
384
|
The SQL-parser field splits into parse-only libraries and semantic tools bound
|
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -120,14 +120,59 @@ Forked from [antlr/grammars-v4](https://github.com/antlr/grammars-v4)
|
|
|
120
120
|
Positive Technologies; (c) 2017 Ivan Khudyashev. Licensed under the MIT License
|
|
121
121
|
(full text retained in the file headers).
|
|
122
122
|
|
|
123
|
+
## Doc-derived function-signature tables (distributed in this repository)
|
|
124
|
+
|
|
125
|
+
The generated per-dialect function-signature tables (produced by
|
|
126
|
+
`tools/harvest-signatures.mjs`, committed under `src/`) carry factual API-surface
|
|
127
|
+
data (function names, parameter names, arity, optionality) extracted from each
|
|
128
|
+
dialect's reference documentation. Sources and their licenses:
|
|
129
|
+
|
|
130
|
+
### T-SQL signatures, from MicrosoftDocs/sql-docs (CC BY 4.0)
|
|
131
|
+
|
|
132
|
+
Derived from the Transact-SQL reference markdown in
|
|
133
|
+
[MicrosoftDocs/sql-docs](https://github.com/MicrosoftDocs/sql-docs), (c) Microsoft
|
|
134
|
+
Corporation, licensed [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
|
|
135
|
+
Changes were made: the documented syntax notation was mechanically parsed and
|
|
136
|
+
transformed into TypeScript signature tables; no documentation prose is reproduced.
|
|
137
|
+
|
|
138
|
+
### DuckDB signatures, from duckdb/duckdb-web (MIT)
|
|
139
|
+
|
|
140
|
+
Derived from the function reference markdown in
|
|
141
|
+
[duckdb/duckdb-web](https://github.com/duckdb/duckdb-web), Copyright 2018-2025
|
|
142
|
+
Stichting DuckDB Foundation, MIT License.
|
|
143
|
+
|
|
144
|
+
### PostgreSQL signatures, from the PostgreSQL documentation (PostgreSQL License)
|
|
145
|
+
|
|
146
|
+
Derived from `doc/src/sgml/func.sgml` of
|
|
147
|
+
[postgres/postgres](https://github.com/postgres/postgres) (REL_18_STABLE),
|
|
148
|
+
Copyright (c) 1996-2025, PostgreSQL Global Development Group, PostgreSQL License.
|
|
149
|
+
|
|
150
|
+
### Trino signatures, from trinodb/trino docs (Apache License 2.0)
|
|
151
|
+
|
|
152
|
+
Derived from the sphinx function reference in
|
|
153
|
+
[trinodb/trino](https://github.com/trinodb/trino) `docs/src/main/sphinx/functions`
|
|
154
|
+
(release 482), Apache License 2.0. trinodb/trino ships no `NOTICE` file, so there
|
|
155
|
+
is no 4(d) attribution to reproduce.
|
|
156
|
+
|
|
157
|
+
### BigQuery / GoogleSQL signatures, from google/googlesql docs (Apache License 2.0)
|
|
158
|
+
|
|
159
|
+
Derived from the function reference markdown in
|
|
160
|
+
[google/googlesql](https://github.com/google/googlesql) `docs/`, (c) Google LLC,
|
|
161
|
+
Apache License 2.0.
|
|
162
|
+
|
|
163
|
+
### Databricks and Snowflake signatures, from the vendors' public SQL references
|
|
164
|
+
|
|
165
|
+
Derived from the Syntax sections of the public SQL language references at
|
|
166
|
+
[docs.databricks.com](https://docs.databricks.com) ((c) Databricks, Inc.) and
|
|
167
|
+
[docs.snowflake.com](https://docs.snowflake.com) ((c) Snowflake Inc.). These sites
|
|
168
|
+
publish no redistribution license; the tables reproduce only the factual call
|
|
169
|
+
shape of each function (name, parameter names, arity, optionality), the same facts
|
|
170
|
+
any SQL tool documents about a dialect's API surface, and no documentation prose.
|
|
171
|
+
Credited here as sources with thanks.
|
|
172
|
+
|
|
123
173
|
## Runtime and build dependencies (not redistributed in source)
|
|
124
174
|
|
|
125
175
|
- **antlr4ng** — the TypeScript ANTLR runtime (BSD-3-Clause). Runtime dependency.
|
|
126
176
|
- **antlr-ng** — the pure-TypeScript ANTLR generator used by `npm run gen` to
|
|
127
177
|
produce `src/generated/` (a build product, gitignored). Dev dependency.
|
|
128
|
-
- **vscode-languageserver** / **vscode-languageserver-protocol** /
|
|
129
|
-
**vscode-languageserver-textdocument** / **vscode-languageserver-types** — the
|
|
130
|
-
LSP layer's runtime dependencies (MIT).
|
|
131
|
-
- **minimatch** — glob matching used by the LSP layer (ISC).
|
|
132
|
-
|
|
133
178
|
Consult each package's own license for the authoritative terms.
|
package/dist/api.d.ts
CHANGED
|
@@ -117,10 +117,12 @@ export { SqlDocument, type DocumentAnalysis, type StatementCell, type DocumentVa
|
|
|
117
117
|
export { LineIndex } from "./document/line-index.js";
|
|
118
118
|
export type { StatementCellSpan } from "./document/split.js";
|
|
119
119
|
export { complete, completeAt, type Completion } from "./completion/complete.js";
|
|
120
|
-
export {
|
|
121
|
-
export {
|
|
120
|
+
export { jinjaSlotAt, type JinjaSlot } from "./completion/jinja-slot.js";
|
|
121
|
+
export { signatureAt, type SignatureHelpInfo, type SignatureLabel } from "./signature/signature.js";
|
|
122
|
+
export { SIGNATURES, lookupSignature, hasSignature, type FnSignature, type ParamSig } from "./signature/signatures.js";
|
|
122
123
|
export { referencesAt, type Occurrence, type Occurrences } from "./references/references.js";
|
|
123
124
|
export { dialectSymbols, type DialectSymbols } from "./dialect-symbols.js";
|
|
124
125
|
export { CallbackSchema, type SchemaProvider, type TableResolver } from "./qualify/schema-provider.js";
|
|
125
126
|
export { DERIVED_DIALECTS, resolveDialect } from "./derived-dialects.js";
|
|
126
|
-
export { foldIdentifier, displayName
|
|
127
|
+
export { foldIdentifier, displayName } from "./dialect-behavior/public-fold.js";
|
|
128
|
+
export type { IdentKind } from "./ident/fold.js";
|
package/dist/api.js
CHANGED
|
@@ -205,11 +205,18 @@ export { LineIndex } from "./document/line-index.js";
|
|
|
205
205
|
// Scope-aware completion over a SqlDocument — the broken-input editor feature (keywords + schema
|
|
206
206
|
// tables/columns + function names at the caret). Total: never throws.
|
|
207
207
|
export { complete, completeAt } from "./completion/complete.js";
|
|
208
|
+
// The NEUTRAL half of jinja completion: which call + arg slot the caret sits in inside a jinja tag
|
|
209
|
+
// (`{{ ref('cu│` → { callee: "ref", argIndex: 0, prefix: "cu" }). Carries no dbt vocabulary; a
|
|
210
|
+
// consumer maps callee + argIndex to a role and supplies candidates. Reuses the parsed tags.
|
|
211
|
+
export { jinjaSlotAt } from "./completion/jinja-slot.js";
|
|
208
212
|
// Signature help over a SqlDocument — the broken-input editor feature that shows parameter hints
|
|
209
|
-
// while typing inside a call's parens.
|
|
210
|
-
// long tail,
|
|
213
|
+
// while typing inside a call's parens. SIGNATURES is the merged per-dialect table (curated overrides
|
|
214
|
+
// folded over the harvested doc-derived long tail at generation time, tools/harvest-signatures.mjs);
|
|
215
|
+
// a name maps to an overload SET (readonly FnSignature[]), not a single shape: it is common for a
|
|
216
|
+
// builtin to be overloaded on argument type or arity. An unknown name degrades to a one-entry
|
|
217
|
+
// name-only fallback. A pure token scan; never throws.
|
|
211
218
|
export { signatureAt } from "./signature/signature.js";
|
|
212
|
-
export {
|
|
219
|
+
export { SIGNATURES, lookupSignature, hasSignature } from "./signature/signatures.js";
|
|
213
220
|
// References / occurrence engine — find the declaration + every occurrence of the symbol under a
|
|
214
221
|
// cursor offset. The core primitive behind LSP references / documentHighlight / codeLens / rename.
|
|
215
222
|
// Total: never throws; returns null off-symbol.
|
|
@@ -228,4 +235,4 @@ export { DERIVED_DIALECTS, resolveDialect } from "./derived-dialects.js";
|
|
|
228
235
|
// The dialect-true identifier fold — the identity key for name comparison (unquote + case-fold per
|
|
229
236
|
// the dialect's documented rules) and its display twin (unquote only). Exported so an embedding
|
|
230
237
|
// consumer comparing names against IR/scope output folds the same way the pipeline does.
|
|
231
|
-
export { foldIdentifier, displayName } from "./
|
|
238
|
+
export { foldIdentifier, displayName } from "./dialect-behavior/public-fold.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { acceptsFor } from "../dialect-behavior/coerce-rules.js";
|
|
2
|
+
import { likePatternToRegExp } from "../scope/like-pattern.js";
|
|
3
|
+
import { SIGNATURES } from "../signature/signatures.js";
|
|
4
|
+
import { displayName, fold, foldTableName, matchesSourceKey } from "./fold.js";
|
|
5
|
+
import { bigqueryLiteral, bigqueryParseType, bigquerySpecial, BIGQUERY_FUNCTION_RETURNS } from "./infer.js";
|
|
6
|
+
export const bigqueryBehavior = {
|
|
7
|
+
fold,
|
|
8
|
+
displayName,
|
|
9
|
+
foldTableName,
|
|
10
|
+
matchesSourceKey,
|
|
11
|
+
likeMatch: (pattern, value) => likePatternToRegExp(pattern).test(value),
|
|
12
|
+
literal: bigqueryLiteral,
|
|
13
|
+
parseType: bigqueryParseType,
|
|
14
|
+
functions: BIGQUERY_FUNCTION_RETURNS,
|
|
15
|
+
division: "float",
|
|
16
|
+
special: bigquerySpecial,
|
|
17
|
+
signatures: SIGNATURES.bigquery,
|
|
18
|
+
// BigQuery implicit coercion: no STRING->NUMBER coercion, no BOOL<->NUMBER coercion (STR_TO_NUM=false, BOOL_NUM=false).
|
|
19
|
+
accepts: (argType, paramText) => acceptsFor(bigqueryParseType, false, false, argType, paramText),
|
|
20
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type Lexer, ListTokenSource } from "antlr4ng";
|
|
2
|
-
import { GoogleSQLLexer } from "../generated/bigquery/GoogleSQLLexer.js";
|
|
3
2
|
import type { SyntaxDiagnostic } from "../parse-diagnostics.js";
|
|
4
3
|
/**
|
|
5
4
|
* Lex `sql` and return a token source with the DOT_IDENTIFIER rewrite applied, plus positioned
|
|
@@ -11,4 +10,3 @@ export declare function dotPathTokenSource(sql: string, lexer: Lexer): {
|
|
|
11
10
|
source: ListTokenSource;
|
|
12
11
|
escapeDiagnostics: SyntaxDiagnostic[];
|
|
13
12
|
};
|
|
14
|
-
export { GoogleSQLLexer };
|
|
@@ -365,4 +365,3 @@ export function dotPathTokenSource(sql, lexer) {
|
|
|
365
365
|
const tokens = lexer.getAllTokens(); // full lex (drives lexer error listeners); EOF excluded
|
|
366
366
|
return { source: new ListTokenSource(rewriteDotPaths(tokens)), escapeDiagnostics: badLiteralEscapes(tokens) };
|
|
367
367
|
}
|
|
368
|
-
export { GoogleSQLLexer };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FoldRule, type IdentKind } from "../ident/fold.js";
|
|
2
|
+
export declare const BIGQUERY_FOLD_RULE: FoldRule;
|
|
3
|
+
/** Fold an identifier to its BigQuery identity key. */
|
|
4
|
+
export declare function fold(raw: string, kind?: IdentKind): string;
|
|
5
|
+
/** Presentation twin: strip delimiters, no case change. */
|
|
6
|
+
export declare function displayName(raw: string): string;
|
|
7
|
+
export declare function foldTableName(parts: string[]): string[];
|
|
8
|
+
export declare function matchesSourceKey(key: string, rawPart: string): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// BigQuery identifier folding. The FoldRule plus its bound engine, colocated here because BOTH the
|
|
2
|
+
// upstream lower() and the downstream DialectBehavior need it (the fold rule is the one dialect concern
|
|
3
|
+
// used at two stages).
|
|
4
|
+
//
|
|
5
|
+
// cloud.google.com/bigquery/docs/reference/standard-sql/lexical — verified live (via search,
|
|
6
|
+
// the JS-rendered page would not return body text to WebFetch): "table names are case-sensitive,
|
|
7
|
+
// but column names are not" — so table identifiers preserve case and everything else (column,
|
|
8
|
+
// field, alias, CTE) folds to lower, REGARDLESS of backtick-quoting either way (backticks are
|
|
9
|
+
// required for reserved words/specials, not a case-quoting mechanism — same "not case-quoting"
|
|
10
|
+
// shape as Databricks, but the preserved/folded split is per identifier KIND here, not
|
|
11
|
+
// per-quoting). Escape mechanism corrected from the originally assumed doubling: "Quoted
|
|
12
|
+
// identifiers have the same escape sequences as string literals" (backslash-escaped, e.g.
|
|
13
|
+
// `` `a\`b` `` → `` a`b ``) — NOT doubling like every other backtick/quote dialect here. This
|
|
14
|
+
// module unescapes the identifier-relevant case (`` \` ``) plus the general `\X`→`X` pattern; it
|
|
15
|
+
// does not implement BigQuery's full string-literal escape grammar (\n, \xHH, \uXXXX, octal, …),
|
|
16
|
+
// out of scope for an identifier fold — those escapes are exotic in identifier text.
|
|
17
|
+
import { displayWith, foldWith } from "../ident/fold.js";
|
|
18
|
+
const BACKTICK = ["`", "`"];
|
|
19
|
+
export const BIGQUERY_FOLD_RULE = {
|
|
20
|
+
delimiters: [BACKTICK],
|
|
21
|
+
unquoted: "lower",
|
|
22
|
+
quoted: "lower",
|
|
23
|
+
tableCase: "preserve",
|
|
24
|
+
escapeStyle: "backslash",
|
|
25
|
+
};
|
|
26
|
+
/** Fold an identifier to its BigQuery identity key. */
|
|
27
|
+
export function fold(raw, kind = "other") {
|
|
28
|
+
return foldWith(BIGQUERY_FOLD_RULE, raw, kind);
|
|
29
|
+
}
|
|
30
|
+
/** Presentation twin: strip delimiters, no case change. */
|
|
31
|
+
export function displayName(raw) {
|
|
32
|
+
return displayWith(BIGQUERY_FOLD_RULE, raw);
|
|
33
|
+
}
|
|
34
|
+
export function foldTableName(parts) {
|
|
35
|
+
return parts.map((p) => fold(p, "table"));
|
|
36
|
+
}
|
|
37
|
+
export function matchesSourceKey(key, rawPart) {
|
|
38
|
+
return key === fold(rawPart) || key === fold(rawPart, "table");
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The complete bigquery dialect module: parse + lower (front end) and behavior (semantic knowledge).
|
|
2
|
+
// The registry wires this; to understand everything sqllens does for bigquery, read this folder.
|
|
3
|
+
import { bigqueryBehavior } from "./behavior.js";
|
|
4
|
+
import { lower } from "./lower.js";
|
|
5
|
+
import { parseBigQuery } from "./parse.js";
|
|
6
|
+
export const bigquery = {
|
|
7
|
+
parse: parseBigQuery,
|
|
8
|
+
lower,
|
|
9
|
+
behavior: bigqueryBehavior,
|
|
10
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Expr } from "../ir/ir.js";
|
|
2
|
-
import type { FnRule } from "
|
|
3
|
-
import { type Type } from "
|
|
2
|
+
import type { FnRule } from "../infer/functions.js";
|
|
3
|
+
import { type Type } from "../infer/types.js";
|
|
4
4
|
export declare const BQ_ALIASES: Record<string, string>;
|
|
5
5
|
export declare function bigqueryParseType(text: string): Type;
|
|
6
6
|
export declare function bigqueryLiteral(text: string): Type;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { commonType } from "
|
|
2
|
-
import { parseType, scalar, UNKNOWN } from "
|
|
1
|
+
import { commonType } from "../infer/coerce.js";
|
|
2
|
+
import { parseType, scalar, UNKNOWN } from "../infer/types.js";
|
|
3
|
+
import { fold } from "./fold.js";
|
|
3
4
|
// BigQuery / GoogleSQL inference knowledge — function return types, literal forms, and scalar-type
|
|
4
5
|
// aliases — from the GoogleSQL function reference
|
|
5
6
|
// (cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators). Same contract as
|
|
@@ -24,7 +25,7 @@ export const BQ_ALIASES = {
|
|
|
24
25
|
geography: "geography",
|
|
25
26
|
};
|
|
26
27
|
export function bigqueryParseType(text) {
|
|
27
|
-
return parseType(text, BQ_ALIASES,
|
|
28
|
+
return parseType(text, BQ_ALIASES, fold);
|
|
28
29
|
}
|
|
29
30
|
export function bigqueryLiteral(text) {
|
|
30
31
|
const t = text.trim();
|
package/dist/bigquery/lower.js
CHANGED
|
@@ -1549,37 +1549,60 @@ function lowerFunctionCall(node) {
|
|
|
1549
1549
|
name = (keyword ? keyword.getText() : (leftmostToken(node) ?? "")).toLowerCase();
|
|
1550
1550
|
}
|
|
1551
1551
|
const suffix = directChildrenOfRule(node, P.RULE_function_call_expression_with_clauses_suffix)[0];
|
|
1552
|
-
const args = suffix ? collectCallArgs(suffix) : [];
|
|
1552
|
+
const { args, argNames } = suffix ? collectCallArgs(suffix) : { args: [], argNames: [] };
|
|
1553
1553
|
const over = suffix ? firstOfRule(suffix, P.RULE_over_clause) : undefined;
|
|
1554
1554
|
const window = over ? lowerOver(over) : undefined;
|
|
1555
1555
|
const distinct = hasDirectToken(node, P.DISTINCT_SYMBOL);
|
|
1556
|
-
return {
|
|
1556
|
+
return {
|
|
1557
|
+
kind: "function",
|
|
1558
|
+
name,
|
|
1559
|
+
qualifier,
|
|
1560
|
+
args,
|
|
1561
|
+
// Named-argument invocation `fn(name => value)`: the per-arg names make the call
|
|
1562
|
+
// conservation-visible and let the arity checker's named-arg bypass fire (a named call's
|
|
1563
|
+
// positional count says nothing about the documented positional signature).
|
|
1564
|
+
...(argNames.some((n) => n !== undefined) ? { argNames } : {}),
|
|
1565
|
+
aggregate: AGGREGATES.has(name),
|
|
1566
|
+
distinct,
|
|
1567
|
+
window,
|
|
1568
|
+
cst: node,
|
|
1569
|
+
};
|
|
1557
1570
|
}
|
|
1558
|
-
/** function_call_argument children of the suffix (skipping nested calls' own args)
|
|
1571
|
+
/** function_call_argument children of the suffix (skipping nested calls' own args), with the
|
|
1572
|
+
* `name => value` parameter name per arg slot (undefined for positional args). */
|
|
1559
1573
|
function collectCallArgs(suffix) {
|
|
1560
|
-
const
|
|
1574
|
+
const args = [];
|
|
1575
|
+
const argNames = [];
|
|
1561
1576
|
for (const arg of shallowNodesOfRule(suffix, P.RULE_function_call_argument)) {
|
|
1562
1577
|
// function_call_argument: expression alias? | named_argument | lambda_argument | sequence_arg
|
|
1563
1578
|
const named = directChildrenOfRule(arg, P.RULE_named_argument)[0];
|
|
1564
1579
|
if (named) {
|
|
1580
|
+
const argName = directChildrenOfRule(named, P.RULE_identifier)[0]?.getText();
|
|
1565
1581
|
const e = directChildrenOfRule(named, P.RULE_expression)[0];
|
|
1566
|
-
if (e)
|
|
1567
|
-
|
|
1582
|
+
if (e) {
|
|
1583
|
+
args.push(lowerExpr(e));
|
|
1584
|
+
argNames.push(argName);
|
|
1585
|
+
}
|
|
1568
1586
|
const lam = directChildrenOfRule(named, P.RULE_lambda_argument)[0];
|
|
1569
|
-
if (lam)
|
|
1570
|
-
|
|
1587
|
+
if (lam) {
|
|
1588
|
+
args.push(lowerLambda(lam));
|
|
1589
|
+
argNames.push(argName);
|
|
1590
|
+
}
|
|
1571
1591
|
continue;
|
|
1572
1592
|
}
|
|
1573
1593
|
const lambda = directChildrenOfRule(arg, P.RULE_lambda_argument)[0];
|
|
1574
1594
|
if (lambda) {
|
|
1575
|
-
|
|
1595
|
+
args.push(lowerLambda(lambda));
|
|
1596
|
+
argNames.push(undefined);
|
|
1576
1597
|
continue;
|
|
1577
1598
|
}
|
|
1578
1599
|
const e = directChildrenOfRule(arg, P.RULE_expression)[0];
|
|
1579
|
-
if (e)
|
|
1580
|
-
|
|
1600
|
+
if (e) {
|
|
1601
|
+
args.push(lowerExpr(e));
|
|
1602
|
+
argNames.push(undefined);
|
|
1603
|
+
}
|
|
1581
1604
|
}
|
|
1582
|
-
return
|
|
1605
|
+
return { args, argNames };
|
|
1583
1606
|
}
|
|
1584
1607
|
/** lambda_argument: lambda_argument_list -> expression. */
|
|
1585
1608
|
function lowerLambda(node) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FnSignature } from "../signature/signatures.js";
|
|
2
|
+
/** The merged function-signature table for bigquery: curated overrides folded over the harvested
|
|
3
|
+
* doc-derived long tail (overrides win by key, replacing the whole overload set), keyed by
|
|
4
|
+
* lowercased name. Each name maps to an ORDERED overload set - a name with one documented shape
|
|
5
|
+
* is a one-element array. `origin` says which layer produced the set. */
|
|
6
|
+
export declare const BIGQUERY_SIGNATURES: Record<string, FnSignature[]>;
|