Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntelliJ IDEA (1.16) - Parsing error at import time #911

Open
Djaytan opened this issue Mar 6, 2023 · 18 comments
Open

IntelliJ IDEA (1.16) - Parsing error at import time #911

Djaytan opened this issue Mar 6, 2023 · 18 comments
Labels

Comments

@Djaytan
Copy link

Djaytan commented Mar 6, 2023

Hello 👋

How to reproduce:

  1. In a Java file, simply start writing a class name which require an import and is not imported yet (e.g. List)
  2. Use the IntelliJ IDEA auto-import feature
    => google-java-format will send immediately after a parsing error message + will not format properly import:

Example:

import java.util.List;import javax.inject.Singleton;

This issue is not present with the previous version of the plugin (1.15)

Environment details

IntelliJ IDEA 2022.3.2 (Ultimate Edition)
Build #IU-223.8617.56, built on January 26, 2023
Runtime version: 17.0.5+1-b653.25 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 20
Registry:
debugger.new.tool.window.layout=true
ide.experimental.ui=true

Non-Bundled Plugins:
com.wakatime.intellij.plugin (14.1.4)
google-java-format (1.16.0.0)
org.jetbrains.plugins.hocon (2022.1.0)
MavenRunHelper (4.23.222.2964.0)
org.sonarlint.idea (8.0.0.63273)
zielu.gittoolbox (500.0.4+213)
mobi.hsz.idea.gitignore (4.4.4)

Kotlin: 223-1.8.0-release-345-IJ8617.56

@Djaytan
Copy link
Author

Djaytan commented Mar 6, 2023

I downgraded to version 1.15 and I confirm that the issue isn't present

@plumpy
Copy link
Collaborator

plumpy commented Mar 6, 2023

The old version did not optimize your imports. Would you like an option to disable optimizing imports?

There's really no other way around this.

@plumpy plumpy added the IntelliJ label Mar 6, 2023
@plumpy
Copy link
Collaborator

plumpy commented Mar 6, 2023

Some additional clarification here:

Since the old plugin didn't optimize imports, the built-in IDE import optimizer handled that. If you had taken the time to configure your IDE to sort imports the same way that google-java-format does, then everything would work okay (and the IDE's import optimizer doesn't require a syntactically correct file to work). But it did require you to take that extra step.

The new plugin handles import ordering for you, so it'll work out of the box, no additional configuration needed...but with this one additional caveat that it only works on files without syntax errors.

@Djaytan
Copy link
Author

Djaytan commented Mar 6, 2023

@plumpy Thanks for your answer

I already have manually configured the import ordering as described in the README, so if I should choice between both versions, it seems better for me to stay with version 1.15 since in-fine the UX is better

So, if the issue can be solved by having an option to disable optimizing imports from plugin to rely on the configured one it would perfectly feet my needs as well for those who would be motivated to follow few additional steps to have a clean UX

@jbduncan
Copy link
Contributor

jbduncan commented Mar 6, 2023

I already have manually configured the import ordering as described in the README...

@Djaytan Which part of the README are you referring to? I can't seem to find anything on imports. 🤔

@plumpy
Copy link
Collaborator

plumpy commented Mar 6, 2023

@jbduncan I removed it from the README since it's not necessary anymore. But you can see the old version here:
https://github.com/google/google-java-format/blob/v1.15.0/README.md#intellij-android-studio-and-other-jetbrains-ides

@ahaczewski
Copy link

ahaczewski commented Mar 13, 2023

The old version did not optimize your imports. Would you like an option to disable optimizing imports?

There's really no other way around this.

Hi @plumpy,

We do relied on the previous IntelliJ plugin not optimizing imports. We also set --skip-sorting-imports for our automated formatting in CI. Is it possible to have a switch in IntelliJ that does what the --skip-sorting-imports does for the command line?

@tgeng
Copy link

tgeng commented Mar 19, 2023

This upgrade basically makes the plugin unusable: if any IDE action needs to touch the import yet the generated/completed code is not syntactically correct yet (since code is not completed yet), google-java-format would simply fail to format the file and report error. I am not sure if there is a way to differentiate reformat request from an IDE action generating new code from reformat request from user hitting reformat command or trigger reformat on save.

@SenreySong
Copy link

When using a new version of a plugin, it can break IntelliJ IDEA's auto import functionality, which can disrupt code completion and cause the related code generation features, such as generating constructors, to stop working.

@smarthkatyal
Copy link

I think when there are syntax errors, it should let the IDE handle things as they were being done before this change. Now, when there are syntax errors, the problem is getting a bit compounded because i see an error in the IJ notification pane about the plugin failing to format and also the imports are just dumped into one long line requiring "manual" fix by putting the imports on the new line. Sometimes syntax errors can take a big changeset to be fixed completely and not being able to format till then is not ideal.

@guillaume-alvarez
Copy link

I have the same issue: when generating code it is not automatically free of syntax errors and thus is badly formatted to the point of being unreadable.... and it generates lots of warning popups for something that should only be a transient state.

Is it possible to revert to the previous plugin version?

@stefanscheidt
Copy link

@guillaume-alvarez Yes, you can download the version you want (probably 1.15.0.0 - works fine for me) here and then install it from disk.

Please note that with version 1.15.0.0 and before you also need to use this code style thingy to get proper import organization.

@jzanon
Copy link

jzanon commented Mar 23, 2023

Same problem here than @guillaume-alvarez . I use using IntelliJ IDEA 2022.3.3. + plugin google-java-format (1.16.0.1)
I had to downgrade plugin google-java-format to 1.15.0.0.

@aaime
Copy link

aaime commented Mar 24, 2023

Same here.. the latest version is not usable, takes a lot of time for format the files, plays pretty poorly with IntelliJ code generation (e.g., creating getters/setters, constructors and the like). Reverting to 1.15.0.0 fixes the problem.

@dangolbeeker
Copy link

Same issue

@binhnv
Copy link

binhnv commented Mar 28, 2023

Have the same issue and it makes this plugin unusable

@mattnworb
Copy link

I think the problem is broader than when a missing import causes syntax/compiler errors - I get the same sort of behavior ("
google-java-format failed. Does Foobar.java have syntax errors?", IntelliJ-generated code appearing on the same line as other existing code without newlines being inserted) any time the file is incomplete and the formatter is running. It seems like the new formatter interferes with general code generation abilities of IntelliJ

@raphaelNguyen
Copy link

Same issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests