Skip to content
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
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7758a48
skeleton draft
Druue Dec 5, 2022
1af311f
Fix build errors
Dec 6, 2022
d664f53
Fix broken link
Dec 6, 2022
111c2c4
Reorganise directory structure
Dec 6, 2022
2881ca1
Spellcheck fix
Dec 6, 2022
70dc28e
Formatting fixes
Dec 6, 2022
82127e9
Terminology fix
Dec 6, 2022
19e9ae8
fixed: inline schema formatting && representation. Squigglies are now…
Druue Dec 7, 2022
57ec5b4
code actions toc wording; squiggly alignment
Druue Dec 7, 2022
f76da90
vscode wip index
Druue Dec 7, 2022
41e9504
Update example models
Dec 8, 2022
50ea41e
Update intro text
Dec 8, 2022
8cdeb6b
Update add unique quick fixes
Dec 8, 2022
2161d0b
Update example descriptions
Dec 8, 2022
088a600
Add experimental features example
Dec 8, 2022
66802c4
Added link to Language Tools on front-page for docs
Druue Dec 14, 2022
f393a55
links to vs code and ls in language-tools
Druue Dec 14, 2022
d159996
Missing index quick fix
Dec 19, 2022
5fba8c4
completions images
Druue Dec 19, 2022
ec47507
updated formatting for create new enum
Druue Dec 19, 2022
0ab9c4e
added small blurbs on:
Druue Dec 20, 2022
3e2c9af
completions
Druue Dec 20, 2022
8a9bf9e
wording to include "Extension"
Druue Dec 20, 2022
2d0cb7f
move editor keybind to be global code actions
Druue Dec 20, 2022
c51be30
images
Druue Dec 20, 2022
1729ea3
formatting; linting; document symbols; highlighting; words
Druue Dec 21, 2022
4242616
Merge branch 'main' into feat/language-server
nilubava Feb 13, 2023
48dda8d
Merge branch 'main' into feat/language-server
janpio Nov 17, 2023
8fde7e3
Optimised images with calibre/image-actions
github-actions[bot] Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ const siteConfig = {
url: 'concepts/components/preview-features',
codeBlock: false,
},
{
text: 'Prisma Language Tools',
url: 'concepts/components/prisma-language-tools',
codeBlock: false,
},
],
},
{
Expand Down
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)
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)
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 ? -->
Copy link
Contributor Author

@Druue Druue Dec 14, 2022

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?


- [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 -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.


</TopBlock>

## Formatting

## Linting

## Tooltips

## Go to Definition

## Document symbols
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? -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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? -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Loading