Skip to content

Commit

Permalink
fix(format): Fix notification about Prettier being missing appearing …
Browse files Browse the repository at this point in the history
…on every format
  • Loading branch information
Princesseuh committed Mar 21, 2024
1 parent 6fd9314 commit d57daad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/happy-beers-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@astrojs/language-server": patch
"astro-vscode": patch
---

Fix notification about Prettier being missing appearing on every format
7 changes: 5 additions & 2 deletions packages/language-server/src/languageServerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,21 @@ export function createServerOptions(
function getPrettierService() {
let prettier: ReturnType<typeof importPrettier>;
let prettierPluginPath: ReturnType<typeof getPrettierPluginPath>;
let hasShownNotification = false;

return createPrettierService(
(context) => {
const workspaceUri = URI.parse(context.env.workspaceFolder);
if (workspaceUri.scheme === 'file') {
prettier = importPrettier(workspaceUri.fsPath);
prettierPluginPath = getPrettierPluginPath(workspaceUri.fsPath);
if (!prettier || !prettierPluginPath) {
if ((!prettier || !prettierPluginPath) && !hasShownNotification) {
connection.sendNotification(ShowMessageNotification.type, {
message:
"Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project.",
"Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project and restart the language server.",
type: MessageType.Warning,
});
hasShownNotification = true;
}
return prettier;
}
Expand Down

0 comments on commit d57daad

Please sign in to comment.