From d57daad6cc59b70212f46b96bceb2a6f09422ac7 Mon Sep 17 00:00:00 2001 From: Princesseuh <3019731+Princesseuh@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:02:34 +0100 Subject: [PATCH] fix(format): Fix notification about Prettier being missing appearing on every format --- .changeset/happy-beers-tie.md | 6 ++++++ packages/language-server/src/languageServerPlugin.ts | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/happy-beers-tie.md diff --git a/.changeset/happy-beers-tie.md b/.changeset/happy-beers-tie.md new file mode 100644 index 00000000..ce39b487 --- /dev/null +++ b/.changeset/happy-beers-tie.md @@ -0,0 +1,6 @@ +--- +"@astrojs/language-server": patch +"astro-vscode": patch +--- + +Fix notification about Prettier being missing appearing on every format diff --git a/packages/language-server/src/languageServerPlugin.ts b/packages/language-server/src/languageServerPlugin.ts index 634e0b1d..7e2f728d 100644 --- a/packages/language-server/src/languageServerPlugin.ts +++ b/packages/language-server/src/languageServerPlugin.ts @@ -91,18 +91,21 @@ export function createServerOptions( function getPrettierService() { let prettier: ReturnType; let prettierPluginPath: ReturnType; + 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; }