Add Prettier support for Vue, Markdown and PHP (#7904)

Current prettier support w/i Zed leaves out a few languages that are
officially supported by prettier. In particular, Vue and Markdown are
supported by the core prettier project, and PHP is supported via an
official plugin. I didn't see any open issues for this, but I have been
wondering for months why `"formatter": "prettier"` wasn't working on my
PHP files. Now that Zed is open source, I was able to find out why, and
fix it. 😄

I have been using this with PHP files daily for a week+ now, and I have
also used it successfully with Vue and Markdown files, though not as
extensively. I looked around and did not see any tests for specific
prettier language integrations, but if I missed them please let me know
and I'll add some tests.

**Notes**
- I did not add support for Ruby (which has an official prettier plugin)
because it seems to require some external dependencies (notably, Rudy
and some Gems). When those are present on the system and `$PATH`,
prettier will will work just fine on Ruby files if the plugin is set up
similar to how the PHP plugin is set up (I tried it), and I can add that
in here, if desired. The PHP plugin is pure JS (as I recall) and doesn't
have this issue.
- I did *not* add support for languages that have "community" plugins,
though I do note that Zed already ships with prettier support for svelte
enabled, which – if I understand correctly – is powered by a community
plugin. If desired, I could look at adding support/configuration to
enable prettier support for things like elm, erb, glsl, bash, toml.
Bash, in particular, *I* would find useful. 😄

Release Notes:

- Added prettier support for Vue, Markdown and PHP
This commit is contained in:
claytonrcarter 2024-02-17 04:35:31 -05:00 committed by GitHub
parent 43a845cbbf
commit cd4d2f7900
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 0 deletions

View File

@ -245,6 +245,8 @@ impl Prettier {
prettier_plugin_dir.join("index.mjs"), prettier_plugin_dir.join("index.mjs"),
prettier_plugin_dir.join("index.js"), prettier_plugin_dir.join("index.js"),
prettier_plugin_dir.join("plugin.js"), prettier_plugin_dir.join("plugin.js"),
// this one is for @prettier/plugin-php
prettier_plugin_dir.join("standalone.js"),
prettier_plugin_dir, prettier_plugin_dir,
] { ] {
if possible_plugin_path.is_file() { if possible_plugin_path.is_file() {

View File

@ -11,3 +11,4 @@ brackets = [
{ start = "'", end = "'", close = false, newline = false }, { start = "'", end = "'", close = false, newline = false },
{ start = "`", end = "`", close = false, newline = false }, { start = "`", end = "`", close = false, newline = false },
] ]
prettier_parser_name = "markdown"

View File

@ -102,6 +102,10 @@ impl LspAdapter for IntelephenseLspAdapter {
fn language_ids(&self) -> HashMap<String, String> { fn language_ids(&self) -> HashMap<String, String> {
HashMap::from_iter([("PHP".into(), "php".into())]) HashMap::from_iter([("PHP".into(), "php".into())])
} }
fn prettier_plugins(&self) -> &[&'static str] {
&["@prettier/plugin-php"]
}
} }
async fn get_cached_server_binary( async fn get_cached_server_binary(

View File

@ -14,3 +14,4 @@ brackets = [
collapsed_placeholder = "/* ... */" collapsed_placeholder = "/* ... */"
word_characters = ["$"] word_characters = ["$"]
scope_opt_in_language_servers = ["tailwindcss-language-server"] scope_opt_in_language_servers = ["tailwindcss-language-server"]
prettier_parser_name = "php"

View File

@ -13,3 +13,4 @@ brackets = [
{ start = "`", end = "`", close = true, newline = false, not_in = ["string"] }, { start = "`", end = "`", close = true, newline = false, not_in = ["string"] },
] ]
word_characters = ["-"] word_characters = ["-"]
prettier_parser_name = "vue"