Repository navigation
TML-2930: add prisma-next lsp subcommand + PSL diagnostics language server - #852
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughA shared ChangesConfig loading, language server, and CLI lsp command
Sequence Diagram(s)sequenceDiagram
participant Editor
participant CLI as prisma-next lsp
participant startServer
participant createServer
participant resolveConfigInputs
participant loadResolvedConfig
participant computeDocumentDiagnostics
Editor->>CLI: launch process --stdio
CLI->>startServer: startServer({ transport: 'stdio' })
startServer->>createServer: createConnection + options
Editor->>createServer: initialize(rootUri)
createServer->>resolveConfigInputs: rootPath, configPath?
resolveConfigInputs->>loadResolvedConfig: load prisma-next.config.ts
loadResolvedConfig-->>resolveConfigInputs: PrismaNextConfig or degraded
resolveConfigInputs-->>createServer: ConfigResolution
createServer-->>Editor: InitializeResult
Editor->>createServer: textDocument/didOpen(uri, text)
createServer->>computeDocumentDiagnostics: uri, text, inputs
computeDocumentDiagnostics-->>createServer: LspDiagnostic[] or null
createServer-->>Editor: textDocument/publishDiagnostics
Editor->>createServer: workspace/didChangeWatchedFiles
createServer->>resolveConfigInputs: re-resolve inputs
createServer-->>Editor: republish diagnostics for all open docs
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/config-loader
@prisma-next/emitter
@prisma-next/language-server
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
packages/1-framework/1-core/config/test/load.test.ts (1)
57-95: Reconsider reliance onprocess.chdir()without explicit test isolation—the config package uses default parallel threading.
packages/1-framework/1-core/config/vitest.config.tshas no explicit isolation settings (unlikepackages/1-framework/3-tooling/cliwhich setsmaxWorkers: 1, fileParallelism: false, isolate: false). By default, tests run across multiple worker threads. While thread isolation does separate process state across workers, if multiple tests run sequentially within the same worker and one fails beforeafterEachcompletes, the next test may inherit a mutatedprocess.cwd().Consider either:
- Adding an explicit
afterEachguard to ensure cwd is restored even on failure (e.g., usingtry…finally)- Declaring
fileParallelism: falsein the config's vitest.config.ts if sequential execution is required🤖 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/1-core/config/test/load.test.ts` around lines 57 - 95, The test suite in the load.test.ts file uses process.chdir() to change directories but without explicit protection against test isolation failures. If a test fails before the afterEach hook completes, the next test in the same worker thread could inherit a mutated process.cwd() state. Wrap the restoration of the original working directory in the afterEach hook using a try-finally block to ensure process.chdir(originalCwd) is always executed regardless of test outcome, or alternatively add explicit parallel execution settings (fileParallelism: false) to the vitest.config.ts file in the config package to force sequential test execution.packages/1-framework/3-tooling/cli/src/commands/lsp.ts (1)
44-48: 💤 Low valueThe
--stdioflag value is never checked.Line 44 declares
--stdioas an option, but Line 48 always passestransport: 'stdio'tostartServerregardless of whether the user provided the flag. SinceStartServerOptions(from context snippet 1) only supports'stdio'transport and defaults to it, the flag appears to be purely informational.If
--stdiois meant to document the transport rather than control it, consider removing it as a user-facing option (the comment on line 18 already documents this). Alternatively, if you want to keep it for clarity, validate thatoptions.stdio !== falsebefore callingstartServer, or add a comment explaining that the flag is documentation-only.🤖 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/cli/src/commands/lsp.ts` around lines 44 - 48, The --stdio option is declared but its value from the options parameter is never actually checked or used when calling startServer. Either remove the .option('--stdio', ...) declaration if the flag is meant to be documentation-only (since StartServerOptions only supports stdio transport anyway), or validate that options.stdio is not false before calling startServer with the transport parameter. If keeping the flag, ensure the parsed value from options.stdio is properly incorporated into the startServer call logic.packages/1-framework/3-tooling/cli/test/control-api/format.test.ts (1)
3-3: 💤 Low valuePrefer pathe over node:path for consistency.
Based on learnings, pathe should be used for path operations across the codebase, including package unit tests. The node:path exception applies specifically to integration tests under test/integration/test/. Consider replacing
node:pathwithpathehere for consistency.🤖 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/cli/test/control-api/format.test.ts` at line 3, The import statement is using node:path instead of pathe, which is inconsistent with the codebase standards. Replace the import statement where join is imported from node:path by changing it to import join from pathe instead. This aligns with the preferred path handling library used throughout the codebase, with the exception being reserved only for integration tests under test/integration/test/.Source: Learnings
packages/1-framework/3-tooling/cli/src/config-loader.ts (1)
51-63: Remove unreachable file-not-found fallback.Lines 38–40 catch
ConfigFileNotFoundErrorfromloadResolvedConfig, which is documented to throw onlyConfigFileNotFoundError(orConfigValidationError) when the config file is missing. The fallback at lines 51–63 that catches genericErrorwith message patterns like'ENOENT'cannot be reached becauseloadResolvedConfighandles all file-not-found scenarios by throwingConfigFileNotFoundError(see lines 56–57 and 62–63 inload.ts). Remove the redundant pattern-matching block.🤖 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/cli/src/config-loader.ts` around lines 51 - 63, Remove the unreachable fallback error handling block in the config-loader.ts file. The if statement that checks for error instanceof Error and pattern-matches against error.message strings like 'ENOENT', 'not found', and 'Cannot find' cannot be reached because the upstream loadResolvedConfig function already handles all file-not-found scenarios by throwing ConfigFileNotFoundError. Delete the entire conditional block (lines 51-63) that includes the error message pattern checking and the errorConfigFileNotFound call, as this logic is redundant and unreachable.
🤖 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/1-core/config/src/config-types.ts`:
- Around line 149-152: The FormatterConfigSchema currently accepts any number
for the indent property but should enforce that indent values are positive
(greater than 0) according to the documented constraint. Update the 'indent?'
field definition in FormatterConfigSchema to use arktype validation that
explicitly constrains the value to be greater than zero, and add test cases that
verify the schema correctly rejects negative and zero indent values.
In `@packages/1-framework/2-authoring/psl-parser/test/format/options.test.ts`:
- Around line 40-41: Remove the `@ts-expect-error` comment from lines 40 and 57 in
the format function test calls. Instead of suppressing the TypeScript error, use
an explicit type cast (such as "as any") to pass the invalid indent value to the
format function. This allows the runtime validation test to remain functional
while adhering to the coding guideline that prohibits `@ts-expect-error` outside
of negative type tests. Apply this change to both instances: the format call
with indent set to 'spaces' and the similar call at line 57-58.
---
Nitpick comments:
In `@packages/1-framework/1-core/config/test/load.test.ts`:
- Around line 57-95: The test suite in the load.test.ts file uses
process.chdir() to change directories but without explicit protection against
test isolation failures. If a test fails before the afterEach hook completes,
the next test in the same worker thread could inherit a mutated process.cwd()
state. Wrap the restoration of the original working directory in the afterEach
hook using a try-finally block to ensure process.chdir(originalCwd) is always
executed regardless of test outcome, or alternatively add explicit parallel
execution settings (fileParallelism: false) to the vitest.config.ts file in the
config package to force sequential test execution.
In `@packages/1-framework/3-tooling/cli/src/commands/lsp.ts`:
- Around line 44-48: The --stdio option is declared but its value from the
options parameter is never actually checked or used when calling startServer.
Either remove the .option('--stdio', ...) declaration if the flag is meant to be
documentation-only (since StartServerOptions only supports stdio transport
anyway), or validate that options.stdio is not false before calling startServer
with the transport parameter. If keeping the flag, ensure the parsed value from
options.stdio is properly incorporated into the startServer call logic.
In `@packages/1-framework/3-tooling/cli/src/config-loader.ts`:
- Around line 51-63: Remove the unreachable fallback error handling block in the
config-loader.ts file. The if statement that checks for error instanceof Error
and pattern-matches against error.message strings like 'ENOENT', 'not found',
and 'Cannot find' cannot be reached because the upstream loadResolvedConfig
function already handles all file-not-found scenarios by throwing
ConfigFileNotFoundError. Delete the entire conditional block (lines 51-63) that
includes the error message pattern checking and the errorConfigFileNotFound
call, as this logic is redundant and unreachable.
In `@packages/1-framework/3-tooling/cli/test/control-api/format.test.ts`:
- Line 3: The import statement is using node:path instead of pathe, which is
inconsistent with the codebase standards. Replace the import statement where
join is imported from node:path by changing it to import join from pathe
instead. This aligns with the preferred path handling library used throughout
the codebase, with the exception being reserved only for integration tests under
test/integration/test/.
🪄 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: 447f79ca-609a-4187-bc5f-844c5e84c000
⛔ Files ignored due to path filters (3)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlprojects/lsp-scaffold/plan.mdis excluded by!projects/**projects/lsp-scaffold/spec.mdis excluded by!projects/**
📒 Files selected for processing (110)
architecture.config.jsonpackages/1-framework/1-core/config/package.jsonpackages/1-framework/1-core/config/src/config-types.tspackages/1-framework/1-core/config/src/contract-source-types.tspackages/1-framework/1-core/config/src/errors.tspackages/1-framework/1-core/config/src/exports/config-types.tspackages/1-framework/1-core/config/src/exports/load.tspackages/1-framework/1-core/config/src/finalize-config.tspackages/1-framework/1-core/config/src/load.tspackages/1-framework/1-core/config/test/config-types.test-d.tspackages/1-framework/1-core/config/test/config-validation.test.tspackages/1-framework/1-core/config/test/finalize-config.test.tspackages/1-framework/1-core/config/test/load.test.tspackages/1-framework/1-core/config/tsdown.config.tspackages/1-framework/2-authoring/psl-parser/package.jsonpackages/1-framework/2-authoring/psl-parser/src/exports/format.tspackages/1-framework/2-authoring/psl-parser/src/exports/parser.tspackages/1-framework/2-authoring/psl-parser/src/format/emit.tspackages/1-framework/2-authoring/psl-parser/src/format/error.tspackages/1-framework/2-authoring/psl-parser/src/format/format.tspackages/1-framework/2-authoring/psl-parser/src/format/options.tspackages/1-framework/2-authoring/psl-parser/test/format/fixtures.test.tspackages/1-framework/2-authoring/psl-parser/test/format/fixtures/alignment-model/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/alignment-model/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/alignment-trivia/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/alignment-trivia/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/alignment-widths/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/alignment-widths/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/blank-lines/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/blank-lines/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/block-attribute-spacing/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/block-attribute-spacing/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/block-attributes/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/block-attributes/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/block-separation/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/block-separation/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/comments-preserved/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/comments-preserved/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/dangling-comments/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/dangling-comments/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/datasource-generic-blocks/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/datasource-generic-blocks/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/enum-and-generator-block/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/enum-and-generator-block/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/inline-comment-after-equals/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/inline-comment-after-equals/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/inline-comment-arg-list/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/inline-comment-arg-list/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/inline-comment-hard-break/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/inline-comment-hard-break/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/kitchen-sink/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/kitchen-sink/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/leading-comments/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/leading-comments/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/named-type-inline-break/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/named-type-inline-break/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/structural-emit/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/structural-emit/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/top-level-blank-collapse/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/top-level-blank-collapse/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/trailing-comments/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/trailing-comments/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/type-annotations/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/type-annotations/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/types-namespaced-constructor/expected.prismapackages/1-framework/2-authoring/psl-parser/test/format/fixtures/types-namespaced-constructor/input.prismapackages/1-framework/2-authoring/psl-parser/test/format/options.test.tspackages/1-framework/2-authoring/psl-parser/tsdown.config.tspackages/1-framework/3-tooling/cli/package.jsonpackages/1-framework/3-tooling/cli/recordings/fixtures/prisma-next.config.tspackages/1-framework/3-tooling/cli/src/cli.tspackages/1-framework/3-tooling/cli/src/commands/format.tspackages/1-framework/3-tooling/cli/src/commands/lsp.tspackages/1-framework/3-tooling/cli/src/config-loader.tspackages/1-framework/3-tooling/cli/src/config-path-validation.tspackages/1-framework/3-tooling/cli/src/control-api/operations/format.tspackages/1-framework/3-tooling/cli/src/exports/index.tspackages/1-framework/3-tooling/cli/test/commands/lsp.test.tspackages/1-framework/3-tooling/cli/test/control-api/format.test.tspackages/1-framework/3-tooling/cli/vitest.config.tspackages/1-framework/3-tooling/language-server/README.mdpackages/1-framework/3-tooling/language-server/biome.jsoncpackages/1-framework/3-tooling/language-server/package.jsonpackages/1-framework/3-tooling/language-server/src/config-resolution.tspackages/1-framework/3-tooling/language-server/src/diagnostic-mapping.tspackages/1-framework/3-tooling/language-server/src/document-diagnostics.tspackages/1-framework/3-tooling/language-server/src/exports/index.tspackages/1-framework/3-tooling/language-server/src/schema-inputs.tspackages/1-framework/3-tooling/language-server/src/server.tspackages/1-framework/3-tooling/language-server/src/start-server.tspackages/1-framework/3-tooling/language-server/test/config-resolution.test.tspackages/1-framework/3-tooling/language-server/test/diagnostic-mapping.test.tspackages/1-framework/3-tooling/language-server/test/document-diagnostics.test.tspackages/1-framework/3-tooling/language-server/test/schema-inputs.test.tspackages/1-framework/3-tooling/language-server/test/server.test.tspackages/1-framework/3-tooling/language-server/tsconfig.jsonpackages/1-framework/3-tooling/language-server/tsconfig.prod.jsonpackages/1-framework/3-tooling/language-server/tsdown.config.tspackages/1-framework/3-tooling/language-server/vitest.config.tspackages/2-mongo-family/2-authoring/contract-psl/src/provider.tspackages/2-mongo-family/2-authoring/contract-psl/test/provider.test.tspackages/2-mongo-family/2-authoring/contract-ts/src/config-types.tspackages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.tspackages/2-sql/2-authoring/contract-psl/src/provider.tspackages/2-sql/2-authoring/contract-psl/test/provider.test.tspackages/2-sql/2-authoring/contract-ts/src/config-types.tspackages/2-sql/2-authoring/contract-ts/test/config-types.test.tspnpm-workspace.yamltest/integration/test/cli-journeys/format.e2e.test.tstest/integration/test/utils/journey-test-helpers.ts
💤 Files with no reviewable changes (2)
- packages/1-framework/3-tooling/cli/src/config-path-validation.ts
- packages/1-framework/3-tooling/cli/vitest.config.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/test/server.test.ts`:
- Around line 278-285: Replace the fixed 50ms setTimeout call with event-based
or condition-based waiting that checks for the actual registration state.
Instead of pausing for an arbitrary delay, implement a helper function or use a
waitFor pattern that repeatedly checks if a workspace/didChangeWatchedFiles
registration exists in harness.registrations, with a reasonable bounded timeout.
This same pattern should be applied to all occurrences of setTimeout delays used
to gate registration assertions in this test file.
🪄 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: f4b4210e-da04-43df-84fb-14d186e60a32
⛔ Files ignored due to path filters (3)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlprojects/lsp-scaffold/plan.mdis excluded by!projects/**projects/lsp-scaffold/spec.mdis excluded by!projects/**
📒 Files selected for processing (37)
architecture.config.jsonpackages/1-framework/1-core/config/package.jsonpackages/1-framework/1-core/config/src/errors.tspackages/1-framework/1-core/config/src/exports/load.tspackages/1-framework/1-core/config/src/finalize-config.tspackages/1-framework/1-core/config/src/load.tspackages/1-framework/1-core/config/test/finalize-config.test.tspackages/1-framework/1-core/config/test/load.test.tspackages/1-framework/1-core/config/tsdown.config.tspackages/1-framework/2-authoring/psl-parser/src/exports/parser.tspackages/1-framework/3-tooling/cli/package.jsonpackages/1-framework/3-tooling/cli/src/cli.tspackages/1-framework/3-tooling/cli/src/commands/lsp.tspackages/1-framework/3-tooling/cli/src/config-loader.tspackages/1-framework/3-tooling/cli/src/config-path-validation.tspackages/1-framework/3-tooling/cli/test/commands/lsp.test.tspackages/1-framework/3-tooling/cli/vitest.config.tspackages/1-framework/3-tooling/language-server/README.mdpackages/1-framework/3-tooling/language-server/biome.jsoncpackages/1-framework/3-tooling/language-server/package.jsonpackages/1-framework/3-tooling/language-server/src/config-resolution.tspackages/1-framework/3-tooling/language-server/src/diagnostic-mapping.tspackages/1-framework/3-tooling/language-server/src/document-diagnostics.tspackages/1-framework/3-tooling/language-server/src/exports/index.tspackages/1-framework/3-tooling/language-server/src/schema-inputs.tspackages/1-framework/3-tooling/language-server/src/server.tspackages/1-framework/3-tooling/language-server/src/start-server.tspackages/1-framework/3-tooling/language-server/test/config-resolution.test.tspackages/1-framework/3-tooling/language-server/test/diagnostic-mapping.test.tspackages/1-framework/3-tooling/language-server/test/document-diagnostics.test.tspackages/1-framework/3-tooling/language-server/test/schema-inputs.test.tspackages/1-framework/3-tooling/language-server/test/server.test.tspackages/1-framework/3-tooling/language-server/tsconfig.jsonpackages/1-framework/3-tooling/language-server/tsconfig.prod.jsonpackages/1-framework/3-tooling/language-server/tsdown.config.tspackages/1-framework/3-tooling/language-server/vitest.config.tspnpm-workspace.yaml
💤 Files with no reviewable changes (2)
- packages/1-framework/3-tooling/cli/vitest.config.ts
- packages/1-framework/3-tooling/cli/src/config-path-validation.ts
✅ Files skipped from review due to trivial changes (6)
- packages/1-framework/3-tooling/language-server/tsconfig.prod.json
- packages/1-framework/3-tooling/language-server/biome.jsonc
- packages/1-framework/3-tooling/language-server/tsconfig.json
- pnpm-workspace.yaml
- architecture.config.json
- packages/1-framework/3-tooling/language-server/vitest.config.ts
🚧 Files skipped from review as they are similar to previous changes (24)
- packages/1-framework/3-tooling/language-server/src/document-diagnostics.ts
- packages/1-framework/3-tooling/cli/test/commands/lsp.test.ts
- packages/1-framework/1-core/config/tsdown.config.ts
- packages/1-framework/3-tooling/language-server/tsdown.config.ts
- packages/1-framework/3-tooling/language-server/src/exports/index.ts
- packages/1-framework/2-authoring/psl-parser/src/exports/parser.ts
- packages/1-framework/1-core/config/src/exports/load.ts
- packages/1-framework/3-tooling/language-server/test/document-diagnostics.test.ts
- packages/1-framework/1-core/config/package.json
- packages/1-framework/3-tooling/language-server/test/diagnostic-mapping.test.ts
- packages/1-framework/3-tooling/language-server/src/start-server.ts
- packages/1-framework/3-tooling/language-server/src/diagnostic-mapping.ts
- packages/1-framework/1-core/config/src/load.ts
- packages/1-framework/3-tooling/language-server/README.md
- packages/1-framework/3-tooling/language-server/test/config-resolution.test.ts
- packages/1-framework/3-tooling/language-server/package.json
- packages/1-framework/1-core/config/src/finalize-config.ts
- packages/1-framework/1-core/config/test/finalize-config.test.ts
- packages/1-framework/1-core/config/test/load.test.ts
- packages/1-framework/1-core/config/src/errors.ts
- packages/1-framework/3-tooling/language-server/src/config-resolution.ts
- packages/1-framework/3-tooling/cli/src/config-loader.ts
- packages/1-framework/3-tooling/cli/src/commands/lsp.ts
- packages/1-framework/3-tooling/language-server/src/server.ts
a7f52e9 to
7b2aaa9
Compare
…erver Stand up the foundation of Prisma Next LSP support: a language server, reachable via the version-matched CLI, that reports PSL parse diagnostics in-editor. Delivered as three layers of one reviewable change: 1. Shared config resolution. Lift config load (c12) + PSL-input resolution out of @prisma-next/cli into @prisma-next/config (new ./load export, loadResolvedConfig). The CLI's loadConfig becomes a thin behaviour- preserving wrapper mapping plain typed errors to its structured errors; the output/input collision guard stays hook-injected so config keeps no @prisma-next/emitter edge. 2. Server package + diagnostics. New @prisma-next/language-server package (vscode-languageserver over stdio) and a thin `prisma-next lsp` subcommand. Schema documents are identified from config (sourceFormat === 'psl' + all resolved inputs); open documents are diagnosed via @prisma-next/psl-parser's CST parse, ranges passed through unchanged. The ParseDiagnostic -> LSP Diagnostic mapping stays free of vscode-languageserver imports. 3. Live config watching. A workspace/didChangeWatchedFiles watcher on the config path re-resolves inputs without a restart, fanning out add/clear diagnostics; graceful degradation on config-load failure. Refs: TML-2930 Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
…856) ## Linked issue n/a — small, self-contained dev tool. Builds on the language server from #852 (`prisma-next lsp`). ## Summary A private `apps/lsp-playground` package providing the `psl-playground` binary: it opens a PSL file in a browser CodeMirror 6 editor wired to `prisma-next lsp` over a single-port WebSocket bridge, giving you live PSL parse diagnostics without setting up an editor extension. ## At a glance ```bash # Open a blank scratch schema (no file, no config needed): psl-playground # Or open an existing PSL file: psl-playground path/to/schema.psl ``` Then open `http://localhost:5273/` and edit; diagnostics from `@prisma-next/psl-parser` update live. With no project config, the playground assumes a default-postgres setup. ``` CodeMirror 6 --LSP/WebSocket--> shared http server (port 5273) --spawn+stdio--> prisma-next lsp --stdio (codemirror-languageserver) (Vite middleware + vscode-ws-jsonrpc) (@prisma-next/language-server) ``` ## Decision This ships one thing: a browser playground for the PSL language server, as a private `apps/` package so it stays out of the framework build graph and `lint:deps` layering. Three design decisions shape it: 1. **CodeMirror 6 + `codemirror-languageserver`** for the editor (lighter than Monaco; grows into hover/completion as the server gains them). 2. **One port for everything.** Vite runs in middleware mode on a single `http.Server`; the LSP WebSocket bridge attaches an `upgrade` listener that only claims `/psl`, so the editor, Vite HMR, and the language server all share port 5273. 3. **PSL file optional; config optional.** With no argument the playground stages a scratch schema and generates a default-postgres config; an existing file already inside a project opens in place under its own config. ## How it fits together 1. **Resolve what to open.** `src/cli.ts` resolves the schema and the config above it: an explicit `--config` + file opens in place; an existing file inside a project opens in place under its discovered config; otherwise (no file / missing path / file with no project config) the schema is staged into `.playground/` and a default-postgres config is generated beside it. 2. **Stage for resolvability.** Staging into `.playground/` (`src/default-config.ts`, `stageSchema` in `src/cli.ts`) is required because the language server discovers a document's config by walking up from the document's own path, and the generated config's `@prisma-next/*` imports must resolve through the workspace `node_modules`. 3. **Bridge stdio over WebSocket.** `src/bridge.ts` attaches to the shared server, and on each `/psl` connection spawns `prisma-next lsp --stdio` and forwards JSON-RPC via `vscode-ws-jsonrpc` (`createServerProcess` + `forward`). 4. **Serve the editor.** Vite serves the page; a generated `src/client/runtime.ts` hands the client the document URI, root, schema text, and WS path; `src/client/main.ts` mounts CodeMirror with the `languageServer` extension pointed at the same origin. ## Behavior changes & evidence - `psl-playground` with **no argument** opens a scratch schema under default-postgres and publishes live diagnostics — `apps/lsp-playground/src/cli.ts`, `apps/lsp-playground/src/default-config.ts`. Validated manually end-to-end (no-arg launch → `PSL_UNTERMINATED_BLOCK`). - `psl-playground <file>` opens an existing schema; if it has no project config it is staged as a sandbox copy under default-postgres, otherwise opened in place — `apps/lsp-playground/src/cli.ts`. Validated manually (staged-copy launch → diagnostics). - Editor and LSP share a single port via Vite middleware mode + an `/psl`-scoped upgrade handler — `apps/lsp-playground/src/cli.ts`, `apps/lsp-playground/src/bridge.ts`. ## Reviewer notes - **Largest file is `src/cli.ts`** — the arg parsing + schema/config resolution + single-port wiring live there. The branching in schema/config resolution is the part to spot-check. - **Staging edits a copy, not your file.** For files outside a project, the playground deliberately opens a copy under `.playground/` rather than your original — both because the server needs the config's `@prisma-next/*` imports to resolve and because walk-up config discovery requires the schema to sit beside the generated config. This is intentional sandbox behaviour. - **Generated artefacts are gitignored.** `.playground/` and `src/client/runtime.ts` are written at launch and excluded from git; only sources are tracked. - **Build prerequisite.** The bridge spawns the built CLI (`@prisma-next/cli`'s `dist/cli.js`) and the generated config loads built postgres-stack packages, so a fresh checkout needs `pnpm install` + a build of those packages before first run. Noted in the README. - **No automated tests.** This is a dev tool validated by manual end-to-end runs (documented in Verification); it ships no unit tests. ## Compatibility / migration / risk No framework surface changes. `apps/` is exempt from `lint:deps`; the package is `private` and unpublished. Zero risk to shipped code. ## Testing performed - `pnpm --filter @prisma-next/lsp-playground typecheck` — clean - `pnpm --filter @prisma-next/lsp-playground lint` — clean (exit 0) - Manual end-to-end against rebased `origin/main`: no-arg launch and existing-file launch both serve the editor on port 5273 and publish `PSL_UNTERMINATED_BLOCK` for a broken schema over the shared-port WebSocket bridge. ## Skill update n/a — internal dev tool; no user-facing CLI/API/config surface of the framework changes (the `psl-playground` binary lives only in this private package). ## Alternatives considered - **Monaco + `monaco-languageclient`** — heavier (pulls the vscode-api shims); CodeMirror 6 is lighter and sufficient for diagnostics, and grows into later language features. - **Two ports (separate Vite + bridge servers)** — the original shape; collapsed to one shared `http.Server` to avoid hogging two ports. - **A Zed/VS Code dev extension** — more setup and editor-specific; a browser playground is editor-agnostic and instantly shareable. - **`lsp-ws-proxy` (Rust) or the 8-year-old `jsonrpc-ws-proxy`** — `vscode-ws-jsonrpc` is maintained, all-JS, and `pnpm`-installable. ## Checklist - [x] All commits are signed off (`git commit -s`) per the DCO. - [x] I read CONTRIBUTING.md and the change is scoped to one logical concern. - [x] Tests are updated (n/a — dev tool validated by manual end-to-end runs; no behavioural delta to framework code). - [ ] The PR title is in `TML-NNNN: <sentence-case title>` form (n/a — no Linear ticket; self-contained dev tool). - [x] The **Skill update** section above is filled in. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes **New Features** - Added an LSP playground web application for live PSL schema editing and diagnostics. - Supports opening an existing schema or using a scratch schema. - Provides real-time LSP updates in the browser via a WebSocket-to-LSP bridge. - Automatically locates the nearest project configuration or generates a default PostgreSQL configuration when needed. **Documentation** - Updated the playground README with local usage and workflow details. **Chores** - Updated ignore rules to exclude generated/staged playground output. **Tests** - Added a sample “broken” PSL fixture for validation scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Serhii Tatarintsev <[email protected]>
Linked issue
Refs TML-2930 — foundation work for the Language Tools Support Prisma Next PSL project. The spec + plan live under
projects/lsp-scaffold/for review and are removed at project close-out.At a glance
The editor launches the project-local CLI as a language server over stdio:
It completes the
initializehandshake, advertising incremental document sync and diagnostics:and then publishes PSL parse diagnostics for the schema files declared in
prisma-next.config.ts, at the exact source ranges the parser reports — the same diagnosticsformat/contract emitwould surface, now live at the cursor instead of only at build time.The decision
This PR ships the first piece of Prisma Next LSP support. It carries three things:
prisma-next lspsubcommand and a new@prisma-next/language-serverpackage. The subcommand is a thin entry point (createLspCommand) that delegates to the package, which owns the LSP connection, lifecycle, document sync, and diagnostics.lspis a CLI subcommand — version-matched to the project's own@prisma-nextby construction, likedeno lsp— not a separate binary.@prisma-next/config-loaderpackage that owns loadingprisma-next.config.ts. This is where config loading now lives for both the CLI and the language server, replacing the loader that previously lived inside@prisma-next/cli.parse, not the legacyparsePslDocument(which is slated for removal independently).One server runs per project. Schema documents are identified from config (a document is a schema input when its path is one of the resolved
contract.source.inputs). The server watchesprisma-next.config.tsand re-resolves on change, so the input set stays live without a restart.How config loading is organised now
Before this PR, loading
prisma-next.config.tslived inside@prisma-next/cli(config-loader.ts+config-path-validation.ts), so a language-server package could not reuse it without importing from the CLI — which the dependency rules forbid. This PR moves that loading into its own package and removes the CLI's private copy:@prisma-next/config-loaderexposes a singleloadConfig(configPath?). It runsc12to execute the config file, validates it, resolvescontract.source.inputs/contract.outputto absolute paths, and applies the emitter output/input collision check (it importsgetEmittedArtifactPathsfrom@prisma-next/emitteritself). On failure it throws the CLI's structured@prisma-next/errors/controlerrors — the same errors, with the same codes, the CLI produced before. Seeconfig-loader/src/load.ts.config-loader.tswrapper is deleted. Its ~17 source consumers (contract-emit,db-sign,db-verify,inspect-live-schema,migrate, themigration-*commands, …) now importloadConfigfrom@prisma-next/config-loaderdirectly — same function name, same behaviour, same error codes.cli/src/config-path-validation.tsis deleted; its path-resolution logic moved alongside the loader.@prisma-next/configgoes back to types + validation + path-finalising helpers (finalize-config.ts,errors.ts,config-types.ts,config-validation.ts); it no longer loads config and no longer depends onc12.How the language server works
initialize— resolves the project root from the client'srootUri/rootPath, loadsprisma-next.config.tsvia@prisma-next/config-loader'sloadConfig, and records which absolute paths are schema inputs. A missing or invalid config degrades gracefully: the server still initializes with an empty input set and logs a warning. Config is resolved once here.loadConfigthrows structuredCliStructuredErrors, so the server'sconfig-resolution.tsbranches on the stable errorcode(4001= config file not found,4009= config validation) to decide whether to degrade; any other code is re-thrown as a genuine failure. The CLI error codes are unchanged by this PR.TextDocumentSyncKind.Incremental); theTextDocumentsmanager applies the client's deltas and the server re-parses the full current buffer on each change.didOpen/didChangeof a document whose URI is a configured input, the server runs@prisma-next/psl-parser'sparse()and publishes the mapped diagnostics. A clean parse publishes an empty array (clearing markers); a non-input document publishes nothing.workspace/didChangeWatchedFilesevent for the config path, the server re-resolves the input set and re-publishes across open documents, so adding/removing an input takes effect without a restart. Works whether or not the config file is open in the editor.The
ParseDiagnostic → LSP diagnosticmapping indiagnostic-mapping.tsis a pure transform with novscode-languageserverimport: the parser already emits zero-based, LSP-shaped ranges, so ranges pass through unchanged and the connection layer adapts severity at the boundary.Behavior changes & evidence
prisma-next lspcommand launches a PSL language server over stdio. Impl:cli/src/commands/lsp.ts,language-server/src/start-server.ts. Evidence:cli/test/commands/lsp.test.tsand the live handshake (see Testing performed).language-server/src/server.ts,language-server/src/document-diagnostics.ts,language-server/src/schema-inputs.ts. Evidence:test/server.test.ts,test/document-diagnostics.test.ts.language-server/src/server.ts,language-server/src/config-resolution.ts. Evidence: the config-watching cases intest/server.test.ts,test/config-resolution.test.ts.@prisma-next/config-loader; CLI consumers re-pointed. Impl:config-loader/src/load.ts, CLI wrapper +config-path-validation.tsdeleted. Evidence:config-loader/test/load.test.ts,config-loader/test/to-structured-config-error.test.ts, and the unchanged CLI/integration suites.Notes for the reviewer
@prisma-next/config-loaderis the one substantive new package besides the language server. It sits at the tooling layer (peer of the CLI and emitter), which is why it may import@prisma-next/emitter,@prisma-next/errors, and@prisma-next/configdirectly.loadConfigkeeps the CLI's existing error codes (PN-CLI-4001/4009/…), so nothing user-facing changes for CLI consumers.4001/4009) to decide graceful degradation rather than catching typed error classes. The codes are stable, documented constants (asserted in@prisma-next/errorstests), so this coupling is to a public contract, not an internal detail.@prisma-next/configlost itsc12dependency and its config-loading exports; it is back to types + validation + path-finalising. The path-finalising still takes the emitter collision check as a hook so@prisma-next/configkeeps no edge to the emitter.psl-parserbarrel gains aparseexport. The CSTparsewasn't exported from any public barrel (onlyparsePslDocumentwas);psl-parser/src/exports/parser.tsnow exports it plus itsParseDiagnostic/Rangetypes.parsePslDocumentis untouched.cli/test/version.test.ts,removed-verb-redirects.test.ts, andmigration-list-json-goldenfail on a hard-coded 500ms CLI-spawn timeout (a cold spawn measures ~1.2s on a dev machine); they fail identically on cleanmainwith this branch's changes stashed. There is also a committed bare-aslint item incli/src/commands/init/hygiene-package-scripts.tsthat predates and is untouched here. If CI's runner is slow, those spawn tests may need a longer timeout — flagging so the red isn't mis-attributed.projects/lsp-scaffold/{spec,plan}.mdare included for review and removed at project close-out (the ADR recording the "version-matched CLI subcommand, one server per project" decision lands indocs/then).Compatibility / migration / risk
loadConfig's signature, behaviour, and thrown error codes are preserved. The additive public surface is the newlspcommand, the@prisma-next/config-loaderpackage, and the new@prisma-next/psl-parser/parserparseexport.Testing performed
Run on final HEAD:
pnpm install --frozen-lockfile— clean (lockfile and manifests agree).pnpm lint:deps— clean (no dependency violations; the new package's imports are legal).pnpm --filter @prisma-next/config-loader test— passes.pnpm --filter @prisma-next/language-server test— passes (incl. config-watching + graceful-degradation cases).pnpm --filter @prisma-next/config test— passes.pnpm --filter @prisma-next/psl-parser test— passes.pnpm --filter @prisma-next/integration-tests test cli.db-verify— passes (CLI structured-error behaviour preserved end-to-end).pnpm --filter @prisma-next/cli typecheck && build— clean;pnpm --filter prisma-next lint(facade dependency sync) — clean.initializehandshake against the built CLI (prisma-next lsp --stdio) returnstextDocumentSync: 2.main): the CLI 500ms spawn-timeout flakes noted above.Skill update
n/a — internal foundation work. No user-facing skill surface changes here; the
prisma-next lspcommand is documented in the package README and the project spec. A user-facing skill / docs update for the LSP will follow with the editor-extension work.Checklist
git commit -s).TML-NNNN: <sentence-case title>form.Alternatives considered
prisma-next-lspbinary instead of a subcommand — rejected: a subcommand is version-matched to the project's own@prisma-nextby construction and avoids a second package to keep pinned together. (deno lspis the precedent.)@prisma-next/cliinstead of its own package — rejected: a dedicated package keepsvscode-languageserver's footprint off the core CLI surface and gives later LSP features a clean home.@prisma-next/cli(or moving it into@prisma-next/config) — rejected: the CLI can't be imported by the language server (dependency rules), and@prisma-next/configsits below the tooling layer, so it can't reach the emitter or the CLI error factories the loader needs. A dedicated tooling-layer@prisma-next/config-loaderpackage is the home that lets both the CLI and the language server share oneloadConfig.loadConfigthrowing structured errors, with the language server reading the stable error codes, keeps a single public entry point and avoids duplicating the loader's surface.parsePslDocument— rejected: it's legacy and slated for removal; the CSTparseis whatformatalready consumes, so the language server and the formatter agree on what a diagnostic is.