@prisma-next/language-server 0.14.0-dev.46 → 0.14.0-dev.48

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 CHANGED
@@ -11,7 +11,7 @@ Supported capabilities are intentionally narrow: parse diagnostics, whole-docume
11
11
  ## Responsibilities
12
12
 
13
13
  - Resolve workspace/project configuration for open PSL documents and keep managed projects aligned with config-file changes.
14
- - Publish parse diagnostics and serve whole-document formatting, folding ranges, full/range semantic tokens, and model field type completion for configured PSL inputs.
14
+ - Serve parse diagnostics (LSP 3.17 pull with push fallback) plus whole-document formatting, folding ranges, full/range semantic tokens, and model field type completion for configured PSL inputs.
15
15
  - Preserve parser artifacts per project so editor features share the same AST, source-file, and symbol-table lifecycle instead of reparsing through feature-specific paths.
16
16
  - Fail safely for unsupported documents, missing or closed buffers, config-load failures, malformed inputs, and oversized semantic-token requests.
17
17
 
@@ -25,14 +25,14 @@ Supported capabilities are intentionally narrow: parse diagnostics, whole-docume
25
25
 
26
26
  ## How it works
27
27
 
28
- 1. **`initialize`** — resolves the workspace root from the client's `rootUri` and registers config-file watching when the client supports it. The server advertises incremental text sync, whole-document formatting, folding ranges, and `semanticTokensProvider` with a stable standard-only legend, `full: true`, and `range: true`. Configs are loaded when matching documents open or when watched config files change. If a config cannot be loaded, the server does not manage that project.
29
- 2. **Document sync** — text-document sync is **incremental** (`TextDocumentSyncKind.Incremental`); the `TextDocuments` manager applies incremental edits, and the server re-parses the full current buffer on each change.
30
- 3. **Diagnostics** — on `didOpen` / `didChange` of a document whose URI is a configured PSL input, the server runs `@prisma-next/psl-parser`'s `parse()` (the CST path) and `buildSymbolTable()`, then publishes the merged, mapped diagnostics via `textDocument/publishDiagnostics`. A clean document publishes an empty array (clearing markers). Documents that are not configured inputs publish nothing.
28
+ 1. **`initialize`** — resolves the workspace root from the client's `rootUri` and registers config-file watching when the client supports it. The server advertises incremental text sync, whole-document formatting, folding ranges, and `semanticTokensProvider` with a stable standard-only legend, `full: true`, and `range: true`. When the client advertises `textDocument.diagnostic`, the server also advertises `diagnosticProvider` with `{ interFileDependencies: false, workspaceDiagnostics: false }` — flags that describe the current single-input implementation scope, not PSL itself. Configs are loaded when matching documents open, on the first read that needs them, or when watched config files change. If a config cannot be loaded, the server does not manage that project.
29
+ 2. **Document sync** — text-document sync is **incremental** (`TextDocumentSyncKind.Incremental`); the `TextDocuments` manager applies incremental edits, and each open or change is forwarded to the project's artifact store as a document-changed event. The server parses the full current buffer at most once per change, when a read (diagnostic pull, completion, semantic tokens, folding, or a push publish) next needs the document's artifacts.
30
+ 3. **Diagnostics** — served over exactly one transport per client, decided at `initialize`. For clients that advertise `textDocument.diagnostic` (pull), `didOpen` / `didChange` only invalidate the artifact store is only told the document changed and no eager work runs; a `textDocument/diagnostic` request reads the document artifacts from the store, which parses the current buffer internally when needed (running `@prisma-next/psl-parser`'s `parse()` and `buildSymbolTable()` once per change) and returns a full report with the merged, mapped diagnostics. Documents that are not configured inputs, or whose project cannot load, return an empty full report. On a config-file change the server reloads the project and asks the client to re-pull via `workspace/diagnostic/refresh` when the client advertises `workspace.diagnostics.refreshSupport`, instead of republishing. For clients without pull support, the previous push behavior is preserved: the server computes on `didOpen` / `didChange` and publishes via `textDocument/publishDiagnostics` (a clean document publishes an empty array, clearing markers; unconfigured documents publish nothing), and config changes republish affected open documents. The report builder is project-scoped so a future multi-input symbol table can attach `relatedDocuments`; today reports carry only the requested document's items.
31
31
  4. **Formatting** — on `textDocument/formatting`, the server formats the current in-memory document text with `@prisma-next/psl-parser/format` when the document is a configured PSL input. It returns one whole-document edit when the formatted text differs, and returns no edits for missing or closed documents, unconfigured documents, already canonical text, malformed PSL, or invalid formatter options.
32
- 5. **Folding ranges** — on `textDocument/foldingRange`, the server reads the preserved document AST for the configured input and returns foldable declaration/block ranges. Missing, unconfigured, or not-yet-parsed documents return an empty result.
33
- 6. **Semantic tokens** — on `textDocument/semanticTokens/full` and `textDocument/semanticTokens/range`, the server reads the current preserved `DocumentAst`, `SourceFile`, project `SymbolTable`, and control-stack scalar types from the same `ProjectArtifacts` lifecycle used by diagnostics. It classifies PSL keywords, declaration names, field/property names, type references, attributes, strings, numbers, booleans, and comments into standard token types/modifiers, then encodes them as LSP five-integer relative semantic-token data. The range request filters to intersecting tokens before encoding. Unconfigured, missing, closed, config-resolution-failed, oversized, or stale documents return `{ data: [] }` instead of throwing or reparsing through a semantic-token-specific path. Malformed PSL returns best-effort tokens from parser recovery when artifacts are available.
32
+ 5. **Folding ranges** — on `textDocument/foldingRange`, the server reads the current document artifacts from the project store for the configured input and returns foldable declaration/block ranges. Missing or unconfigured documents return an empty result.
33
+ 6. **Semantic tokens** — on `textDocument/semanticTokens/full` and `textDocument/semanticTokens/range`, the server reads the current preserved `DocumentAst`, `SourceFile`, project `SymbolTable`, and control-stack scalar types from the same `ProjectArtifacts` lifecycle used by diagnostics. It classifies PSL keywords, declaration names, field/property names, type references, attributes, strings, numbers, booleans, and comments into standard token types/modifiers, then encodes them as LSP five-integer relative semantic-token data. The range request filters to intersecting tokens before encoding. Unconfigured, missing, closed, config-resolution-failed, or oversized documents return `{ data: [] }` instead of throwing; the store parses the current buffer internally before returning artifacts, so tokens never derive from an out-of-date parse. Malformed PSL returns best-effort tokens from parser recovery when artifacts are available.
34
34
  7. **Completion** — on `textDocument/completion`, the server serves configured PSL model field type positions, descriptor-backed generic block parameter-key positions, and declaration keyword positions from cached parse artifacts. It classifies the cursor using the cached AST/source file, reads the current project symbol table plus project control-stack block descriptors, threads the client's snippet capability into declaration keyword item construction, and returns `[]` for missing or closed documents, unconfigured documents, unavailable artifacts, unsupported contexts, ordinary attributes or attribute arguments, generic block parameter values, generic block value positions, relation-aware scenarios, and external contract-space discovery gaps.
35
- 8. **Preserved artifacts** — each project keeps the parse artifacts it produces: the AST per open document (keyed by URI) and one symbol table per project, rebuilt from the open configured input on each edit and dropped when the document closes. Diagnostics populate these artifacts, and folding/semantic-token/completion handlers read them instead of constructing independent parse/token caches. They are exposed through `getDocumentAst` / `getProjectSymbolTable` for future features. Filling the project table from several inputs — and reading unopened inputs from disk — is deferred cross-file work.
35
+ 8. **Project artifact store** — each project load constructs one artifact store with the config's inputs, control stack, and a text provider over the open-document mirror. The store returns the AST, `SourceFile`, and diagnostics per open configured input plus one project symbol table, parsing internally when a read needs them; document-changed/closed events (edits, closes) and store replacement on config reload are the only things that change what reads return. The artifacts are exposed through `getDocumentAst` / `getProjectSymbolTable` for future features. Filling the project table from several inputs — and reading unopened inputs from disk — is deferred cross-file work.
36
36
 
37
37
  ## Module layout
38
38
 
@@ -40,7 +40,7 @@ Supported capabilities are intentionally narrow: parse diagnostics, whole-docume
40
40
  - `schema-inputs.ts` — resolves the schema-input set (`SchemaInputSet`) from a config and answers URI membership.
41
41
  - `config-resolution.ts` — wraps `loadConfig` and resolves schema inputs, formatter options, and control-stack inputs for a config. A standalone async function so it can be re-run on a config change without rewiring the server.
42
42
  - `document-diagnostics.ts` — `computeDocumentDiagnostics(uri, text, inputs, controlStack)`, the pure seam that parses, builds the symbol table, and returns the diagnostics plus the parse artifacts.
43
- - `project-artifacts.ts` — `createProjectArtifacts()`, the per-project store that preserves the per-URI ASTs and the single project symbol table across edits.
43
+ - `project-artifacts.ts` — `createProjectArtifacts({ inputs, controlStack, getText })`, the per-project-load store that owns document artifacts and the project symbol table, parsing on demand and responding to document-changed/closed events.
44
44
  - `folding-ranges.ts` — pure AST-to-LSP folding-range computation for declaration/block bodies.
45
45
  - `semantic-tokens.ts` — pure PSL semantic-token collection, range filtering, multiline normalization, duplicate resolution, modifier bitset encoding, and LSP semantic-token data encoding.
46
46
  - `completion-context.ts` — pure cursor classifier for PSL completion contexts, currently routing model field type positions, descriptor-backed generic block parameter-key positions, and declaration keyword positions while marking everything outside slice scope unsupported.
@@ -18,10 +18,10 @@ interface LspDiagnostic {
18
18
  declare function mapParseDiagnostics(diagnostics: readonly ParseDiagnostic[]): readonly LspDiagnostic[];
19
19
  //#endregion
20
20
  //#region src/project-artifacts.d.ts
21
- interface CachedDocument {
21
+ interface DocumentArtifacts {
22
22
  readonly document: DocumentAst;
23
23
  readonly sourceFile: SourceFile;
24
- readonly text: string;
24
+ readonly diagnostics: readonly LspDiagnostic[];
25
25
  }
26
26
  //#endregion
27
27
  //#region src/server.d.ts
@@ -31,7 +31,7 @@ interface LanguageServer {
31
31
  * Exposed for future features (completion, semantic tokens); nothing consumes
32
32
  * them yet.
33
33
  */
34
- getDocumentAst(uri: string): CachedDocument | undefined;
34
+ getDocumentAst(uri: string): DocumentArtifacts | undefined;
35
35
  getProjectSymbolTable(uri: string): SymbolTable | undefined;
36
36
  }
37
37
  declare function createServer(connection: Connection): LanguageServer;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/diagnostic-mapping.ts","../../src/project-artifacts.ts","../../src/server.ts","../../src/start-server.ts"],"mappings":";;;;;cAEa,uBAAA;EAAA;;;;;UAOI,aAAA;EAAA,SACN,KAAA,EAAO,KAAK;EAAA,SACZ,OAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA;AAAA;AAAA,iBAGK,mBAAA,CACd,WAAA,WAAsB,eAAA,cACZ,aAAa;;;UCXR,cAAA;EAAA,SACN,QAAA,EAAU,WAAA;EAAA,SACV,UAAA,EAAY,UAAU;EAAA,SACtB,IAAA;AAAA;;;UC4BM,cAAA;EACf,OAAA;;AFrCF;;;EE0CE,cAAA,CAAe,GAAA,WAAc,cAAA;EAC7B,qBAAA,CAAsB,GAAA,WAAc,WAAW;AAAA;AAAA,iBAiBjC,YAAA,CAAa,UAAA,EAAY,UAAA,GAAa,cAAc;;;iBC3DpD,WAAA,IAAe,cAAc"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/diagnostic-mapping.ts","../../src/project-artifacts.ts","../../src/server.ts","../../src/start-server.ts"],"mappings":";;;;;cAEa,uBAAA;EAAA;;;;;UAOI,aAAA;EAAA,SACN,KAAA,EAAO,KAAK;EAAA,SACZ,OAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA;AAAA;AAAA,iBAGK,mBAAA,CACd,WAAA,WAAsB,eAAA,cACZ,aAAa;;;UCXR,iBAAA;EAAA,SACN,QAAA,EAAU,WAAA;EAAA,SACV,UAAA,EAAY,UAAA;EAAA,SACZ,WAAA,WAAsB,aAAA;AAAA;;;UC+BhB,cAAA;EACf,OAAA;;AFxCF;;;EE6CE,cAAA,CAAe,GAAA,WAAc,iBAAA;EAC7B,qBAAA,CAAsB,GAAA,WAAc,WAAW;AAAA;AAAA,iBAkCjC,YAAA,CAAa,UAAA,EAAY,UAAA,GAAa,cAAc;;;iBC/EpD,WAAA,IAAe,cAAc"}