Skip to content

v8.0.0-rc.14-dev.42

@StevenMcClankerton StevenMcClankerton tagged this 06 Oct 15:01
The PSL language server answers `textDocument/references` for models,
composite types, named types, blocks (including enum blocks), fields and
namespaces, across every schema file of the project. A usage is a token
that go-to-definition would take to the same declaration, so the list
agrees with diagnostics and navigation. The planned rename feature will
edit exactly the ranges this returns.

## Changes

- **References provider**
(`packages/1-framework/3-tooling/language-server/src/references.ts`):
resolves the symbol at the cursor with `resolvedNodeAt`, searches the
text of every project document for the symbol's name, and keeps the
identifier tokens whose binder resolution holds the same symbol object.
Each location is the range of one identifier token: `User` in
`auth.User`, not the whole qualified name. A cursor on a declaration
name and a cursor on any reference return the same list.
`includeDeclaration` is honoured.
- **Namespaces**: the name of every `namespace X` block is returned
whether or not `includeDeclaration` is set, because each block both
declares and reopens the namespace. For that, the binder
(`packages/1-framework/2-authoring/psl-parser/src/binder.ts`) now
records a `namespace` resolution on each namespace block's name node, as
it already does for the names of models, types, blocks and fields. This
is the only binder change. Hover on a namespace block name now shows
`namespace <name>` as a result.
- **Go-to-definition on a declaration name** (`src/definition.ts`):
returns the declaration's own location instead of `null`; a namespace
block name returns every block of the namespace. VS Code runs find
references when a definition result is the position the cursor is
already on, so F12 on `model User` shows its usages.
- **Wiring**: `ProjectArtifacts.documents()` exposes the project's
documents, read the same way the symbol table reads them;
`Project.references` follows `Project.definition`; `server.ts` declares
`referencesProvider`.
- **Tests**: `test/references.test.ts` covers each symbol kind from a
declaration and from a reference over a three-file project, the
discarded candidates (longer identifiers, comments, strings, same-named
fields on other models), and positions with no target. One expectation
in the SQL `contract-psl` binder test gains the new `namespace` entry.

## Why

- **Text search, then binder confirmation.** The binder maps nodes to
resolutions and cannot list the references to a symbol. Syntax tree
nodes are created on first access, so visiting every token of every file
would create a node per element; a text search creates nodes only on the
path to each match. The binder gets no reverse index.
- **Symbol identity decides.** Two fields named `id` on different models
are different symbols and never appear in each other's results. Text
only proposes candidates.
- **Definition returns the declaration, not its usages.** Putting usages
in a definition response would make peek definition show the wrong list
and would mislead clients other than VS Code.

## Not in this PR

- Enum member references (`@default(ACTIVE)`): the binder records no
resolution for them.
- Rename and document highlight.
- Symbols with no declaration in the schema sources (attributes,
functions, contributed types, cross-space references) return an empty
result.

## Verification

- Package tests and lint for `psl-parser`, `language-server` and
`sql-contract-psl` pass, as does `pnpm lint:deps`.
- A QA run drove the built CLI over stdio against a four-file project;
every scripted scenario passed.
- Not yet done: the manual check in VS Code (Find All References, Peek
References, F12 on a declaration name) and in `apps/lsp-playground`.
- On the authoring machine `pnpm test:packages` failed in three tarball
tests (`ERR_PNPM_TRUST_DOWNGRADE` in their own `pnpm install`) and the
workspace typecheck failed in `prisma7-adoption` (404 fetching an engine
checksum). Both fail before reaching code from this branch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added Find References to the language server and playground, with
results across project files—including files not open in the editor—and
an option to include declarations.
* Namespace declaration names now support resolution, hover, and
go-to-definition. Namespace definitions include all matching namespace
blocks.
* **Documentation**
* Updated playground and language-server guides to describe Find
References and clarify supported targets, results, and limitations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Steven McClankerton <tatarintsev@prisma.io>
Co-authored-by: Steven McClankerton <tatarintsev@prisma.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Assets 2
Loading