-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Language-Tools Documentation #4191
Closed
Closed
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
7758a48
skeleton draft
Druue 1af311f
Fix build errors
d664f53
Fix broken link
111c2c4
Reorganise directory structure
2881ca1
Spellcheck fix
70dc28e
Formatting fixes
82127e9
Terminology fix
19e9ae8
fixed: inline schema formatting && representation. Squigglies are now…
Druue 57ec5b4
code actions toc wording; squiggly alignment
Druue f76da90
vscode wip index
Druue 41e9504
Update example models
50ea41e
Update intro text
8cdeb6b
Update add unique quick fixes
2161d0b
Update example descriptions
088a600
Add experimental features example
66802c4
Added link to Language Tools on front-page for docs
Druue f393a55
links to vs code and ls in language-tools
Druue d159996
Missing index quick fix
5fba8c4
completions images
Druue ec47507
updated formatting for create new enum
Druue 0ab9c4e
added small blurbs on:
Druue 3e2c9af
completions
Druue 8a9bf9e
wording to include "Extension"
Druue 2d0cb7f
move editor keybind to be global code actions
Druue c51be30
images
Druue 1729ea3
formatting; linting; document symbols; highlighting; words
Druue 4242616
Merge branch 'main' into feat/language-server
nilubava 48dda8d
Merge branch 'main' into feat/language-server
janpio 8fde7e3
Optimised images with calibre/image-actions
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
266 changes: 266 additions & 0 deletions
266
...mponents/09-prisma-language-tools/01-prisma-language-server/02-code-actions.mdx
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,266 @@ | ||
--- | ||
title: 'Code Actions' | ||
metaTitle: 'Code Actions' | ||
metaDescription: 'Code Actions ...' | ||
tocDepth: 2 | ||
--- | ||
|
||
<TopBlock> | ||
|
||
The Prisma Language Server provides the following options to restructure code and fix issues: | ||
|
||
- [Quick Fixes](#quick-fixes) represent code changes that fix issues that the Prisma Language Server identifies in your code. | ||
- [Refactorings](#refactorings) represent ways to restructure your code. | ||
|
||
</TopBlock> | ||
|
||
## Quick Fixes | ||
|
||
This section lists the Quick Fixes provided by the Prisma Language Server. | ||
|
||
Quick fixes have the following key bindings in different code editors: | ||
|
||
| Editor | Key binding | | ||
| ------- | --------------- | | ||
| VS Code | `Cmd / Win + .` | | ||
|
||
### Add Index for Relation Fields | ||
|
||
![applying a quick-fix for relationMode to add index](code_action-relation_mode-index.gif) | ||
|
||
### Add a missing <inlineCode>@unique</inlineCode> attribute to a relation | ||
|
||
These Quick Fixes add missing `@unique` attributes to either the referencing or the referenced side of a relation. The following examples add missing `@unique` attributes to a `Profile` model that references a `Post` model. | ||
|
||
#### Add a missing <inlineCode>@unique</inlineCode> attribute to a referencing field | ||
|
||
This example adds a missing `@unique` attribute to the `userId` relation scalar field in the referencing `Profile` model: | ||
|
||
<TabbedContent tabs={[<FileWithIcon text="Before" icon="file"/>, <FileWithIcon text="After" icon="file"/>]}> | ||
<tab> | ||
|
||
```prisma | ||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Profile { | ||
id Int @id | ||
userId String | ||
user User @relation(fields: [userId], references: [email]) | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
// Quick Fix: Make referencing field(s) unique | ||
} | ||
|
||
model User { | ||
id Int @id | ||
email String @unique | ||
profile Profile? | ||
} | ||
``` | ||
|
||
</tab> | ||
<tab> | ||
|
||
```prisma | ||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Profile { | ||
id Int @id | ||
userId String @unique // @unique attribute added | ||
user User @relation(fields: [userId], references: [email]) | ||
} | ||
|
||
model User { | ||
id Int @id | ||
email String @unique | ||
profile Profile? | ||
} | ||
``` | ||
|
||
</tab> | ||
</TabbedContent> | ||
|
||
#### Add a missing <inlineCode>@unique</inlineCode> attribute to a referenced field | ||
|
||
This example adds a `@unique` attribute to the `email` field in the referenced `Post` model: | ||
|
||
<TabbedContent tabs={[<FileWithIcon text="Before" icon="file"/>, <FileWithIcon text="After" icon="file"/>]}> | ||
<tab> | ||
|
||
```prisma | ||
model Profile { | ||
id Int @id | ||
userId String @unique | ||
user User @relation(fields: [userId], references: [email]) | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
// Quick Fix: Make referenced field(s) unique | ||
} | ||
|
||
model User { | ||
id Int @id | ||
email String | ||
profile Profile? | ||
} | ||
``` | ||
|
||
</tab> | ||
<tab> | ||
|
||
```prisma | ||
model Profile { | ||
id Int @id | ||
userId String @unique | ||
user User @relation(fields: [userId], references: [email]) | ||
} | ||
|
||
model User { | ||
id Int @id | ||
email String @unique // @unique attribute added | ||
profile Profile? | ||
} | ||
``` | ||
|
||
</tab> | ||
</TabbedContent> | ||
|
||
### Fix the spelling of a field | ||
|
||
This Quick Fix updates incorrectly spelled relation types. In the following example, the `User` model has a `posts` field with an incorrectly named `Poste[]` relation type. The Quick Fix corrects the name to `Post[]`: | ||
|
||
<TabbedContent tabs={[<FileWithIcon text="Before" icon="file"/>, <FileWithIcon text="After" icon="file"/>]}> | ||
<tab> | ||
|
||
```prisma | ||
model User { | ||
id Int @id | ||
posts Poste[] | ||
// ^^^^^ | ||
// Quick Fix: Change spelling to 'Post' | ||
} | ||
|
||
model Post { | ||
id Int @id | ||
User User? @relation(fields: [userId], references: [id]) | ||
userId Int? | ||
} | ||
``` | ||
|
||
</tab> | ||
<tab> | ||
|
||
```prisma | ||
model User { | ||
id Int @id | ||
posts Post[] // Spelling corrected | ||
} | ||
|
||
model Post { | ||
id Int @id | ||
User User? @relation(fields: [userId], references: [id]) | ||
userId Int? | ||
} | ||
``` | ||
|
||
</tab> | ||
</TabbedContent> | ||
|
||
### Create a new model or enum | ||
|
||
This Quick Fix suggests that you add a new model or enum if you add a relation field to your model with a relation type that you have not yet defined. In the following example, the `User` model has a `posts` relation field, but no `Post` model or enum currently exists: | ||
|
||
<TabbedContent tabs={[ | ||
<FileWithIcon text="Before" icon="file"/>, | ||
<FileWithIcon text="After (model)" icon="file"/>, | ||
<FileWithIcon text="After (enum)" icon="file"/>, | ||
]}> | ||
<tab> | ||
|
||
```prisma | ||
model User { | ||
id Int @id | ||
posts Post[] | ||
// ^^^^ | ||
// Quick Fix: Create new model/enum 'Post' | ||
} | ||
``` | ||
|
||
</tab> | ||
<tab> | ||
|
||
```prisma | ||
model User { | ||
id Int @id | ||
posts Post[] | ||
} | ||
|
||
// New model added | ||
model Post { | ||
|
||
} | ||
``` | ||
|
||
</tab> | ||
<tab> | ||
|
||
```prisma | ||
model User { | ||
id Int @id | ||
posts Post|[] | ||
} | ||
|
||
// New enum added | ||
enum Post { | ||
|
||
} | ||
``` | ||
|
||
</tab> | ||
</TabbedContent> | ||
|
||
### Rename the <inlinecode>experimentalFeatures</inlinecode> field | ||
|
||
This Quick Fix renames the legacy `experimentalFeatures` field in the `generator` block to `previewFeatures`: | ||
|
||
<TabbedContent tabs={[<FileWithIcon text="Before" icon="file"/>, <FileWithIcon text="After" icon="file"/>]}> | ||
<tab> | ||
|
||
```prisma | ||
generator client { | ||
provider = "prisma-client-js" | ||
experimentalFeatures = ["fullTextSearch"] | ||
// ^^^^^^^^^^^^^^^^^ | ||
// Quick Fix: Rename property to 'previewFeatures' | ||
} | ||
``` | ||
|
||
</tab> | ||
<tab> | ||
|
||
```prisma | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["fullTextSearch"] // Correct name | ||
} | ||
``` | ||
|
||
</tab> | ||
</TabbedContent> | ||
|
||
## Refactorings | ||
|
||
This section lists the refactorings provided by the Prisma Language Server. | ||
|
||
### Rename | ||
|
||
| Editor | Key binding | | ||
| ------- | ----------- | | ||
| VS Code | `F2` | | ||
|
||
Renames the word currently below the cursor and any references within the same file. This currently only handles surface-level renames with a `@map()` to the original name. Therefore the client will use the new name but the underlying db will still use the old. | ||
|
||
![Gif of renaming a model in VS Code](code_action-rename.gif) |
42 changes: 42 additions & 0 deletions
42
...ponents/09-prisma-language-tools/01-prisma-language-server/03-auto-complete.mdx
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,42 @@ | ||
--- | ||
title: 'Completions' | ||
metaTitle: 'Completions' | ||
metaDescription: 'Completions ...' | ||
tocDepth: 2 | ||
--- | ||
|
||
<TopBlock> | ||
|
||
- [Field attributes](#field-attributes): ... | ||
- [Native types](#native-types): ... | ||
- [Supported fields](#supported-fields): ... | ||
|
||
</TopBlock> | ||
|
||
## Field attributes | ||
|
||
### Example | ||
|
||
![completions-field-attributes](completion-field-attributes.png) | ||
|
||
## Native types | ||
|
||
### Example | ||
|
||
![completions-native-db-types](completion-native-db-types.png) | ||
|
||
## Supported fields | ||
|
||
| block | field | | ||
| ---------- | --------------- | | ||
| generator | provider | | ||
| generator | engineType | | ||
| generator | previewFeatures | | ||
| --- | --- | | ||
| datasource | provider | | ||
| datasource | url | | ||
| datasource | relationMode | | ||
|
||
### Example | ||
|
||
![completions-supported-fields-datasource-provider](completion-datasource-provider-fields.png) |
37 changes: 37 additions & 0 deletions
37
...pts/100-components/09-prisma-language-tools/01-prisma-language-server/index.mdx
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,37 @@ | ||
--- | ||
title: 'Prisma Language Server' | ||
metaTitle: 'Prisma Language Server' | ||
metaDescription: 'The Prisma Language Server ...' | ||
--- | ||
|
||
<TopBlock> | ||
|
||
The Prisma Language Server implements the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) and offers functionality in the following areas: | ||
|
||
<!-- TODO: link to https://www.prisma.io/docs/concepts/components/prisma-schema#auto-formatting ? --> | ||
|
||
- [Formatting](#formatting): ... | ||
- [Linting and validation](#linting): | ||
- [Auto-completion](/concepts/components/prisma-language-tools/prisma-language-server/auto-complete): ... | ||
- [Code Actions](/concepts/components/prisma-language-tools/prisma-language-server/code-actions): ... | ||
- [Tooltips](#tooltips): ... | ||
- [Go to Definition](#go-to-definition): ... | ||
- [Document symbols](#document-symbols): ... | ||
keerlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<!-- TODO: [**File Watcher?**](file-watcher): ... ---> | ||
|
||
<!-- TODO: Do we want to link the language-tools source? --> | ||
|
||
<!-- TODO: Do we want to menton prisma-engines -- part of the language server is implemented there --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. . |
||
|
||
</TopBlock> | ||
|
||
## Formatting | ||
|
||
## Linting | ||
|
||
## Tooltips | ||
|
||
## Go to Definition | ||
|
||
## Document symbols |
38 changes: 38 additions & 0 deletions
38
content/200-concepts/100-components/09-prisma-language-tools/05-vs-code/index.mdx
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,38 @@ | ||
--- | ||
title: 'Prisma VS Code Extension' | ||
metaTitle: 'Prisma VS Code Extension' | ||
metaDescription: 'Prisma VS Code Extension' | ||
--- | ||
|
||
<TopBlock> | ||
|
||
- [Syntax Highlighting](#syntax-highlighting) | ||
- [Colour Theme Validation](#colour-theme-validation) | ||
- [Client File Watcher](#client-file-watcher) | ||
- [Insider](#insider) | ||
|
||
</TopBlock> | ||
|
||
## Syntax Highlighting | ||
|
||
<!-- TODO ... --> | ||
|
||
## Colour Theme Validation | ||
|
||
To ensure effective syntax highlighting, ... emit the following warning: | ||
|
||
<!-- TODO: Picture? --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. . |
||
|
||
> The VS Code Color Theme {currentTheme} you are using unfortunately does not fully support syntax highlighting. We suggest you switch to 'suggestedTheme' which does fully support it and will give you a better experience. | ||
|
||
## Client File Watcher | ||
|
||
Monitors for changes in the client types and will refresh the TypeScript language server on detected change. | ||
|
||
## Insider | ||
|
||
It is not reccomended to have both the Stable and Insider release of the Prisma VS Code extension enabled in a given workspace. On detection, we emit the following warning: | ||
|
||
<!-- TODO: Picture? --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. . |
||
|
||
> You have both the Insider and stable Prisma VS Code extension installed. Please uninstall or disable one of them for a better experience. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to have a link to the auto-formatting section in prisma-schema here?