From e5bd9f184b75979632b07ea6a21ae5375232936d Mon Sep 17 00:00:00 2001 From: Remco Smits Date: Tue, 12 Mar 2024 11:38:30 +0100 Subject: [PATCH] Fix prettier plugins does not seem to be picked up (#9193) This fixed the issue that prettier plugins were not picked up. The old code would always send an empty array to the prettier plugin that happens inside the `prettier_server.js`. **Before** The `options.plugins` key is an empty array, which is not correct. ```log stderr: Resolved config: {"singleQuote":true,"trailingComma":"all","plugins":["prettier-plugin-organize-imports"]}, will format file '/Users/remcosmits/Documents/code/prettier-test/src/app/page.tsx' with options: {"singleQuote":true,"trailingComma":"all","plugins":[],"parser":"typescript","path":"/Users/remcosmits/Documents/code/prettier-test/src/app/page.tsx"} ``` https://github.com/zed-industries/zed/assets/62463826/52f2aad0-2f96-43a9-81ec-9d4630c495b2 **After** The `options.plugins` contains the `prettier-plugin-organize-imports` plugin as expected. ```log stderr: Resolved config: {"singleQuote":true,"trailingComma":"all","plugins":["prettier-plugin-organize-imports"]}, will format file '/Users/remcosmits/Documents/code/prettier-test/src/app/page.tsx' with options: {"singleQuote":true,"trailingComma":"all","plugins":["prettier-plugin-organize-imports"],"parser":"typescript","path":"/Users/remcosmits/Documents/code/prettier-test/src/app/page.tsx"} ``` https://github.com/zed-industries/zed/assets/62463826/9045028d-aeca-4df1-819c-01905d83216c Release Notes: - Fixed send plugins correctly to the prettier plugin ([#8841](https://github.com/zed-industries/zed/issues/8841)). --- crates/prettier/src/prettier_server.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/prettier/src/prettier_server.js b/crates/prettier/src/prettier_server.js index bf62e538dd..ebe2303777 100644 --- a/crates/prettier/src/prettier_server.js +++ b/crates/prettier/src/prettier_server.js @@ -173,12 +173,16 @@ async function handleMessage(message, prettier) { if (params.options.filepath !== undefined) { resolvedConfig = (await prettier.prettier.resolveConfig(params.options.filepath)) || {}; } + + const plugins = Array.isArray(resolvedConfig?.plugins) && resolvedConfig.plugins.length > 0 ? + resolvedConfig.plugins : + params.options.plugins; const options = { ...(params.options.prettierOptions || prettier.config), ...resolvedConfig, + plugins, parser: params.options.parser, - plugins: params.options.plugins, path: params.options.filepath, }; process.stderr.write(