Skip to content

TML-2946: Add PSL type and generic block completions#871

Open
SevInf wants to merge 3 commits into
mainfrom
lsp-autocomplete
Open

TML-2946: Add PSL type and generic block completions#871
SevInf wants to merge 3 commits into
mainfrom
lsp-autocomplete

Conversation

@SevInf

@SevInf SevInf commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2946

At a glance

model User {
  id Int @id
}

type Address {
  street String
}

model Post {
  id Int @id
  author |
}

policy UserAccess {
  wh|
}

At the author | model field type position, textDocument/completion returns configured scalar types plus visible model/composite/type-alias candidates such as Boolean, DateTime, Int, String, Post, User, and Address, plus namespace qualifiers such as auth.. After the user types or accepts a namespace qualifier, positions like auth.| complete model/composite members inside that namespace. At descriptor-backed generic block parameter-key positions like wh|, it returns declared block parameters such as where and filters out sibling keys that already exist in the block.

Decision

This PR ships the first PSL autocomplete surfaces in @prisma-next/language-server: configured PSL model field type completions and descriptor-backed generic block parameter-key completions. It adds a typed cursor classifier over cached parser artifacts, completion providers backed by configured scalars, the current project symbol table, and the project control-stack PSL block descriptors, an LSP completion route, and README/guardrail coverage for the intentionally narrow scope.

Summary

The language server now answers completion requests for open configured PSL documents at model field type positions and descriptor-backed generic block parameter-key positions. Unsupported contexts stay empty, including ordinary PSL @ / @@ attributes, attribute arguments, generic block parameter values, unconfigured documents, relation-aware scenarios, and external contract-space discovery gaps.

