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.
Files changed (234) hide show
  1. package/README.md +2 -74
  2. package/THIRD-PARTY-NOTICES.md +50 -5
  3. package/dist/api.d.ts +5 -3
  4. package/dist/api.js +11 -4
  5. package/dist/bigquery/behavior.d.ts +2 -0
  6. package/dist/bigquery/behavior.js +20 -0
  7. package/dist/bigquery/dot-path.d.ts +0 -2
  8. package/dist/bigquery/dot-path.js +0 -1
  9. package/dist/bigquery/fold.d.ts +8 -0
  10. package/dist/bigquery/fold.js +39 -0
  11. package/dist/bigquery/index.d.ts +7 -0
  12. package/dist/bigquery/index.js +10 -0
  13. package/dist/{infer/bigquery.d.ts → bigquery/infer.d.ts} +2 -2
  14. package/dist/{infer/bigquery.js → bigquery/infer.js} +4 -3
  15. package/dist/bigquery/lower.js +35 -12
  16. package/dist/bigquery/signatures.generated.d.ts +6 -0
  17. package/dist/bigquery/signatures.generated.js +1068 -0
  18. package/dist/completion/atn-walk.d.ts +13 -2
  19. package/dist/completion/atn-walk.js +13 -10
  20. package/dist/completion/complete.d.ts +4 -3
  21. package/dist/completion/complete.js +101 -45
  22. package/dist/completion/jinja-slot.d.ts +24 -0
  23. package/dist/completion/jinja-slot.js +126 -0
  24. package/dist/completion/parser-factory.d.ts +13 -1
  25. package/dist/completion/parser-factory.js +12 -0
  26. package/dist/databricks/behavior.d.ts +2 -0
  27. package/dist/databricks/behavior.js +19 -0
  28. package/dist/databricks/fold.d.ts +8 -0
  29. package/dist/databricks/fold.js +27 -0
  30. package/dist/databricks/index.d.ts +7 -0
  31. package/dist/databricks/index.js +10 -0
  32. package/dist/databricks/infer.d.ts +6 -0
  33. package/dist/databricks/infer.js +638 -0
  34. package/dist/databricks/signatures.generated.d.ts +6 -0
  35. package/dist/databricks/signatures.generated.js +1745 -0
  36. package/dist/dialect-behavior/behavior.d.ts +26 -0
  37. package/dist/dialect-behavior/behavior.js +1 -0
  38. package/dist/dialect-behavior/carrier.d.ts +5 -0
  39. package/dist/dialect-behavior/carrier.js +5 -0
  40. package/dist/dialect-behavior/coerce-rules.d.ts +7 -0
  41. package/dist/dialect-behavior/coerce-rules.js +69 -0
  42. package/dist/dialect-behavior/public-fold.d.ts +6 -0
  43. package/dist/dialect-behavior/public-fold.js +9 -0
  44. package/dist/dialect-behavior/registry.d.ts +6 -0
  45. package/dist/dialect-behavior/registry.js +34 -0
  46. package/dist/dialect-symbols.js +16 -19
  47. package/dist/document/document.d.ts +1 -1
  48. package/dist/document/document.js +8 -7
  49. package/dist/duckdb/behavior.d.ts +2 -0
  50. package/dist/duckdb/behavior.js +21 -0
  51. package/dist/duckdb/fold.d.ts +8 -0
  52. package/dist/duckdb/fold.js +29 -0
  53. package/dist/duckdb/index.d.ts +7 -0
  54. package/dist/duckdb/index.js +10 -0
  55. package/dist/{infer/duckdb.d.ts → duckdb/infer.d.ts} +2 -2
  56. package/dist/{infer/duckdb.js → duckdb/infer.js} +4 -3
  57. package/dist/duckdb/lower.js +47 -15
  58. package/dist/duckdb/signatures.generated.d.ts +6 -0
  59. package/dist/duckdb/signatures.generated.js +1072 -0
  60. package/dist/generated/bigquery/GoogleSQLParser.js +0 -7060
  61. package/dist/generated/databricks/DatabricksParser.js +0 -4800
  62. package/dist/generated/duckdb/DuckdbParser.js +0 -9100
  63. package/dist/generated/minijinja/MinijinjaParser.js +0 -380
  64. package/dist/generated/mysql/MysqlParser.js +0 -6330
  65. package/dist/generated/postgres/PostgresParser.js +0 -8530
  66. package/dist/generated/redshift/RedshiftParser.js +0 -10970
  67. package/dist/generated/snowflake/SnowflakeParser.js +0 -7320
  68. package/dist/generated/sqlite/SqliteParser.js +0 -1150
  69. package/dist/generated/trino/TrinoParser.js +0 -3770
  70. package/dist/generated/tsql/TSqlParser.js +0 -8420
  71. package/dist/ident/fold.d.ts +24 -15
  72. package/dist/ident/fold.js +12 -194
  73. package/dist/index.d.ts +2 -2
  74. package/dist/index.js +10 -8
  75. package/dist/infer/functions.d.ts +22 -11
  76. package/dist/infer/functions.js +26 -888
  77. package/dist/infer/infer.js +16 -14
  78. package/dist/infer/nullability.js +3 -4
  79. package/dist/infer/types.d.ts +1 -1
  80. package/dist/infer/types.js +7 -7
  81. package/dist/ir/ir.d.ts +26 -17
  82. package/dist/ir/span.js +0 -2
  83. package/dist/ir/walk.js +3 -3
  84. package/dist/lineage/hops.js +13 -10
  85. package/dist/lineage/lineage.js +10 -7
  86. package/dist/minijinja/apply-tags.d.ts +14 -7
  87. package/dist/minijinja/apply-tags.js +66 -121
  88. package/dist/minijinja/parse.js +5 -5
  89. package/dist/minijinja/tag-ast.d.ts +29 -36
  90. package/dist/minijinja/tag-ast.js +210 -90
  91. package/dist/mysql/behavior.d.ts +2 -0
  92. package/dist/mysql/behavior.js +21 -0
  93. package/dist/mysql/fold.d.ts +8 -0
  94. package/dist/mysql/fold.js +49 -0
  95. package/dist/mysql/index.d.ts +7 -0
  96. package/dist/mysql/index.js +10 -0
  97. package/dist/{infer/mysql.d.ts → mysql/infer.d.ts} +2 -2
  98. package/dist/{infer/mysql.js → mysql/infer.js} +3 -2
  99. package/dist/mysql/signatures.generated.d.ts +6 -0
  100. package/dist/mysql/signatures.generated.js +508 -0
  101. package/dist/postgres/behavior.d.ts +2 -0
  102. package/dist/postgres/behavior.js +19 -0
  103. package/dist/postgres/fold.d.ts +8 -0
  104. package/dist/postgres/fold.js +30 -0
  105. package/dist/postgres/index.d.ts +7 -0
  106. package/dist/postgres/index.js +10 -0
  107. package/dist/{infer/postgres.d.ts → postgres/infer.d.ts} +2 -2
  108. package/dist/{infer/postgres.js → postgres/infer.js} +4 -3
  109. package/dist/postgres/lower.js +2 -2
  110. package/dist/postgres/signatures.generated.d.ts +6 -0
  111. package/dist/postgres/signatures.generated.js +2973 -0
  112. package/dist/qualify/check-calls.js +80 -161
  113. package/dist/qualify/qualify.js +16 -14
  114. package/dist/qualify/schema-provider.js +2 -2
  115. package/dist/qualify/schema.js +3 -3
  116. package/dist/qualify/template-provider.d.ts +45 -12
  117. package/dist/qualify/template-provider.js +69 -38
  118. package/dist/redshift/behavior.d.ts +2 -0
  119. package/dist/redshift/behavior.js +19 -0
  120. package/dist/redshift/fold.d.ts +8 -0
  121. package/dist/redshift/fold.js +31 -0
  122. package/dist/redshift/index.d.ts +7 -0
  123. package/dist/redshift/index.js +10 -0
  124. package/dist/{infer/redshift.d.ts → redshift/infer.d.ts} +2 -2
  125. package/dist/{infer/redshift.js → redshift/infer.js} +4 -3
  126. package/dist/redshift/lower.js +2 -2
  127. package/dist/redshift/signatures.generated.d.ts +6 -0
  128. package/dist/redshift/signatures.generated.js +757 -0
  129. package/dist/references/references.js +17 -12
  130. package/dist/scope/like-pattern.d.ts +2 -0
  131. package/dist/scope/like-pattern.js +15 -0
  132. package/dist/scope/scope.d.ts +5 -5
  133. package/dist/scope/scope.js +48 -42
  134. package/dist/sema/resolve.js +17 -12
  135. package/dist/session.d.ts +2 -2
  136. package/dist/signature/signature.d.ts +14 -6
  137. package/dist/signature/signature.js +30 -22
  138. package/dist/signature/signatures.d.ts +14 -12
  139. package/dist/signature/signatures.js +42 -721
  140. package/dist/snowflake/behavior.d.ts +2 -0
  141. package/dist/snowflake/behavior.js +22 -0
  142. package/dist/snowflake/fold.d.ts +8 -0
  143. package/dist/snowflake/fold.js +25 -0
  144. package/dist/snowflake/index.d.ts +7 -0
  145. package/dist/snowflake/index.js +10 -0
  146. package/dist/{infer/snowflake.d.ts → snowflake/infer.d.ts} +2 -2
  147. package/dist/{infer/snowflake.js → snowflake/infer.js} +4 -3
  148. package/dist/snowflake/lower.js +59 -19
  149. package/dist/snowflake/signatures.generated.d.ts +6 -0
  150. package/dist/snowflake/signatures.generated.js +2080 -0
  151. package/dist/sqlite/behavior.d.ts +2 -0
  152. package/dist/sqlite/behavior.js +19 -0
  153. package/dist/sqlite/fold.d.ts +8 -0
  154. package/dist/sqlite/fold.js +41 -0
  155. package/dist/sqlite/index.d.ts +7 -0
  156. package/dist/sqlite/index.js +10 -0
  157. package/dist/{infer/sqlite.d.ts → sqlite/infer.d.ts} +2 -2
  158. package/dist/{infer/sqlite.js → sqlite/infer.js} +4 -3
  159. package/dist/sqlite/signatures.generated.d.ts +6 -0
  160. package/dist/sqlite/signatures.generated.js +277 -0
  161. package/dist/symbols/symbols.js +14 -12
  162. package/dist/trino/behavior.d.ts +2 -0
  163. package/dist/trino/behavior.js +21 -0
  164. package/dist/trino/fold.d.ts +8 -0
  165. package/dist/trino/fold.js +39 -0
  166. package/dist/trino/index.d.ts +7 -0
  167. package/dist/trino/index.js +10 -0
  168. package/dist/{infer/trino.d.ts → trino/infer.d.ts} +2 -2
  169. package/dist/{infer/trino.js → trino/infer.js} +4 -3
  170. package/dist/trino/lower.js +5 -5
  171. package/dist/trino/signatures.generated.d.ts +6 -0
  172. package/dist/trino/signatures.generated.js +968 -0
  173. package/dist/tsql/behavior.d.ts +2 -0
  174. package/dist/tsql/behavior.js +20 -0
  175. package/dist/tsql/fold.d.ts +8 -0
  176. package/dist/tsql/fold.js +34 -0
  177. package/dist/tsql/index.d.ts +7 -0
  178. package/dist/tsql/index.js +10 -0
  179. package/dist/tsql/infer.d.ts +16 -0
  180. package/dist/tsql/infer.js +289 -0
  181. package/dist/tsql/lower.js +4 -4
  182. package/dist/tsql/signatures.generated.d.ts +6 -0
  183. package/dist/tsql/signatures.generated.js +640 -0
  184. package/package.json +5 -10
  185. package/dist/generated/bigquery/GoogleSQLLexer.d.ts +0 -407
  186. package/dist/generated/bigquery/GoogleSQLParser.d.ts +0 -9558
  187. package/dist/generated/bigquery/GoogleSQLParserListener.d.ts +0 -7777
  188. package/dist/generated/bigquery/GoogleSQLParserListener.js +0 -7070
  189. package/dist/generated/databricks/DatabricksLexer.d.ts +0 -566
  190. package/dist/generated/databricks/DatabricksParser.d.ts +0 -7771
  191. package/dist/generated/databricks/DatabricksParserListener.d.ts +0 -5737
  192. package/dist/generated/databricks/DatabricksParserListener.js +0 -5256
  193. package/dist/generated/duckdb/DuckdbLexer.d.ts +0 -691
  194. package/dist/generated/duckdb/DuckdbParser.d.ts +0 -13932
  195. package/dist/generated/duckdb/DuckdbParserListener.d.ts +0 -10049
  196. package/dist/generated/duckdb/DuckdbParserListener.js +0 -9138
  197. package/dist/generated/minijinja/MinijinjaLexer.d.ts +0 -108
  198. package/dist/generated/minijinja/MinijinjaParser.d.ts +0 -604
  199. package/dist/generated/minijinja/MinijinjaParserListener.d.ts +0 -449
  200. package/dist/generated/minijinja/MinijinjaParserListener.js +0 -410
  201. package/dist/generated/mysql/MysqlLexer.d.ts +0 -1198
  202. package/dist/generated/mysql/MysqlParser.d.ts +0 -10992
  203. package/dist/generated/mysql/MysqlParserListener.d.ts +0 -7592
  204. package/dist/generated/mysql/MysqlParserListener.js +0 -6958
  205. package/dist/generated/postgres/PostgresLexer.d.ts +0 -663
  206. package/dist/generated/postgres/PostgresParser.d.ts +0 -12963
  207. package/dist/generated/postgres/PostgresParserListener.d.ts +0 -9408
  208. package/dist/generated/postgres/PostgresParserListener.js +0 -8554
  209. package/dist/generated/redshift/RedshiftLexer.d.ts +0 -954
  210. package/dist/generated/redshift/RedshiftParser.d.ts +0 -16939
  211. package/dist/generated/redshift/RedshiftParserListener.d.ts +0 -12092
  212. package/dist/generated/redshift/RedshiftParserListener.js +0 -10994
  213. package/dist/generated/snowflake/SnowflakeLexer.d.ts +0 -1046
  214. package/dist/generated/snowflake/SnowflakeParser.d.ts +0 -14196
  215. package/dist/generated/snowflake/SnowflakeParserListener.d.ts +0 -8063
  216. package/dist/generated/snowflake/SnowflakeParserListener.js +0 -7330
  217. package/dist/generated/sqlite/SqliteLexer.d.ts +0 -210
  218. package/dist/generated/sqlite/SqliteParser.d.ts +0 -2115
  219. package/dist/generated/sqlite/SqliteParserListener.d.ts +0 -1276
  220. package/dist/generated/sqlite/SqliteParserListener.js +0 -1160
  221. package/dist/generated/trino/TrinoLexer.d.ts +0 -381
  222. package/dist/generated/trino/TrinoParser.d.ts +0 -5340
  223. package/dist/generated/trino/TrinoParserListener.d.ts +0 -4704
  224. package/dist/generated/trino/TrinoParserListener.js +0 -4326
  225. package/dist/generated/tsql/TSqlLexer.d.ts +0 -1278
  226. package/dist/generated/tsql/TSqlParser.d.ts +0 -17267
  227. package/dist/generated/tsql/TSqlParserListener.d.ts +0 -9697
  228. package/dist/generated/tsql/TSqlParserListener.js +0 -8854
  229. package/dist/infer/dialect.d.ts +0 -21
  230. package/dist/infer/dialect.js +0 -100
  231. package/dist/infer/literals.d.ts +0 -6
  232. package/dist/infer/literals.js +0 -44
  233. package/dist/signature/generated/tsql.d.ts +0 -3
  234. 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). An LSP
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, { dialect: "snowflake" }); // idempotent lift
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
@@ -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 { signatureAt, type SignatureInfo } from "./signature/signature.js";
121
- export { FUNCTION_SIGNATURES, HARVESTED_SIGNATURES, lookupSignature, hasSignature, type FnSignature, type ParamSig, } from "./signature/signatures.js";
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, type IdentKind } from "./ident/fold.js";
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. Lookup order: curated (hand-verified) harvested (doc-derived
210
- // long tail, from tools/harvest-signatures.mjs) → name-only fallback. A pure token scan; never throws.
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 { FUNCTION_SIGNATURES, HARVESTED_SIGNATURES, lookupSignature, hasSignature, } from "./signature/signatures.js";
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 "./ident/fold.js";
238
+ export { foldIdentifier, displayName } from "./dialect-behavior/public-fold.js";
@@ -0,0 +1,2 @@
1
+ import type { DialectBehavior } from "../dialect-behavior/behavior.js";
2
+ export declare const bigqueryBehavior: DialectBehavior;
@@ -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,7 @@
1
+ import { lower } from "./lower.js";
2
+ import { parseBigQuery } from "./parse.js";
3
+ export declare const bigquery: {
4
+ parse: typeof parseBigQuery;
5
+ lower: typeof lower;
6
+ behavior: import("../dialect-behavior/behavior.js").DialectBehavior;
7
+ };
@@ -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 "./functions.js";
3
- import { type Type } from "./types.js";
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 "./coerce.js";
2
- import { parseType, scalar, UNKNOWN } from "./types.js";
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, "bigquery");
28
+ return parseType(text, BQ_ALIASES, fold);
28
29
  }
29
30
  export function bigqueryLiteral(text) {
30
31
  const t = text.trim();
@@ -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 { kind: "function", name, qualifier, args, aggregate: AGGREGATES.has(name), distinct, window, cst: node };
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 out = [];
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
- out.push(lowerExpr(e));
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
- out.push(lowerLambda(lam));
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
- out.push(lowerLambda(lambda));
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
- out.push(lowerExpr(e));
1600
+ if (e) {
1601
+ args.push(lowerExpr(e));
1602
+ argNames.push(undefined);
1603
+ }
1581
1604
  }
1582
- return out;
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[]>;