From fe081acd6b4da6d2e21bd9a264838665e14dba53 Mon Sep 17 00:00:00 2001 From: Serhii Tatarintsev Date: Thu, 16 May 2024 18:22:07 +0200 Subject: [PATCH] Basic tests for multifile schemas (#1731) * Basic tests for multifile schemas * Fix windows test * fix: Newline characters should be a part of untrimmed lines * Fix characterAfter, add failing test for empty completion * Fix `@map` spacing * Revert windows hack * Windows, please --- .../language-server/src/__test__/helper.ts | 18 +- .../src/__test__/multifile/MultifileHelper.ts | 83 +++++++++ .../src/__test__/multifile/completion.test.ts | 33 ++++ .../src/__test__/multifile/hover.test.ts | 21 +++ .../multifile/jumpToDefinition.test.ts | 43 +++++ .../src/__test__/multifile/linting.test.ts | 35 ++++ .../src/__test__/multifile/quickFix.test.ts | 35 ++++ .../src/__test__/multifile/rename.test.ts | 175 ++++++++++++++++++ .../src/__test__/quickFix.test.ts | 6 +- .../src/__test__/rename.test.ts | 21 +-- packages/language-server/src/lib/Schema.ts | 21 ++- .../src/lib/code-actions/rename.ts | 29 ++- .../complete-field-notype/Post.prisma | 8 + .../complete-field-notype/User.prisma | 7 + .../complete-field-notype/config.prisma | 9 + .../multifile/complete-field/Post.prisma | 8 + .../multifile/complete-field/User.prisma | 7 + .../multifile/complete-field/config.prisma | 9 + .../fixtures/multifile/linting/Post.prisma | 9 + .../fixtures/multifile/linting/User.prisma | 7 + .../fixtures/multifile/linting/config.prisma | 9 + .../multifile/quick-fix/Profile.prisma | 5 + .../fixtures/multifile/quick-fix/User.prisma | 7 + .../multifile/quick-fix/config.prisma | 9 + .../fixtures/multifile/user-posts/Post.prisma | 8 + .../fixtures/multifile/user-posts/User.prisma | 7 + .../multifile/user-posts/config.prisma | 9 + 27 files changed, 601 insertions(+), 37 deletions(-) create mode 100644 packages/language-server/src/__test__/multifile/MultifileHelper.ts create mode 100644 packages/language-server/src/__test__/multifile/completion.test.ts create mode 100644 packages/language-server/src/__test__/multifile/hover.test.ts create mode 100644 packages/language-server/src/__test__/multifile/jumpToDefinition.test.ts create mode 100644 packages/language-server/src/__test__/multifile/linting.test.ts create mode 100644 packages/language-server/src/__test__/multifile/quickFix.test.ts create mode 100644 packages/language-server/src/__test__/multifile/rename.test.ts create mode 100644 packages/language-server/test/fixtures/multifile/complete-field-notype/Post.prisma create mode 100644 packages/language-server/test/fixtures/multifile/complete-field-notype/User.prisma create mode 100644 packages/language-server/test/fixtures/multifile/complete-field-notype/config.prisma create mode 100644 packages/language-server/test/fixtures/multifile/complete-field/Post.prisma create mode 100644 packages/language-server/test/fixtures/multifile/complete-field/User.prisma create mode 100644 packages/language-server/test/fixtures/multifile/complete-field/config.prisma create mode 100644 packages/language-server/test/fixtures/multifile/linting/Post.prisma create mode 100644 packages/language-server/test/fixtures/multifile/linting/User.prisma create mode 100644 packages/language-server/test/fixtures/multifile/linting/config.prisma create mode 100644 packages/language-server/test/fixtures/multifile/quick-fix/Profile.prisma create mode 100644 packages/language-server/test/fixtures/multifile/quick-fix/User.prisma create mode 100644 packages/language-server/test/fixtures/multifile/quick-fix/config.prisma create mode 100644 packages/language-server/test/fixtures/multifile/user-posts/Post.prisma create mode 100644 packages/language-server/test/fixtures/multifile/user-posts/User.prisma create mode 100644 packages/language-server/test/fixtures/multifile/user-posts/config.prisma diff --git a/packages/language-server/src/__test__/helper.ts b/packages/language-server/src/__test__/helper.ts index 42b4b0efd9..18f35550fe 100644 --- a/packages/language-server/src/__test__/helper.ts +++ b/packages/language-server/src/__test__/helper.ts @@ -1,21 +1,35 @@ import * as fs from 'fs' import { Position, TextDocument } from 'vscode-languageserver-textdocument' +import { loadSchemaFiles } from '@prisma/schema-files-loader' import path from 'path' import { URI } from 'vscode-uri' +import { PrismaSchema, SchemaDocument } from '../lib/Schema' export const CURSOR_CHARACTER = '|' const fixturesDir = path.resolve(__dirname, '../../test/fixtures') +const multifileFixturesDir = path.join(fixturesDir, 'multifile') export function getTextDocument(testFilePath: string): TextDocument { const absPath = path.join(fixturesDir, testFilePath) const content: string = fs.readFileSync(absPath, 'utf8') - return TextDocument.create(fixturePathToUri(testFilePath), 'prisma', 1, content) + return TextDocument.create(fixturePathToUri(absPath), 'prisma', 1, content) +} + +export async function getMultifileSchema(folderPath: string): Promise { + const files = await loadSchemaFiles(path.join(multifileFixturesDir, folderPath)) + const schemaDocs = files.map(([filePath, content]) => { + const uri = fixturePathToUri(filePath) + const doc = TextDocument.create(uri, 'prisma', 1, content) + return new SchemaDocument(doc) + }) + + return new PrismaSchema(schemaDocs) } export function fixturePathToUri(fixturePath: string) { - const absPath = path.join(fixturesDir, fixturePath) + const absPath = path.isAbsolute(fixturePath) ? fixturePath : path.join(fixturesDir, fixturePath) // that would normalize testFilePath and resolve all of // the . and .. diff --git a/packages/language-server/src/__test__/multifile/MultifileHelper.ts b/packages/language-server/src/__test__/multifile/MultifileHelper.ts new file mode 100644 index 0000000000..31e9786331 --- /dev/null +++ b/packages/language-server/src/__test__/multifile/MultifileHelper.ts @@ -0,0 +1,83 @@ +import { URI } from 'vscode-uri' +import { PrismaSchema, SchemaDocument } from '../../lib/Schema' +import path from 'path' +import { getMultifileSchema } from '../helper' +import { Position, TextEdit } from 'vscode-languageserver' +import { TextDocument } from 'vscode-languageserver-textdocument' + +export async function getMultifileHelper(fixturePath: string) { + const schema = await getMultifileSchema(fixturePath) + const helper = new MultfileHelper(`/multifile/${fixturePath}`, schema) + return helper +} + +class MultfileHelper { + constructor( + private baseDir: string, + readonly schema: PrismaSchema, + ) {} + + file(filePath: string) { + const doc = this.schema.findDocByUri(URI.file(path.join(this.baseDir, filePath)).toString()) + if (!doc) { + throw new Error(`${filePath} is not found fixture`) + } + + return new File(doc) + } + + applyChanges(edits: Record | undefined): Record { + if (!edits) { + return {} + } + const results = {} as Record + for (const [uri, fileEdits] of Object.entries(edits)) { + let doc = this.schema.findDocByUri(uri)?.textDocument + if (!doc) { + doc = TextDocument.create(uri, 'prisma', 1, '') + } + const updatedDoc = TextDocument.applyEdits(doc, fileEdits) + results[uri] = updatedDoc + } + return results + } +} + +class File { + constructor(readonly schemaDocument: SchemaDocument) {} + + get textDocument() { + return this.schemaDocument.textDocument + } + + get uri() { + return this.schemaDocument.uri + } + + lineContaining(match: string) { + for (const line of this.schemaDocument.lines) { + if (line.text.includes(match)) { + return new Line(line.lineIndex, line.untrimmedText) + } + } + throw new Error(`Can not find line with "${match}"`) + } +} + +class Line { + constructor( + readonly lineNumber: number, + readonly text: string, + ) {} + + characterAfter(substring: string): Position { + const index = this.text.indexOf(substring) + if (index === -1) { + throw new Error(`Can not find ${substring} in ${this.text}`) + } + return { + line: this.lineNumber, + character: index + substring.length + 1, + } + } +} diff --git a/packages/language-server/src/__test__/multifile/completion.test.ts b/packages/language-server/src/__test__/multifile/completion.test.ts new file mode 100644 index 0000000000..ddd382e273 --- /dev/null +++ b/packages/language-server/src/__test__/multifile/completion.test.ts @@ -0,0 +1,33 @@ +import { test, expect } from 'vitest' +import { handleCompletionRequest } from '../../lib/MessageHandler' +import { getMultifileHelper } from './MultifileHelper' + +test('type name completion', async () => { + const helper = await getMultifileHelper('complete-field') + const post = helper.file('Post.prisma') + + const response = handleCompletionRequest(helper.schema, post.textDocument, { + textDocument: { + uri: post.uri, + }, + position: post.lineContaining('author Us').characterAfter('U'), + }) + + const userItem = response?.items.find((item) => item.label === 'User') + expect(userItem).not.toBeUndefined() +}) + +test('type name completion with no name typed', async () => { + const helper = await getMultifileHelper('complete-field') + const post = helper.file('Post.prisma') + + const response = handleCompletionRequest(helper.schema, post.textDocument, { + textDocument: { + uri: post.uri, + }, + position: post.lineContaining('author ').characterAfter('r '), + }) + + const userItem = response?.items.find((item) => item.label === 'User') + expect(userItem).not.toBeUndefined() +}) diff --git a/packages/language-server/src/__test__/multifile/hover.test.ts b/packages/language-server/src/__test__/multifile/hover.test.ts new file mode 100644 index 0000000000..3a78072bb7 --- /dev/null +++ b/packages/language-server/src/__test__/multifile/hover.test.ts @@ -0,0 +1,21 @@ +import { test, expect } from 'vitest' +import { handleHoverRequest } from '../../lib/MessageHandler' +import { getMultifileHelper } from './MultifileHelper' + +test('basic doc', async () => { + const helper = await getMultifileHelper('user-posts') + const user = helper.file('User.prisma') + + const response = handleHoverRequest(helper.schema, user.textDocument, { + textDocument: { + uri: user.uri, + }, + position: user.lineContaining('posts Post[]').characterAfter('Po'), + }) + + expect(response).toMatchInlineSnapshot(` + { + "contents": "This is a blog post", + } + `) +}) diff --git a/packages/language-server/src/__test__/multifile/jumpToDefinition.test.ts b/packages/language-server/src/__test__/multifile/jumpToDefinition.test.ts new file mode 100644 index 0000000000..47f3f704cb --- /dev/null +++ b/packages/language-server/src/__test__/multifile/jumpToDefinition.test.ts @@ -0,0 +1,43 @@ +import { test, expect } from 'vitest' +import { handleDefinitionRequest } from '../../lib/MessageHandler' +import { getMultifileHelper } from './MultifileHelper' + +test('basic doc', async () => { + const helper = await getMultifileHelper('user-posts') + const post = helper.file('Post.prisma') + + const response = handleDefinitionRequest(helper.schema, post.textDocument, { + textDocument: { + uri: post.uri, + }, + position: post.lineContaining('author User').characterAfter('Us'), + }) + + expect(response).toMatchInlineSnapshot(` + [ + { + "targetRange": { + "end": { + "character": 1, + "line": 6, + }, + "start": { + "character": 0, + "line": 1, + }, + }, + "targetSelectionRange": { + "end": { + "character": 10, + "line": 1, + }, + "start": { + "character": 6, + "line": 1, + }, + }, + "targetUri": "file:///multifile/user-posts/User.prisma", + }, + ] + `) +}) diff --git a/packages/language-server/src/__test__/multifile/linting.test.ts b/packages/language-server/src/__test__/multifile/linting.test.ts new file mode 100644 index 0000000000..134160e863 --- /dev/null +++ b/packages/language-server/src/__test__/multifile/linting.test.ts @@ -0,0 +1,35 @@ +import { test, expect } from 'vitest' +import { handleDiagnosticsRequest } from '../../lib/MessageHandler' +import { getMultifileHelper } from './MultifileHelper' + +test('invalid doc', async () => { + const helper = await getMultifileHelper('linting') + + const response = handleDiagnosticsRequest(helper.schema) + + expect(response).toMatchInlineSnapshot(` + DiagnosticMap { + "_map": Map { + "file:///multifile/linting/Post.prisma" => [ + { + "message": "Type "Like" is neither a built-in type, nor refers to another model, composite type, or enum.", + "range": { + "end": { + "character": 17, + "line": 7, + }, + "start": { + "character": 13, + "line": 7, + }, + }, + "severity": 1, + "source": "Prisma", + }, + ], + "file:///multifile/linting/User.prisma" => [], + "file:///multifile/linting/config.prisma" => [], + }, + } + `) +}) diff --git a/packages/language-server/src/__test__/multifile/quickFix.test.ts b/packages/language-server/src/__test__/multifile/quickFix.test.ts new file mode 100644 index 0000000000..6c65905233 --- /dev/null +++ b/packages/language-server/src/__test__/multifile/quickFix.test.ts @@ -0,0 +1,35 @@ +import { test, expect } from 'vitest' +import { handleCodeActions, handleDiagnosticsRequest } from '../../lib/MessageHandler' +import { getMultifileHelper } from './MultifileHelper' + +test('basic doc', async () => { + const helper = await getMultifileHelper('quick-fix') + const profile = helper.file('Profile.prisma') + const diagnostics = handleDiagnosticsRequest(helper.schema).get(profile.uri) + + const response = handleCodeActions(helper.schema, profile.textDocument, { + textDocument: { + uri: profile.uri, + }, + range: { + start: profile.lineContaining('user User').characterAfter('us'), + end: profile.lineContaining('user User').characterAfter('user'), + }, + context: { + diagnostics, + }, + }) + + const changes = response[0]?.edit?.changes + const updated = helper.applyChanges(changes) + expect(updated).toMatchInlineSnapshot(` + { + "file:///multifile/quick-fix/Profile.prisma": "model Profile { + id String @id @default(uuid()) + userId String @unique + user User @relation(fields: [userId], references: [id]) + } + ", + } + `) +}) diff --git a/packages/language-server/src/__test__/multifile/rename.test.ts b/packages/language-server/src/__test__/multifile/rename.test.ts new file mode 100644 index 0000000000..33fe7e9a09 --- /dev/null +++ b/packages/language-server/src/__test__/multifile/rename.test.ts @@ -0,0 +1,175 @@ +import { test, expect } from 'vitest' +import { handleRenameRequest } from '../../lib/MessageHandler' +import { getMultifileHelper } from './MultifileHelper' + +test('rename model', async () => { + const helper = await getMultifileHelper('user-posts') + const user = helper.file('User.prisma') + + const response = handleRenameRequest(helper.schema, user.textDocument, { + textDocument: { + uri: user.uri, + }, + position: user.lineContaining('model User').characterAfter('Us'), + newName: 'Account', + }) + + expect(response).toMatchInlineSnapshot(` + { + "changes": { + "file:///multifile/user-posts/Post.prisma": [ + { + "newText": "Account", + "range": { + "end": { + "character": 17, + "line": 6, + }, + "start": { + "character": 13, + "line": 6, + }, + }, + }, + ], + "file:///multifile/user-posts/User.prisma": [ + { + "newText": "Account", + "range": { + "end": { + "character": 10, + "line": 1, + }, + "start": { + "character": 6, + "line": 1, + }, + }, + }, + { + "newText": " @@map("User") + }", + "range": { + "end": { + "character": 1, + "line": 6, + }, + "start": { + "character": 0, + "line": 6, + }, + }, + }, + ], + }, + } + `) + + expect(helper.applyChanges(response?.changes)).toMatchInlineSnapshot(` + { + "file:///multifile/user-posts/Post.prisma": "/// This is a blog post + model Post { + id String @id @default(uuid()) + title String + content String + authorId String + author Account @relation(fields: [authorId], references: [id]) + } + ", + "file:///multifile/user-posts/User.prisma": "/// This is the user of the platform + model Account { + id String @id @default(uuid()) + name String + email String + posts Post[] + @@map("User") + } + ", + } + `) +}) + +test('rename field', async () => { + const helper = await getMultifileHelper('user-posts') + const user = helper.file('User.prisma') + + const response = handleRenameRequest(helper.schema, user.textDocument, { + textDocument: { + uri: user.uri, + }, + position: user.lineContaining('id').characterAfter('i'), + newName: 'primaryKey', + }) + + expect(response).toMatchInlineSnapshot(` + { + "changes": { + "file:///multifile/user-posts/Post.prisma": [ + { + "newText": "primaryKey", + "range": { + "end": { + "character": 65, + "line": 6, + }, + "start": { + "character": 63, + "line": 6, + }, + }, + }, + ], + "file:///multifile/user-posts/User.prisma": [ + { + "newText": "primaryKey", + "range": { + "end": { + "character": 6, + "line": 2, + }, + "start": { + "character": 4, + "line": 2, + }, + }, + }, + { + "newText": " @map("id")", + "range": { + "end": { + "character": 36, + "line": 2, + }, + "start": { + "character": 36, + "line": 2, + }, + }, + }, + ], + }, + } + `) + + expect(helper.applyChanges(response?.changes)).toMatchInlineSnapshot(` + { + "file:///multifile/user-posts/Post.prisma": "/// This is a blog post + model Post { + id String @id @default(uuid()) + title String + content String + authorId String + author User @relation(fields: [authorId], references: [primaryKey]) + } + ", + "file:///multifile/user-posts/User.prisma": "/// This is the user of the platform + model User { + primaryKey String @id @default(uuid() @map("id")) + name String + email String + posts Post[] + } + ", + } + `) +}) diff --git a/packages/language-server/src/__test__/quickFix.test.ts b/packages/language-server/src/__test__/quickFix.test.ts index e32409d611..0a15a5eae4 100644 --- a/packages/language-server/src/__test__/quickFix.test.ts +++ b/packages/language-server/src/__test__/quickFix.test.ts @@ -215,11 +215,7 @@ describe('Quick Fixes', () => { }, ] - let character = 11 - - if (process.platform === 'win32') { - character = 12 - } + const character = 11 assertQuickFix( [ diff --git a/packages/language-server/src/__test__/rename.test.ts b/packages/language-server/src/__test__/rename.test.ts index 8e8ee98551..275ebf871b 100644 --- a/packages/language-server/src/__test__/rename.test.ts +++ b/packages/language-server/src/__test__/rename.test.ts @@ -2,7 +2,6 @@ import type { TextDocument } from 'vscode-languageserver-textdocument' import { handleRenameRequest } from '../lib/MessageHandler' import { WorkspaceEdit, RenameParams, Position } from 'vscode-languageserver' import { getTextDocument } from './helper' -import { MAX_SAFE_VALUE_i32 } from '../lib/constants' import { PrismaSchema } from '../lib/Schema' import { describe, test, expect } from 'vitest' @@ -368,8 +367,8 @@ describe('Rename', () => { { newText: ' @map("Album")', range: { - start: { line: 136, character: MAX_SAFE_VALUE_i32 }, - end: { line: 136, character: MAX_SAFE_VALUE_i32 }, + start: { line: 136, character: 33 }, + end: { line: 136, character: 33 }, }, }, ], @@ -415,8 +414,8 @@ describe('Rename', () => { { newText: ' @map("authorId")', range: { - start: { line: 4, character: MAX_SAFE_VALUE_i32 }, - end: { line: 4, character: MAX_SAFE_VALUE_i32 }, + start: { line: 4, character: 16 }, + end: { line: 4, character: 16 }, }, }, { @@ -457,8 +456,8 @@ describe('Rename', () => { { newText: ' @map("title")', range: { - start: { line: 17, character: MAX_SAFE_VALUE_i32 }, - end: { line: 17, character: MAX_SAFE_VALUE_i32 }, + start: { line: 17, character: 16 }, + end: { line: 17, character: 16 }, }, }, { @@ -491,8 +490,8 @@ describe('Rename', () => { { newText: ' @map("humanId")', range: { - start: { line: 25, character: MAX_SAFE_VALUE_i32 }, - end: { line: 25, character: MAX_SAFE_VALUE_i32 }, + start: { line: 25, character: 13 }, + end: { line: 25, character: 13 }, }, }, { @@ -566,8 +565,8 @@ describe('Rename', () => { { newText: ' @map("A_VARIANT_WITH_UNDERSCORES")', range: { - start: { line: 8, character: MAX_SAFE_VALUE_i32 }, - end: { line: 8, character: MAX_SAFE_VALUE_i32 }, + start: { line: 8, character: 27 }, + end: { line: 8, character: 27 }, }, }, { diff --git a/packages/language-server/src/lib/Schema.ts b/packages/language-server/src/lib/Schema.ts index ffd633e221..3c3db8c22a 100644 --- a/packages/language-server/src/lib/Schema.ts +++ b/packages/language-server/src/lib/Schema.ts @@ -9,6 +9,7 @@ import { import { Position, TextDocuments } from 'vscode-languageserver' import { TextDocument } from 'vscode-languageserver-textdocument' import { URI } from 'vscode-uri' +import { getCurrentLine } from './ast' export type Line = { readonly document: SchemaDocument @@ -17,18 +18,18 @@ export type Line = { readonly untrimmedText: string } export class SchemaDocument { - readonly lines: Line[] + readonly lines: Line[] = [] - constructor(private textDocument: TextDocument) { - this.lines = textDocument - .getText() - .split(/\r?\n/) - .map((untrimmedText, lineIndex) => ({ + constructor(readonly textDocument: TextDocument) { + for (let i = 0; i < textDocument.lineCount; i++) { + const line = getCurrentLine(textDocument, i) + this.lines.push({ document: this, - lineIndex, - untrimmedText, - text: untrimmedText.trim(), - })) + lineIndex: i, + untrimmedText: line, + text: line.trim(), + }) + } } get uri(): string { diff --git a/packages/language-server/src/lib/code-actions/rename.ts b/packages/language-server/src/lib/code-actions/rename.ts index bdcba3bd30..c823b7298b 100644 --- a/packages/language-server/src/lib/code-actions/rename.ts +++ b/packages/language-server/src/lib/code-actions/rename.ts @@ -11,8 +11,8 @@ import { getWordAtPosition, } from '../ast' import { BlockType } from '../types' -import { MAX_SAFE_VALUE_i32, relationNamesRegexFilter } from '../constants' -import { PrismaSchema } from '../Schema' +import { relationNamesRegexFilter } from '../constants' +import { Line, PrismaSchema } from '../Schema' function getType(currentLine: string): string { const wordsInLine: string[] = currentLine.split(/\s+/) @@ -154,18 +154,19 @@ export function printLogMessage( console.log(typeOfRename + message) } -function insertInlineRename(fileUri: string, currentName: string, line: number): EditsMap { +function insertInlineRename(currentName: string, line: Line): EditsMap { + const character = lastNoNewlineCharacter(line.untrimmedText) return { - [fileUri]: [ + [line.document.uri]: [ { range: { start: { - line: line, - character: MAX_SAFE_VALUE_i32, + line: line.lineIndex, + character, }, end: { - line: line, - character: MAX_SAFE_VALUE_i32, + line: line.lineIndex, + character, }, }, newText: ` @map("${currentName}")`, @@ -174,6 +175,15 @@ function insertInlineRename(fileUri: string, currentName: string, line: number): } } +function lastNoNewlineCharacter(lineText: string) { + for (let i = lineText.length - 1; i >= 0; i--) { + if (lineText[i] !== '\n' && lineText[i] !== '\r') { + return i + } + } + return 0 +} + function insertMapBlockAttribute(oldName: string, block: Block): EditsMap { return { [block.definingDocument.uri]: [ @@ -466,7 +476,8 @@ export function insertMapAttribute( if (isDatamodelBlockRename) { return insertMapBlockAttribute(currentName, block) } else { - return insertInlineRename(block.definingDocument.uri, currentName, position.line) + const line = block.definingDocument.lines[position.line] + return insertInlineRename(currentName, line) } } diff --git a/packages/language-server/test/fixtures/multifile/complete-field-notype/Post.prisma b/packages/language-server/test/fixtures/multifile/complete-field-notype/Post.prisma new file mode 100644 index 0000000000..5903b7472a --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/complete-field-notype/Post.prisma @@ -0,0 +1,8 @@ +/// This is a blog post +model Post { + id String @id @default(uuid()) + title String + content String + authorId String + author +} diff --git a/packages/language-server/test/fixtures/multifile/complete-field-notype/User.prisma b/packages/language-server/test/fixtures/multifile/complete-field-notype/User.prisma new file mode 100644 index 0000000000..030c4d5bb1 --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/complete-field-notype/User.prisma @@ -0,0 +1,7 @@ +/// This is the user of the platform +model User { + id String @id @default(uuid()) + name String + email String + posts Post[] +} diff --git a/packages/language-server/test/fixtures/multifile/complete-field-notype/config.prisma b/packages/language-server/test/fixtures/multifile/complete-field-notype/config.prisma new file mode 100644 index 0000000000..97fbd437ae --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/complete-field-notype/config.prisma @@ -0,0 +1,9 @@ +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" + previewFeatures = ["prismaSchemaFolder"] +} diff --git a/packages/language-server/test/fixtures/multifile/complete-field/Post.prisma b/packages/language-server/test/fixtures/multifile/complete-field/Post.prisma new file mode 100644 index 0000000000..f32cffe1df --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/complete-field/Post.prisma @@ -0,0 +1,8 @@ +/// This is a blog post +model Post { + id String @id @default(uuid()) + title String + content String + authorId String + author Us +} diff --git a/packages/language-server/test/fixtures/multifile/complete-field/User.prisma b/packages/language-server/test/fixtures/multifile/complete-field/User.prisma new file mode 100644 index 0000000000..030c4d5bb1 --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/complete-field/User.prisma @@ -0,0 +1,7 @@ +/// This is the user of the platform +model User { + id String @id @default(uuid()) + name String + email String + posts Post[] +} diff --git a/packages/language-server/test/fixtures/multifile/complete-field/config.prisma b/packages/language-server/test/fixtures/multifile/complete-field/config.prisma new file mode 100644 index 0000000000..97fbd437ae --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/complete-field/config.prisma @@ -0,0 +1,9 @@ +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" + previewFeatures = ["prismaSchemaFolder"] +} diff --git a/packages/language-server/test/fixtures/multifile/linting/Post.prisma b/packages/language-server/test/fixtures/multifile/linting/Post.prisma new file mode 100644 index 0000000000..cd371252b8 --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/linting/Post.prisma @@ -0,0 +1,9 @@ +/// This is a blog post +model Post { + id String @id @default(uuid()) + title String + content String + authorId String + author User @relation(fields: [authorId], references: [id]) + likes Like[] +} diff --git a/packages/language-server/test/fixtures/multifile/linting/User.prisma b/packages/language-server/test/fixtures/multifile/linting/User.prisma new file mode 100644 index 0000000000..030c4d5bb1 --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/linting/User.prisma @@ -0,0 +1,7 @@ +/// This is the user of the platform +model User { + id String @id @default(uuid()) + name String + email String + posts Post[] +} diff --git a/packages/language-server/test/fixtures/multifile/linting/config.prisma b/packages/language-server/test/fixtures/multifile/linting/config.prisma new file mode 100644 index 0000000000..97fbd437ae --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/linting/config.prisma @@ -0,0 +1,9 @@ +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" + previewFeatures = ["prismaSchemaFolder"] +} diff --git a/packages/language-server/test/fixtures/multifile/quick-fix/Profile.prisma b/packages/language-server/test/fixtures/multifile/quick-fix/Profile.prisma new file mode 100644 index 0000000000..2d19dd9e00 --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/quick-fix/Profile.prisma @@ -0,0 +1,5 @@ +model Profile { + id String @id @default(uuid()) + userId String + user User @relation(fields: [userId], references: [id]) +} diff --git a/packages/language-server/test/fixtures/multifile/quick-fix/User.prisma b/packages/language-server/test/fixtures/multifile/quick-fix/User.prisma new file mode 100644 index 0000000000..c53699b1b4 --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/quick-fix/User.prisma @@ -0,0 +1,7 @@ +/// This is the user of the platform +model User { + id String @id @default(uuid()) + name String + email String + profile Profile +} diff --git a/packages/language-server/test/fixtures/multifile/quick-fix/config.prisma b/packages/language-server/test/fixtures/multifile/quick-fix/config.prisma new file mode 100644 index 0000000000..97fbd437ae --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/quick-fix/config.prisma @@ -0,0 +1,9 @@ +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" + previewFeatures = ["prismaSchemaFolder"] +} diff --git a/packages/language-server/test/fixtures/multifile/user-posts/Post.prisma b/packages/language-server/test/fixtures/multifile/user-posts/Post.prisma new file mode 100644 index 0000000000..78de5db220 --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/user-posts/Post.prisma @@ -0,0 +1,8 @@ +/// This is a blog post +model Post { + id String @id @default(uuid()) + title String + content String + authorId String + author User @relation(fields: [authorId], references: [id]) +} diff --git a/packages/language-server/test/fixtures/multifile/user-posts/User.prisma b/packages/language-server/test/fixtures/multifile/user-posts/User.prisma new file mode 100644 index 0000000000..030c4d5bb1 --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/user-posts/User.prisma @@ -0,0 +1,7 @@ +/// This is the user of the platform +model User { + id String @id @default(uuid()) + name String + email String + posts Post[] +} diff --git a/packages/language-server/test/fixtures/multifile/user-posts/config.prisma b/packages/language-server/test/fixtures/multifile/user-posts/config.prisma new file mode 100644 index 0000000000..97fbd437ae --- /dev/null +++ b/packages/language-server/test/fixtures/multifile/user-posts/config.prisma @@ -0,0 +1,9 @@ +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" + previewFeatures = ["prismaSchemaFolder"] +}