History

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. :smile: 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. :smile: Release Notes: - Added prettier support for Vue, Markdown and PHP

claytonrcarter committed 2 years ago

Commit cd4d2f71 parent 43a845c5 files · +9 −0Browse files

Unified · Split

5 files
  1. crates/prettier/src/prettier.rs +2 −0
  2. crates/zed/src/languages/markdown/config.toml +1 −0
  3. crates/zed/src/languages/php.rs +4 −0
  4. crates/zed/src/languages/php/config.toml +1 −0
  5. crates/zed/src/languages/vue/config.toml +1 −0
crates/prettier/src/prettier.rs+2−0
@@ -245,6 +245,8 @@ impl Prettier { · 244 unmodified lines
245245 prettier_plugin_dir.join("index.mjs"),
246246 prettier_plugin_dir.join("index.js"),
247247 prettier_plugin_dir.join("plugin.js"),
248+ // this one is for @prettier/plugin-php
249+ prettier_plugin_dir.join("standalone.js"),
248250 prettier_plugin_dir,
249251 ] {
250252 if possible_plugin_path.is_file() {
crates/zed/src/languages/markdown/config.toml+1−0
@@ -11,3 +11,4 @@ brackets = [ · 10 unmodified lines
1111 { start = "'", end = "'", close = false, newline = false },
1212 { start = "`", end = "`", close = false, newline = false },
1313 ]
14+prettier_parser_name = "markdown"
crates/zed/src/languages/php.rs+4−0
@@ -102,6 +102,10 @@ impl LspAdapter for IntelephenseLspAdapter { · 101 unmodified lines
102102 fn language_ids(&self) -> HashMap<String, String> {
103103 HashMap::from_iter([("PHP".into(), "php".into())])
104104 }
105+
106+ fn prettier_plugins(&self) -> &[&'static str] {
107+ &["@prettier/plugin-php"]
108+ }
105109 }
106110
107111 async fn get_cached_server_binary(
crates/zed/src/languages/php/config.toml+1−0
@@ -14,3 +14,4 @@ brackets = [ · 13 unmodified lines
1414 collapsed_placeholder = "/* ... */"
1515 word_characters = ["$"]
1616 scope_opt_in_language_servers = ["tailwindcss-language-server"]
17+prettier_parser_name = "php"
crates/zed/src/languages/vue/config.toml+1−0
@@ -13,3 +13,4 @@ brackets = [ · 12 unmodified lines
1313 { start = "`", end = "`", close = true, newline = false, not_in = ["string"] },
1414 ]
1515 word_characters = ["-"]
16+prettier_parser_name = "vue"