zed/crates
Remco Smits 65152baa3f
Fix prettier-plugin-organize-imports plugin removes used imports (#9598)
### Issue
So this pull request fixes an issue that was driven me crazy. The issue
was that when you use the `prettier-plugin-organize-imports` It would
remove some imports that should not be removed before they were used
inside the module itself.

You can reproduce it with the following `prettierrc.json` config and
source code. When you **save** the file, it would remove the `import
clsx from "clsx";` import from the file.

**Prettier config**
```json
{
  "semi": true,
  "tabWidth": 4,
  "trailingComma": "es5",
  "useTabs": true,
  "plugins": [
    "prettier-plugin-tailwindcss",
    "prettier-plugin-organize-imports"
  ]
}
```

**Source code**
```typescript
import clsx from "clsx";

export default function Home() {
  return (
      <main>
	      {clsx("asdjklasdjlkasd", "asdjlkasjdjlk")}
      </main>
  );
}
``` 

### Findings
After a deep dive with @mrnugget, I was debugging deep down the prettier
plugin system and found the issue that was causing this issue. When I
was looking inside the
`node_modules/prettier-plugin-organize-imports/lib/organize.js`. I saw
the following code that looked strange to me because it falls back to
`file.ts` if `filepath` is not passed through inside the prettier config
options.

<img width="860" alt="Screenshot 2024-03-20 at 21 31 46"
src="https://github.com/zed-industries/zed/assets/62463826/47177fe5-e5a9-41d8-9f2f-0304b2c2159f">

So the issue was small, if you look at the following code, the `path`
key should be `filepath` inside the
`crates/prettier/src/prettier_server.js:205`
![Screenshot 2024-03-20 at 21 35
25](https://github.com/zed-industries/zed/assets/62463826/1eea0a88-c886-4632-9c69-9f3095126971)

Release Notes:

- Fixed prettier integration not using the correct filepath when
invoking prettier, which could lead to some prettier plugins failing to
format correctly.
([#9496](https://github.com/zed-industries/zed/issues/9496)).
2024-03-21 08:23:15 +01:00
..
activity_indicator Show formatting failure (#9229) 2024-03-12 16:30:08 +01:00
assets Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
assistant Allow AI interactions to be proxied through Zed's server so you don't need an API key (#7367) 2024-03-19 19:22:26 +01:00
audio Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
auto_update markdown preview: highlight code blocks (#9087) 2024-03-12 12:54:12 +02:00
breadcrumbs Encode rem values derived from pixels using rems_from_px (#9367) 2024-03-14 16:39:55 -04:00
call Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
channel Channel chat: Add edit message (#9035) 2024-03-19 19:49:04 -06:00
cli Make the cli crate depend on workspace clap (#9507) 2024-03-18 20:00:37 +01:00
client Add a schema to extensions, to prevent installing extensions on too old of a Zed version (#9599) 2024-03-20 17:33:26 -04:00
clock Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
collab Make it (a tiny bit) easier to run your own collab (#9557) 2024-03-20 21:00:02 -06:00
collab_ui Add support for applying theme after extension is installed (#9529) 2024-03-20 11:13:58 -04:00
collections Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
color Fix hex_to_hsla inside the color crate (#9412) 2024-03-15 16:58:46 -04:00
command_palette Encapsulate CommandPaletteFilter and CommandPaletteInterceptor (#9402) 2024-03-15 12:37:25 -04:00
command_palette_hooks Encapsulate CommandPaletteFilter and CommandPaletteInterceptor (#9402) 2024-03-15 12:37:25 -04:00
copilot Encapsulate CommandPaletteFilter and CommandPaletteInterceptor (#9402) 2024-03-15 12:37:25 -04:00
copilot_ui Fix copilot modal (#9613) 2024-03-20 20:37:40 -06:00
db Always remember the last window size and position (#9416) 2024-03-15 14:24:44 -07:00
diagnostics Add an animation to the LSP checking indicator (#9463) 2024-03-19 10:16:18 -07:00
editor Allow to handle autoclosed characters differently (#8666) 2024-03-20 09:35:42 +01:00
extension Add a schema to extensions, to prevent installing extensions on too old of a Zed version (#9599) 2024-03-20 17:33:26 -04:00
extension_api Add a schema to extensions, to prevent installing extensions on too old of a Zed version (#9599) 2024-03-20 17:33:26 -04:00
extension_cli Add a schema to extensions, to prevent installing extensions on too old of a Zed version (#9599) 2024-03-20 17:33:26 -04:00
extensions_ui Only allow opening one Extensions view (#9569) 2024-03-20 14:49:36 -04:00
feature_flags Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
feedback Remove wezterm fork from dependencie (#8998) 2024-03-12 21:27:40 +02:00
file_finder Action release handlers (#8782) 2024-03-20 18:43:31 -06:00
fs Windows: implement symlink (#9508) 2024-03-18 14:27:39 -07:00
fsevent Add rs-notify implementation of fs::watch (#9040) 2024-03-08 22:18:44 -08:00
fuzzy Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
git Properly display deleted diff hunks (#9182) 2024-03-11 17:53:45 +02:00
go_to_line Restore --all-targets for clippy (#9346) 2024-03-14 12:39:45 -04:00
google_ai Fix licensing errors 2024-03-20 15:52:02 +01:00
gpui Wayland: double click (#9608) 2024-03-20 19:22:47 -07:00
gpui_macros Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
image_viewer Image viewer (#9425) 2024-03-19 10:13:10 -07:00
install_cli Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
journal Add --add/--new to control CLI behaviour (#9202) 2024-03-12 14:27:58 -06:00
language Allow extensions to define more of the methods in the LspAdapter trait (#9554) 2024-03-20 12:47:04 -07:00
language_selector Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
language_tools Enable clippy::eq_op (#9369) 2024-03-14 17:05:07 -04:00
languages Allow extensions to define more of the methods in the LspAdapter trait (#9554) 2024-03-20 12:47:04 -07:00
live_kit_client Add a schema to extensions, to prevent installing extensions on too old of a Zed version (#9599) 2024-03-20 17:33:26 -04:00
live_kit_server Merge prost dependecies (#9522) 2024-03-18 20:33:20 -06:00
lsp Always resolve code action if needed (#8904) 2024-03-05 23:42:12 +02:00
markdown_preview Add a setting for custom associations between languages and files (#9290) 2024-03-13 10:23:30 -07:00
media Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
menu Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
multi_buffer Enable clippy::never_loop (#9006) 2024-03-14 14:07:50 -04:00
node_runtime Allow extensions to define more of the methods in the LspAdapter trait (#9554) 2024-03-20 12:47:04 -07:00
notifications Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
open_ai Fix licensing errors 2024-03-20 15:52:02 +01:00
outline Restore --all-targets for clippy (#9346) 2024-03-14 12:39:45 -04:00
picker Clean up Picker constructor signature (#9500) 2024-03-18 12:27:51 -04:00
prettier Fix prettier-plugin-organize-imports plugin removes used imports (#9598) 2024-03-21 08:23:15 +01:00
project Allow extensions to define more of the methods in the LspAdapter trait (#9554) 2024-03-20 12:47:04 -07:00
project_panel Fix skip prompt warning (#9590) 2024-03-20 13:35:29 -07:00
project_symbols Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
quick_action_bar Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
recent_projects chore: Wrap WorkspaceId in newtype (#9492) 2024-03-18 12:39:03 +01:00
refineable Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
release_channel Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
rich_text Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
rope rope: Preallocate chunks buffer 2024-03-11 13:28:10 +01:00
rpc Add a schema to extensions, to prevent installing extensions on too old of a Zed version (#9599) 2024-03-20 17:33:26 -04:00
search Allow AI interactions to be proxied through Zed's server so you don't need an API key (#7367) 2024-03-19 19:22:26 +01:00
settings Allow AI interactions to be proxied through Zed's server so you don't need an API key (#7367) 2024-03-19 19:22:26 +01:00
snippet Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
sqlez Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
sqlez_macros Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
story Enable clippy::eq_op (#9369) 2024-03-14 17:05:07 -04:00
storybook windows: Add manifest for storybook (#9453) 2024-03-18 10:14:01 -04:00
sum_tree Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
task VS Code -> Zed tasks converter (#9538) 2024-03-20 16:37:26 +01:00
tasks_ui task: Add ZED_PACKAGE task variable in Rust files. (#9491) 2024-03-18 12:18:42 +01:00
telemetry_events Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
terminal linux: scrolling improvements (#9103) 2024-03-18 14:50:29 -07:00
terminal_view Small improvements of the task terminal spawn behavior (#9399) 2024-03-15 18:32:59 +02:00
text Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
theme Allow overriding font style and weight via experimental.theme_overrides in settings (#9122) 2024-03-11 12:21:37 -04:00
theme_importer Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
theme_selector Add support for applying theme after extension is installed (#9529) 2024-03-20 11:13:58 -04:00
time_format notification panel: rework time formatting (#8997) 2024-03-12 21:02:04 -06:00
ui ui: Make top_padding an associated function on the TitleBar (#9577) 2024-03-20 10:55:09 -04:00
util Add a schema to extensions, to prevent installing extensions on too old of a Zed version (#9599) 2024-03-20 17:33:26 -04:00
vcs_menu Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
vim Encapsulate CommandPaletteFilter and CommandPaletteInterceptor (#9402) 2024-03-15 12:37:25 -04:00
welcome Allow specifying no base keymap (#9471) 2024-03-20 18:52:17 -06:00
workspace Image viewer (#9425) 2024-03-19 10:13:10 -07:00
worktree Fix file git status refresh on .gitignore update (#9466) 2024-03-18 20:35:38 -06:00
zed Allow specifying no base keymap (#9471) 2024-03-20 18:52:17 -06:00
zed_actions Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00