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

Formatting is failing for certain files after #1407 #1410

Closed
bschlenk opened this issue Nov 28, 2023 · 2 comments · Fixed by #1413
Closed

Formatting is failing for certain files after #1407 #1410

bschlenk opened this issue Nov 28, 2023 · 2 comments · Fixed by #1413

Comments

@bschlenk
Copy link

It seems like after #1407, formatting certain files in my repo isn't working. I have a monorepo and there are multiple Gemfiles in different subdirectories. I found that trying to format files in subdirectories that don't have syntax_tree listed in the Gemfile are the ones that fail. I think this makes sense because the require "bundler/setup" is resolving based on the nearest Gemfile. It'd be nice though if I could configure the directory that the plugin spawns in so I only have to install the plugin's dependencies in the top level directory.

It may also be an issue if the plugin only gets spawned once in whatever directory happens to be the first file formatted (not sure if this is the case though).

@kddnewton
Copy link
Member

Thanks @bschlenk I think that's an unintended consequence of #1407 - @hrabe could you take a look at this? We certainly shouldn't be breaking behavior in point releases, hopefully we can get this fixed without reverting.

@bschlenk
Copy link
Author

I don't know if this would work for everyone, but in my case using the directory where the prettier config file lives as the cwd of the spawned ruby process works for me, both from the cli and vscode. It looks like this:

// plugin.js
...
import { resolveConfigFile } from "prettier";
...

// in spawnServer
    
const options = { 
  env: Object.assign({}, process.env, { LANG: getLang() }),
  stdio: ["ignore", "ignore", "inherit"],
  detached: true
};

if (opts.filepath) { 
  const prettierConfig = await resolveConfigFile(opts.filepath)
  options.cwd = path.dirname(prettierConfig)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants