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

Stop adding code in format/lint, use code actions instead #980

Open
pimeys opened this issue Dec 1, 2021 · 5 comments
Open

Stop adding code in format/lint, use code actions instead #980

pimeys opened this issue Dec 1, 2021 · 5 comments
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. kind/improvement An improvement to existing feature and code. tech/engines/formatter engine Issue in the Formatter Engine topic: code action LSP code actions topic: formatting

Comments

@pimeys
Copy link
Contributor

pimeys commented Dec 1, 2021

In this video I demonstrate how our formatter acts differently compared what formatting typically does:

recording.mp4

The user does manual work, removes the front sides of all relations. The user has set the formatter to be run on save. When we run it, we do a thing that a formatter should not do: we add the relations back because we forgot to remove the back-relations before saving/formatting.

What a formatter typically should do:

  • Align code
  • Ordering
  • Spacing

Whatever we want to do additionally, like missing relation fields, should be happen through a code action. This would then require the user to go on top of a relation field, and if we notice it doesn't have the other side available, we'd be showing a light bulb in the editor through the language server protocol, and offering code actions for the user.

Example:

The user has only defined one forward relation field, and presses the code action quick key on top of the relation attribute, listing available code actions:

  • first being add a back-relation 1:n, so the back-relation is an array.
  • second is adding a back-relation 1:1

We can also do this from the other side, with different options:

  • Add an array back-relation to the other side, make a m:n relation
  • Add a singular forward field
@pimeys pimeys added kind/feature A request for a new feature. kind/improvement An improvement to existing feature and code. topic: autocompletion LSP text document completion labels Dec 1, 2021
@Jolg42 Jolg42 added the domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. label Dec 1, 2021
@Jolg42
Copy link
Contributor

Jolg42 commented Dec 1, 2021

If we remove the "fix" part from "format" and only add it to the language-server then users won't be able to use it like they did with npx prisma format like we sometimes recommend to do.

We would probably need a "fix" CLI command?

@pimeys
Copy link
Contributor Author

pimeys commented Dec 1, 2021

Yep. Formatting is not supposed to be adding code, just formatting it.

@pimeys
Copy link
Contributor Author

pimeys commented Dec 1, 2021

And instead of fixing, we should guide our users to utilize their editors instead of magic commands. And provide them the best tools to autofill missing things in the schema.

@janpio
Copy link
Contributor

janpio commented Dec 1, 2021

We can also treat the format in the extension separate from the existing behavior that prisma format in the CLI has.

@tomhoule
Copy link
Contributor

tomhoule commented Jan 7, 2022

I'd be in favor of splitting the current thing into a format command and a fix command. In the editor, the fix part can be code actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. kind/improvement An improvement to existing feature and code. tech/engines/formatter engine Issue in the Formatter Engine topic: code action LSP code actions topic: formatting
Projects
None yet
Development

No branches or pull requests

5 participants