language-tools: Automatic alignment no longer works

Hi. I am not sure if I am doing something wrong, but since today, automatic formatting/alignment of schema.prisma file no longer works. It used to work properly before.

Noticed that there is some version upgrade. Any configuration to change from my end or is it a bug?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (13 by maintainers)

Most upvoted comments

To get this working again, I had to add the following to my settings.json:

"[prisma]": {
  "editor.defaultFormatter": "Prisma.prisma"
},

@dkozma Thanks for your solution, it got me 99% of the way there. I had to add one more setting to get mine to work:

"[prisma]": {
  "editor.defaultFormatter": "Prisma.prisma",
  "editor.formatOnSave": true
},

Is what is documented on https://marketplace.visualstudio.com/items?itemName=Prisma.prisma and https://github.com/prisma/language-tools/tree/master/packages/vscode#features not enough?

To be honest, no.

Simply saying add "editor.formatOnSave": true wasn’t clear enough for me, and I doubt it would be for a few others…

Changing it to…

"[prisma]": {
  "editor.defaultFormatter": "Prisma.prisma",
  "editor.formatOnSave": true
},

…would be a little clearer. It would help devs who aren’t too familiar with configuring settings and associating it to an extension in VS Code.

Yeah well its fixed, just need @mavilein to do the review 😛

@dkozma Thanks for your solution, it got me 99% of the way there. I had to add one more setting to get mine to work:

"[prisma]": {
  "editor.defaultFormatter": "Prisma.prisma",
  "editor.formatOnSave": true
},

Can we add this to the docs or somewhere a user can access this information prior to them digging through various comments? 😃

Can confirm that this is fixed with 0.0.31 👍

Thank you for your persistence and patience on this issue everyone.


I’ve done some debugging. It looks like there was a regression in prisma’s formatter sometime in the last 8 days.

Given the following schema:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id Int          @id
}

model Ok {
  id Int @id
}

https://github.com/prisma/prisma-engines/commit/6aa23a61c78a5418a0231347458d639aa337ec1d is able to gracefully format this to:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id Int @id
}

model Ok {
  id Int @id
}

However prisma-fmt today https://github.com/prisma/prisma-engines/commit/8814060fa684793b73d07dbfccd4b7777b3361ae yields this:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ErrorCollection { errors: [EnvironmentFunctionalEvaluationError { var_name: "DATABASE_URL", span: Span { start: 55, end: 74 } }] }', libs/datamodel/core/src/ast/reformat/mod.rs:10:19

We didn’t see this right away because our prisma-fmt happened to be downloaded at a time when this worked. As of yesterday we’ve introduced version pinning so we’ll all share the same prisma-fmt (assuming we’re on the same Prisma VSCode Extension version)

I’ve opened an issue for the backend team to fix this regression: https://github.com/prisma/prisma-engines/issues/620

I think it’s broken by env("DATABASE_URL")

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

This works:

datasource db {
  provider = "postgresql"
  url      = "anyString"
}

And yes, there was an error in dev tools in vscode.

prisma-fmt error'd during formatting. This was likely due to a syntax error. Please see linter output.

@matthewmueller

As @alexichepura mentioned, I can confirm this. After removing env(“url”) and also the new line/comment as mentioned in https://github.com/prisma/vscode/issues/62 the automatic alignment and formatting starts working properly. So, looks like a bug.

Even I got the error in devtools when I had env and new line:

Extension Host] prisma-fmt error'd during formatting. This was likely due to a syntax error. Please see linter output.

I think it’s broken by env("DATABASE_URL")

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

This works:

datasource db {
  provider = "postgresql"
  url      = "anyString"
}

And yes, there was an error in dev tools in vscode.

prisma-fmt error'd during formatting. This was likely due to a syntax error. Please see linter output.

Thanks @dkozma and @nhuesmann! I’ll close this issue. Happy to re-open if this is still an issue after adding the setting above.