bazelbuild / intellij

IntelliJ plugin for Bazel projects
https://ij.bazel.build/
Apache License 2.0
753 stars 297 forks source link

BUILD file contents deleted when automatically formatted on save #6471

Open chance-mongo opened 1 month ago

chance-mongo commented 1 month ago

Description of the bug:

Whenever I make a change to a BUILD file and then save, the file's contents are all deleted (see attached video). Confirmed that this stops happening when the Bazel plugin's Automatically format BUILD files on save is turned off.

My best guess is that this is just some incompatibility between IDE version, plugin version, and bazel version? Maybe it's an interaction between the Bazel plugin's save action and IntelliJ's built in save action formatting?

https://github.com/bazelbuild/intellij/assets/154269108/f63912cb-4aac-4680-ad99-40b7673df886

Which category does this issue belong to?

Intellij

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  1. Ensure Automatically format BUILD files on save is turned on
  2. Make a change to a BUILD file
  3. Save (cmd-s)
  4. The BUILD file contents are deleted

Which Intellij IDE are you using? Please provide the specific version.

2024.1.2

What programming languages and tools are you using? Please provide specific versions.

Java

What Bazel plugin version are you using?

2024.05.21.0.1-api-version-241

Have you found anything relevant by searching the web?

No, but this issue is kind of hard to google so possible there's something out there?

Any other information, logs, or outputs that you want to share?

No response

mai93 commented 3 weeks ago

I was not able to reproduce this with the plugin/IDE versions you mentioned, what os are you using the plugin on?

chance-mongo commented 3 weeks ago

I'm on 14.5 (23F79) Also, not sure if the plugin uses the buildifier.json file behind the scenes, but ours is:

{
  "type": "auto",
  "mode": "check",
  "lint": "warn",
  "warningsList": ["-positional-args"]
}

And here's my bazel version as well:

Bazelisk version: v1.18.0
Build label: 6.5.0
Build target: bazel-out/darwin_arm64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Jan 23 16:45:22 2024 (1706028322)
Build timestamp: 1706028322
Build timestamp as int: 1706028322
mai93 commented 3 weeks ago

I think we do use the buildifier.json, https://github.com/bazelbuild/intellij/pull/6158/files.

Thanks for providing the extra details, I am still not able to reproduce it, when you run buildifier from command line does it result in the same issue? Also are you able to reproduce it with a simple project like the ones under https://github.com/bazelbuild/intellij/tree/master/examples