Skip to content

31.12.15

Choose a tag to compare

@github-actions github-actions released this 08 Oct 14:06
4c5c3d7
fix: resolve the Prisma ORM 8 CLI from the nearest node_modules (#2010)

In a monorepo, Prisma ORM 8 language features did not work when `prisma`
was installed in a package (for example `apps/api`) and the monorepo
root was opened in VS Code.

## Problem

The extension looked for the CLI only at `<workspace
folder>/node_modules/prisma/dist/prisma.js`.

- With `prisma` installed only in `apps/api`, no Prisma ORM 8 language
server started, and VS Code reported "There is no formatter for 'prisma'
files installed."
- After accepting the install prompt, `prisma@latest` was installed at
the workspace root and used for `prisma lsp`. When that version differed
from the `@prisma/orm-*` packages in `apps/api`, loading
`apps/api/prisma.config.ts` failed with `PRISMA_CONFIG_LOAD_FAILED`. The
server still advertised formatting but returned no edits.

Reproduced by driving `prisma lsp` over stdio in a pnpm monorepo with
the schema at `apps/api/src/prisma/contract.prisma`:

| CLI used for `prisma lsp` | `@prisma/orm-postgres` in `apps/api` |
Formatting result |
|---|---|---|
| root, `8.0.0-rc.21` | `8.0.0-rc.12` | no edits,
`PRISMA_CONFIG_LOAD_FAILED` |
| `apps/api`, `8.0.0-rc.17`, cwd `apps/api` | `8.0.0-rc.12` | formats
correctly |

## Changes

- Search for `node_modules/prisma` from the schema file's directory up
to the workspace folder. The search does not go above the workspace
folder.
- Start `prisma lsp` with the directory that contains the selected
`node_modules` as its working directory, and scope the client's document
selector to that directory.
- Start one language server per directory with an installed CLI instead
of one per workspace folder, so packages with different CLI versions
each use their own.
- Update the document routing section of `docs/language-server.md`.
- Show an error notification when the Prisma ORM 8 server publishes a
`PRISMA_CONFIG_LOAD_FAILED` diagnostic. The diagnostic is attached to
`prisma.config.ts`, so it was easy to miss while editing a schema. The
notification names the config file and has two actions: "Open config",
and "Show details", which reveals the language server's output channel
where the server's error message is written. It is shown once per config
file and failure message, and again if the failure clears and returns.

## Not covered

- When a CLI at the workspace root and a CLI in a nested package are
both in use at the same time, the root server's document selector also
matches the nested package's files, so those files can receive duplicate
diagnostics and completions.
- The install prompt is unchanged: when no CLI is found, it still
installs `prisma@latest` at the workspace root.
- If a package is opened as the workspace folder and `prisma` is hoisted
above it, the CLI is still not found.

## Validation

- `vitest run tests/__tests__` in `packages/vscode`: 55 tests pass,
including six new monorepo resolution cases and twelve for the config
load failure notification.
- `tsc --noEmit` and `eslint` pass for `packages/vscode`.
- Not run in a VS Code window; the integration suite was not executed.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>