language-tools
language-tools copied to clipboard
Add `schemaPath` support
Add schemaPath Setting Support to Language Server
Summary
This PR adds support for the prisma.schemaPath VS Code setting to the Language Server, enabling proper multi-file schema support in monorepos and projects with custom schema locations.
Problem
Previously, the prisma.schemaPath setting was only used for CLI commands (like prisma generate) but was not passed to the Language Server. This caused the following issues:
- Multi-file schemas in custom directories failed to be compatible with the LSP when the
prisma.config.tswas not at the workspace root (colocated at the custom directory)- "Go to Definition" failed for cross-file references
- Autocomplete, hover, and other IDE features didn't work across files
- The Language Server only validated the currently opened file in isolation
The Prisma CLI (generate, validate, etc.) worked with the same configuration, making this purely a Language Server/extension issue.
Solution
This PR implements the following changes:
1. Language Server Changes (packages/language-server/)
src/lib/types.ts: AddedschemaPathfield toLSSettingsinterfacesrc/lib/Schema.ts:- Added
PrismaSchemaLoadOptionsinterface withschemaPathandconfigRootoptions - Updated
PrismaSchema.load()to accept options object (backward compatible with stringconfigRoot) - Implemented priority-based schema path resolution:
schemaPathfrom VS Code settingsschemapath fromprisma.config.ts- Current document path (fallback)
- Added
src/server.ts: Updated all LSP request handlers to passschemaPathfrom settings toPrismaSchema.load()
2. VS Code Extension Changes (packages/vscode/)
package.json: Updatedprisma.schemaPathsetting description to clarify it now works with the Language Server and supports directories
3. Tests (packages/language-server/src/__test__/)
schema-path.test.ts: Test suite covering:- Loading multi-file schemas via
schemaPathoption - Fallback behavior when
schemaPathis not provided - Backward compatibility with old string
configRootparameter - Priority of
schemaPathoverprisma.config.ts - Direct loading from
SchemaDocumentarrays
- Loading multi-file schemas via
4. Documentation
docs/language-server.md: Added detailed section on schema path resolution and VS Code configurationpackages/vscode/package.json: Enhanced setting description with examples
Behavior
Before
// Language Server ignored prisma.schemaPath setting
const schema = await PrismaSchema.load({
currentDocument,
allDocuments
})
// ❌ Only loaded current document's directory
After
// Language Server respects prisma.schemaPath setting
const schema = await PrismaSchema.load(
{ currentDocument, allDocuments },
{ schemaPath: settings.schemaPath }
)
// ✅ Loads all files from configured schema path
Schema Path Resolution Priority
schemaPathoption (from VS Codeprisma.schemaPathsetting)prisma.config.ts(discovered by searching upward fromschemaPathor current document)- Current document path (fallback)
This matches the Prisma CLI behavior, ensuring consistency between IDE and command-line tooling.
Configuration Example
Users can now configure multi-file schemas in monorepos:
// .vscode/settings.json
{
"prisma.schemaPath": "packages/backend/prisma"
}
// packages/backend/prisma.config.ts
export default defineConfig({
schema: './prisma',
migrations: {
seed: 'tsx ./scripts/seed.ts',
},
});
Backward Compatibility
- ✅ Existing code using
PrismaSchema.load(input, configRoot)continues to work - ✅ Tests using string
configRootparameter are unaffected - ✅ Projects without
schemaPathsetting work as before