zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
47.86k stars 2.8k forks source link

Built-in Prettier cannot read overrides config #12049

Open rendaoer opened 4 months ago

rendaoer commented 4 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

.prettierrc:

{
  "overrides": [
      {
        "files": ["*.html"],
        "options": {
          "parser": "jinja-template"
        }
      }
    ],
  "plugins": ["prettier-plugin-jinja-template", "prettier-plugin-tailwindcss"]
}

This configuration can be used in vs code, but it does not take effect in zed. I tried to find the place in the code where the configuration file is parsed, but unfortunately I couldn't find it.

Environment

Zed: v0.135.2 (Zed) OS: macOS 14.4.1 Memory: 8 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

mrnugget commented 4 months ago

I'm 99% sure that this is fixed on main after @SomeoneToIgnore's https://github.com/zed-industries/zed/commit/cb430fc3e40aaf48a56f4faf8b4353007981f7fb

joefitzgerald commented 3 months ago

I'm running Zed Preview 0.139.3 and the built-in prettier does not seem to respect the .prettierrc file in my project. I can only get prettier to work by:

  1. brew install prettier
  2. Adding this to my settings:
    "formatter": {
    "external": {
        "command": "prettier",
        "arguments": [
            "--stdin-filepath",
            "{buffer_path}"
        ]
    }
    },

I could not use npx prettier as npx could not be found (I use homebrew and nvm, and I have two copies of npx installed). I suspect the core issue is that the built-in prettier is not setting its working directory to that of the file being edited. If it were doing so, I would expect prettier to walk to the file tree up until it finds the .prettierrc, then use the configuration from that file, and be able to resolve the plugins referenced in it by looking in the node_modules directory in my project root.

.prettierrc

{
  "plugins": ["prettier-plugin-go-template", "prettier-plugin-tailwindcss"],
  "overrides": [
    {
      "files": ["*.html"],
      "options": {
        "parser": "go-template",
        "goTemplateBracketSpacing": true
      }
    }
  ]
}
mrnugget commented 3 months ago

@joefitzgerald can you reproduce this in a new project with prettier? Because on the latest preview, when using the built-in prettier, it works for me:

https://github.com/zed-industries/zed/assets/1185253/eaebbc4b-e484-49f3-8ace-1317e4d5ab7c

Is the problem that prettier doesn't work or that it doesn't pick up the plugins? Do the logs say anything?

  1. Use zed: open logs
  2. Use debug: open language server logs and open prettier in the dropdown