Reviewer notes

  • completion-context.ts owns the cursor-context boundary: token lookup, ancestor rejection, blank model type positions, partial qualified names, generic block body/key detection, and explicit unsupported reasons.
  • Contract-space-qualified syntax is supported as syntax/filtering only. The provider uses visible namespace candidates from the cached symbol table; it does not add a new external contract-space symbol index.
  • Generic block completions are intentionally limited to descriptor-declared parameter keys. Parameter value completions for ref, option, value, or list descriptors remain out of scope.
  • projects/lsp-autocomplete/** is included for Drive traceability: it contains the project/slice specs, dispatch briefs, and trace for this project. Close-out removes/migrates project artifacts after the overall project is done.

How it fits together

  1. The classifier maps an LSP position over cached DocumentAst / SourceFile data into either a model-field-type context, a generic-block-parameter context, or an explicit unsupported reason. This keeps completion on the existing recovered CST/AST path instead of reparsing with a marker.
  2. The provider consumes that typed context and current candidates. For model field types, it returns stable LSP CompletionItems for configured scalars, top-level model/composite/scalar/type-alias symbols, bare namespace qualifier candidates such as auth., and namespace-local model/composite members only after a qualifier is present. For generic blocks, it resolves the descriptor by block keyword and returns declared parameter keys that match the typed prefix.
  3. The server advertises completionProvider and routes textDocument/completion through the same configured-input and cached-artifact ownership checks used by diagnostics/formatting, passing both the project symbol table and pslBlockDescriptors into the provider.
  4. The README and server tests pin the narrow surface so future slices can add value completions or relation-aware suggestions without accidentally turning ordinary PSL attributes into completion contexts.

Behavior changes & evidence

  • Configured PSL inputs now complete model field type positions. The server advertises completion and routes requests only after it finds an open configured document, cached parse artifacts, and a project symbol table.

    • Implementation: packages/1-framework/3-tooling/language-server/src/server.ts, packages/1-framework/3-tooling/language-server/src/completion-context.ts, packages/1-framework/3-tooling/language-server/src/completion-provider.ts
    • Evidence: packages/1-framework/3-tooling/language-server/test/server.test.ts, packages/1-framework/3-tooling/language-server/test/completion-context.test.ts, packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts
  • Descriptor-backed generic block parameter keys now complete. The classifier identifies blank and partial key positions inside GenericBlockDeclarationAst bodies, the provider resolves the matching AuthoringPslBlockDescriptor, and completions exclude already-present sibling keys.

    • Implementation: packages/1-framework/3-tooling/language-server/src/completion-context.ts, packages/1-framework/3-tooling/language-server/src/completion-provider.ts, packages/1-framework/3-tooling/language-server/src/server.ts
    • Evidence: packages/1-framework/3-tooling/language-server/test/completion-context.test.ts, packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts, packages/1-framework/3-tooling/language-server/test/server.test.ts
  • Model type candidates are stable and scoped to visible type-like symbols. The provider orders configured scalars before top-level candidates and namespace qualifiers, filters prefixes, completes namespace qualifiers such as auth. before namespace-local model names, and excludes generic block symbols from model-field-type completions.

    • Implementation: packages/1-framework/3-tooling/language-server/src/completion-provider.ts
    • Evidence: packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts
  • Qualified type positions preserve the typed shape. Bare namespace prefixes like a| replace the typed segment with auth., namespace-qualified positions like auth.U| complete only the typed member segment, and contract-space-qualified positions like supabase:auth.P| replace only the typed name segment and use currently visible candidates.

    • Implementation: packages/1-framework/3-tooling/language-server/src/completion-context.ts, packages/1-framework/3-tooling/language-server/src/completion-provider.ts
    • Evidence: packages/1-framework/3-tooling/language-server/test/completion-context.test.ts, packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts
  • Unsupported contexts return [] instead of misleading suggestions. Unconfigured documents, ordinary field/model attributes, attribute arguments, generic block parameter values, comments, constructor arguments, and other non-type/non-key positions are rejected before provider output reaches the client.

    • Implementation: packages/1-framework/3-tooling/language-server/src/completion-context.ts, packages/1-framework/3-tooling/language-server/src/server.ts
    • Evidence: packages/1-framework/3-tooling/language-server/test/server.test.ts, packages/1-framework/3-tooling/language-server/test/completion-context.test.ts
  • The supported editor surface is documented. The README now says completion is supported for configured PSL model field type positions and descriptor-backed generic block parameter-key positions, and explicitly excludes ordinary attributes, attribute arguments, generic block parameter values, relation-aware suggestions, and external contract-space discovery.

    • Implementation: packages/1-framework/3-tooling/language-server/README.md

Compatibility / migration / risk

No contract emission, runtime, migration, adapter, or public TypeScript API behavior changes are expected. The main risk is editor-surface false positives; this PR mitigates it by returning [] outside configured model field type and descriptor-backed generic block parameter-key positions.

Testing performed

  • pnpm --filter @prisma-next/framework-components build — passed; rebuilt missing local dist/ needed by language-server tests in this worktree
  • pnpm --filter @prisma-next/language-server test — 9 files / 103 tests passed
  • pnpm --filter @prisma-next/language-server typecheck — passed
  • pnpm --filter @prisma-next/language-server lint — passed, 26 files checked

Skill update

n/a — no reusable agent skill update is required. The language-server README documents the new editor-facing behavior and exclusions.

Follow-ups

  • Generic block parameter value completions can be added later by interpreting descriptor value kinds (ref, option, value, list) at the value cursor position.
  • Relation-aware field completions and external contract-space candidate discovery remain separate work.

Alternatives considered

  • Completion-marker reparsing. Rejected because the existing recovered CST/AST plus red-tree offsets are sufficient for this slice, and marker reparsing would create a second parser path to keep consistent.
  • Provider-side context rediscovery. Rejected because explicit classifier → provider dispatch makes unsupported contexts visible and keeps descriptor-backed generic-block completion from duplicating cursor analysis.
  • External contract-space candidate discovery. Rejected for this slice because the current language-server artifacts only expose visible project candidates. The syntax shape is supported, but new cross-contract indexing belongs in separate work.
  • Ordinary PSL attribute completions. Rejected for this slice because @ / @@ attributes are a different surface from descriptor-backed generic block parameters.

Checklist

  • All commits are signed off (git commit -s) per the DCO. The DCO status check will block merge if any commit is missing a Signed-off-by: trailer.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated (or n/a if the change is doc-only / refactor with no behavioural delta).
  • The PR title is in TML-NNNN: <sentence-case title> form (Linear ticket prefix + concise title naming the concrete deliverable). See .claude/skills/create-pr/SKILL.md for the full convention.
  • The Skill update section above is filled in (or stated n/a — internal only).

Summary by CodeRabbit

  • New Features
    • Added language-server code completion for Prisma PSL documents, covering model field type suggestions and supported block parameter (“where”) completions.
    • Suggestions now adapt to cursor position, typed prefixes, namespaces/contract-space qualifiers, and already-present generic keys.
  • Bug Fixes
    • Completion is withheld for unsupported contexts (for example, comments, attribute regions, and invalid type/constructor positions), returning no items instead.
  • Documentation
    • Updated language-server README with detailed completion capability scope and behavior.
  • Tests
    • Added coverage for completion context classification, completion item generation, and end-to-end server completion requests.

@SevInf SevInf requested a review from a team as a code owner June 25, 2026 13:34
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 13c39c8a-e7f9-477c-800e-006afbd3a3bc

📥 Commits

Reviewing files that changed from the base of the PR and between 6d2947a and 8ef6f1a.

⛔ Files ignored due to path filters (9)
  • projects/lsp-autocomplete/plan.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/dispatches/01-cursor-classifier-substrate.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/dispatches/02-model-type-provider.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/dispatches/03-lsp-completion-route.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/dispatches/04-scope-docs-and-final-guardrails.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/plan.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/spec.md is excluded by !projects/**
  • projects/lsp-autocomplete/spec.md is excluded by !projects/**
  • projects/lsp-autocomplete/trace.jsonl is excluded by !projects/**
📒 Files selected for processing (7)
  • packages/1-framework/3-tooling/language-server/README.md
  • packages/1-framework/3-tooling/language-server/src/completion-context.ts
  • packages/1-framework/3-tooling/language-server/src/completion-provider.ts
  • packages/1-framework/3-tooling/language-server/src/server.ts
  • packages/1-framework/3-tooling/language-server/test/completion-context.test.ts
  • packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts
  • packages/1-framework/3-tooling/language-server/test/server.test.ts
💤 Files with no reviewable changes (7)
  • packages/1-framework/3-tooling/language-server/test/completion-context.test.ts
  • packages/1-framework/3-tooling/language-server/README.md
  • packages/1-framework/3-tooling/language-server/src/server.ts
  • packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts
  • packages/1-framework/3-tooling/language-server/test/server.test.ts
  • packages/1-framework/3-tooling/language-server/src/completion-provider.ts
  • packages/1-framework/3-tooling/language-server/src/completion-context.ts

📝 Walkthrough

Walkthrough

Adds PSL completion classification, completion item generation, and LSP completion wiring to the language server. Tests cover classifier outcomes, completion item results, and server-level completion requests. README text is updated to describe the new completion scope and flow.

Changes

Prisma Next language-server completion

Layer / File(s) Summary
Completion context classification
packages/1-framework/3-tooling/language-server/src/completion-context.ts, packages/1-framework/3-tooling/language-server/test/completion-context.test.ts, packages/1-framework/3-tooling/language-server/README.md
PslCompletionContext now distinguishes model field type, generic block parameter, and unsupported cursor positions, with classifier helpers, token/AST navigation, and tests covering the returned context shapes.
Completion item generation
packages/1-framework/3-tooling/language-server/src/completion-provider.ts, packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts
providePslCompletionItems builds model field and generic block completions from scalar, symbol-table, and namespace sources, with tests covering prefixes, replacement ranges, filtering, and empty results.
Completion request wiring
packages/1-framework/3-tooling/language-server/src/server.ts, packages/1-framework/3-tooling/language-server/test/server.test.ts, packages/1-framework/3-tooling/language-server/README.md
The language server advertises completion support, resolves cached artifacts during textDocument/completion, and the server tests cover configured, unconfigured, and unsupported completion contexts.

Sequence Diagram(s)

sequenceDiagram
  participant LSPClient as LSP client
  participant Connection as connection.onCompletion
  participant CompleteDocument as completeDocument
  participant Artifacts as project.artifacts
  participant Classifier as classifyPslCompletionContext
  participant Provider as providePslCompletionItems

  LSPClient->>Connection: textDocument/completion
  Connection->>CompleteDocument: uri + position
  CompleteDocument->>Artifacts: read cached document/source and symbol table
  CompleteDocument->>Classifier: classify cursor context
  CompleteDocument->>Provider: generate completion items
  Provider-->>CompleteDocument: CompletionItem[]
  CompleteDocument-->>LSPClient: completion list or []
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • prisma/prisma-next#852: Extends the language-server setup with textDocument/completion support through the new completion context/provider pipeline.
  • prisma/prisma-next#862: Adds the project-artifacts and control-stack plumbing that the completion handler reads for cached documents and symbol tables.

Suggested reviewers

  • wmadden

Poem

A bunny hops through PSL land,
With completions gently close at hand.
Fields and blocks now bloom with choice,
And cursor whispers find their voice.
🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding PSL type and generic block completions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lsp-autocomplete

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@871

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@871

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@871

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@871

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@871

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@871

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@871

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@871

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@871

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@871

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@871

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@871

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@871

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@871

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@871

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@871

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@871

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@871

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@871

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@871

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@871

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@871

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@871

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@871

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@871

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@871

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@871

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@871

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@871

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@871

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@871

@prisma-next/config-loader

npm i https://pkg.pr.new/@prisma-next/config-loader@871

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@871

@prisma-next/language-server

npm i https://pkg.pr.new/@prisma-next/language-server@871

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@871

prisma-next

npm i https://pkg.pr.new/prisma-next@871

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@871

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@871

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@871

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@871

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@871

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@871

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@871

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@871

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@871

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@871

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@871

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@871

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@871

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@871

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@871

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@871

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@871

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@871

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@871

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@871

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@871

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@871

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@871

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@871

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@871

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@871

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@871

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@871

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@871

commit: 8ef6f1a

@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 159.43 KB (0%)
postgres / emit 146.98 KB (0%)
mongo / no-emit 78 KB (0%)
mongo / emit 72.09 KB (0%)
cf-worker / no-emit 186.89 KB (0%)
cf-worker / emit 172.89 KB (0%)

@SevInf SevInf changed the title TML-2946: Add PSL model type completions TML-2946: Add PSL type and generic block completions Jun 25, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/1-framework/3-tooling/language-server/README.md`:
- Around line 37-39: The server module description is incomplete because it only
mentions model field type completions and omits the generic-block parameter-key
completions that `createServer(connection)` also wires up. Update the
`server.ts` bullet in the README so it reflects both supported completion
contexts, matching the behavior described in `completion-context.ts` and
`completion-provider.ts`.

In `@packages/1-framework/3-tooling/language-server/src/server.ts`:
- Around line 253-295: Refresh the completion path in completeDocument so it
does not rely on stale cached parse artifacts from
project.artifacts.getDocument(uri) when the buffer has just changed. Before
calling classifyPslCompletionContext(), rebuild or refresh the document
artifacts from the current document.getText() and use those updated artifacts
for the completion context and providePslCompletionItems call, while keeping the
existing early returns and try/catch behavior intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: b388a8f7-7b3e-4afb-a96d-db96126c5a9d

📥 Commits

Reviewing files that changed from the base of the PR and between 01b1488 and 6d2947a.

⛔ Files ignored due to path filters (9)
  • projects/lsp-autocomplete/plan.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/dispatches/01-cursor-classifier-substrate.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/dispatches/02-model-type-provider.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/dispatches/03-lsp-completion-route.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/dispatches/04-scope-docs-and-final-guardrails.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/plan.md is excluded by !projects/**
  • projects/lsp-autocomplete/slices/model-type-completions/spec.md is excluded by !projects/**
  • projects/lsp-autocomplete/spec.md is excluded by !projects/**
  • projects/lsp-autocomplete/trace.jsonl is excluded by !projects/**
📒 Files selected for processing (7)
  • packages/1-framework/3-tooling/language-server/README.md
  • packages/1-framework/3-tooling/language-server/src/completion-context.ts
  • packages/1-framework/3-tooling/language-server/src/completion-provider.ts
  • packages/1-framework/3-tooling/language-server/src/server.ts
  • packages/1-framework/3-tooling/language-server/test/completion-context.test.ts
  • packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts
  • packages/1-framework/3-tooling/language-server/test/server.test.ts

Comment on lines +37 to +39
- `completion-context.ts` — pure cursor classifier for PSL completion contexts, currently routing model field type positions and descriptor-backed generic block parameter-key positions while marking everything outside slice scope unsupported.
- `completion-provider.ts` — pure completion item provider for supported model field type and generic block parameter contexts.
- `server.ts` — `createServer(connection)` wires diagnostics, whole-document formatting, and narrow model field type completion handlers onto an injected connection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the server.ts module description to include generic-block completions.

This bullet now understates the server wiring: the README above documents generic block parameter-key completion too, and server.ts registers a single completion handler for both supported contexts. As per coding guidelines, "Keep docs current (READMEs, rules, links)".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/1-framework/3-tooling/language-server/README.md` around lines 37 -
39, The server module description is incomplete because it only mentions model
field type completions and omits the generic-block parameter-key completions
that `createServer(connection)` also wires up. Update the `server.ts` bullet in
the README so it reflects both supported completion contexts, matching the
behavior described in `completion-context.ts` and `completion-provider.ts`.

Source: Coding guidelines

Comment on lines +253 to +295
async function completeDocument(uri: string, position: Position): Promise<CompletionItem[]> {
const document = documents.get(uri);
if (document === undefined) {
return [];
}

let project: ProjectState | undefined;
try {
project = await resolveProjectForDocument(uri);
} catch {
return [];
}
if (project === undefined || !project.inputs.includes(uri)) {
return [];
}

const cached = project.artifacts.getDocument(uri);
const symbolTable = project.artifacts.getSymbolTable();
if (cached === undefined || symbolTable === undefined) {
return [];
}

try {
const context = classifyPslCompletionContext({
document: cached.document,
sourceFile: cached.sourceFile,
position,
});
return [
...providePslCompletionItems({
context,
sourceFile: cached.sourceFile,
candidates: {
scalarTypes: project.controlStack.scalarTypes,
pslBlockDescriptors: project.controlStack.pslBlockDescriptors,
symbolTable,
},
}),
];
} catch {
return [];
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Refresh artifacts from the current buffer before classifying completions.

Line 269 reads cached parse artifacts, but those artifacts are only refreshed asynchronously in publish() after onDidChangeContent. A completion request that lands right after typing can therefore run against the previous buffer and return wrong items/ranges or []. Rebuild or refresh the artifacts from document.getText() on this path before calling classifyPslCompletionContext().

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/1-framework/3-tooling/language-server/src/server.ts` around lines
253 - 295, Refresh the completion path in completeDocument so it does not rely
on stale cached parse artifacts from project.artifacts.getDocument(uri) when the
buffer has just changed. Before calling classifyPslCompletionContext(), rebuild
or refresh the document artifacts from the current document.getText() and use
those updated artifacts for the completion context and providePslCompletionItems
call, while keeping the existing early returns and try/catch behavior intact.

SevInf added 3 commits June 25, 2026 15:46
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
@SevInf SevInf force-pushed the lsp-autocomplete branch from 6d2947a to 8ef6f1a Compare June 25, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant