-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* companion pr to prisma/prisma-engines#4934 * test references in LT --------- Co-authored-by: Serhii Tatarintsev <[email protected]>
- Loading branch information
Showing
9 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
packages/language-server/src/__test__/__fixtures__/multi-file/references/config.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["prismaSchemaFolder", "views"] | ||
} | ||
|
||
datasource db { | ||
provider = "mongodb" | ||
url = env("DATABASE_URL") | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/language-server/src/__test__/__fixtures__/multi-file/references/enums.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/// enum doc | ||
enum Pet { | ||
/// Cat doc | ||
Cat | ||
RedPanda | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/language-server/src/__test__/__fixtures__/multi-file/references/models.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
model User { | ||
id String @id @map("_id") | ||
posts Post[] | ||
/// field doc | ||
pet Pet | ||
address Address | ||
indexedField String | ||
@@index([indexedField]) | ||
} | ||
|
||
/// Documentation | ||
model Post { | ||
id String @id @map("_id") | ||
authorId String | ||
author User @relation(fields: [authorId], references: [id]) | ||
blah UserTwo[] | ||
} | ||
|
||
model B { | ||
/// field doc | ||
id String @id @map("_id") | ||
bId String? | ||
bees B[] @relation(name: "bees") | ||
B B? @relation(name: "bees", fields: [bId], references: [id], onDelete: NoAction, onUpdate: NoAction) | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/language-server/src/__test__/__fixtures__/multi-file/references/types.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// Address doc | ||
type Address { | ||
street String | ||
city String | ||
/// poBox doc | ||
poBox POBox | ||
} | ||
|
||
/// Nested ct doc | ||
type POBox { | ||
name String | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/language-server/src/__test__/__fixtures__/multi-file/references/views.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
view UserTwo { | ||
id String @id @map("_id") | ||
postId String | ||
posts Post @relation(fields: [postId], references: [id]) | ||
address Address | ||
uniqueField String | ||
otherUniqueField String | ||
@@unique(fields: [uniqueField]) | ||
@@unique([otherUniqueField]) | ||
@@unique([address.poBox.name]) | ||
@@map("hi") | ||
} |
283 changes: 283 additions & 0 deletions
283
packages/language-server/src/__test__/references.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,283 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { Position, ReferenceParams } from 'vscode-languageserver' | ||
import { handleReferencesRequest } from '../lib/MessageHandler' | ||
import { PrismaSchema } from '../lib/Schema' | ||
import { getMultifileHelper } from './MultifileHelper' | ||
|
||
const getReferences = async (uri: string, schema: PrismaSchema, position: Position) => { | ||
const params: ReferenceParams = { | ||
textDocument: { uri: uri }, | ||
position, | ||
context: { includeDeclaration: true }, | ||
} | ||
|
||
return handleReferencesRequest(schema, params) | ||
} | ||
describe('References', async () => { | ||
const helper = await getMultifileHelper('references') | ||
|
||
test('of a composite type block name', async () => { | ||
const file = helper.file('types.prisma') | ||
|
||
const references = await getReferences( | ||
file.uri, | ||
helper.schema, | ||
file.lineContaining('type Address').characterAfter('Addr'), | ||
) | ||
|
||
expect(references).not.toBeUndefined() | ||
expect(references).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 12, | ||
"line": 1, | ||
}, | ||
"start": { | ||
"character": 5, | ||
"line": 1, | ||
}, | ||
}, | ||
"uri": "file:///references/types.prisma", | ||
}, | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 19, | ||
"line": 6, | ||
}, | ||
"start": { | ||
"character": 12, | ||
"line": 6, | ||
}, | ||
}, | ||
"uri": "file:///references/models.prisma", | ||
}, | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 19, | ||
"line": 6, | ||
}, | ||
"start": { | ||
"character": 12, | ||
"line": 6, | ||
}, | ||
}, | ||
"uri": "file:///references/views.prisma", | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
test('of a composite type as a field type', async () => { | ||
const file = helper.file('models.prisma') | ||
|
||
const references = await getReferences( | ||
file.uri, | ||
helper.schema, | ||
file.lineContaining('address Address').characterAfter('Addr'), | ||
) | ||
|
||
expect(references).not.toBeUndefined() | ||
expect(references).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 12, | ||
"line": 1, | ||
}, | ||
"start": { | ||
"character": 5, | ||
"line": 1, | ||
}, | ||
}, | ||
"uri": "file:///references/types.prisma", | ||
}, | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 19, | ||
"line": 6, | ||
}, | ||
"start": { | ||
"character": 12, | ||
"line": 6, | ||
}, | ||
}, | ||
"uri": "file:///references/models.prisma", | ||
}, | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 19, | ||
"line": 6, | ||
}, | ||
"start": { | ||
"character": 12, | ||
"line": 6, | ||
}, | ||
}, | ||
"uri": "file:///references/views.prisma", | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
test('of a model block name', async () => { | ||
const file = helper.file('models.prisma') | ||
|
||
const references = await getReferences( | ||
file.uri, | ||
helper.schema, | ||
file.lineContaining('model Post').characterAfter('Po'), | ||
) | ||
|
||
expect(references).not.toBeUndefined() | ||
expect(references).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 10, | ||
"line": 14, | ||
}, | ||
"start": { | ||
"character": 6, | ||
"line": 14, | ||
}, | ||
}, | ||
"uri": "file:///references/models.prisma", | ||
}, | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 16, | ||
"line": 3, | ||
}, | ||
"start": { | ||
"character": 12, | ||
"line": 3, | ||
}, | ||
}, | ||
"uri": "file:///references/models.prisma", | ||
}, | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 15, | ||
"line": 4, | ||
}, | ||
"start": { | ||
"character": 11, | ||
"line": 4, | ||
}, | ||
}, | ||
"uri": "file:///references/views.prisma", | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
test('of a model relation as a field type', async () => { | ||
const file = helper.file('models.prisma') | ||
|
||
const references = await getReferences( | ||
file.uri, | ||
helper.schema, | ||
file.lineContaining('author User').characterAfter('Us'), | ||
) | ||
|
||
expect(references).not.toBeUndefined() | ||
expect(references).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 10, | ||
"line": 0, | ||
}, | ||
"start": { | ||
"character": 6, | ||
"line": 0, | ||
}, | ||
}, | ||
"uri": "file:///references/models.prisma", | ||
}, | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 17, | ||
"line": 17, | ||
}, | ||
"start": { | ||
"character": 13, | ||
"line": 17, | ||
}, | ||
}, | ||
"uri": "file:///references/models.prisma", | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
test('of a field from relation fields', async () => { | ||
const file = helper.file('models.prisma') | ||
|
||
const references = await getReferences( | ||
file.uri, | ||
helper.schema, | ||
file.lineContaining('author User').characterAfter('fields: [auth'), | ||
) | ||
|
||
expect(references).not.toBeUndefined() | ||
expect(references).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 12, | ||
"line": 16, | ||
}, | ||
"start": { | ||
"character": 4, | ||
"line": 16, | ||
}, | ||
}, | ||
"uri": "file:///references/models.prisma", | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
test('of a field from relation fields', async () => { | ||
const file = helper.file('models.prisma') | ||
|
||
const references = await getReferences( | ||
file.uri, | ||
helper.schema, | ||
file.lineContaining('author User').characterAfter('references: [i'), | ||
) | ||
|
||
expect(references).not.toBeUndefined() | ||
expect(references).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"range": { | ||
"end": { | ||
"character": 6, | ||
"line": 1, | ||
}, | ||
"start": { | ||
"character": 4, | ||
"line": 1, | ||
}, | ||
}, | ||
"uri": "file:///references/models.prisma", | ||
}, | ||
] | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.