palantir / palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Apache License 2.0
403 stars 43 forks source link

Formatting shortcut not intercepted in IntelliJ 2024.1 #1068

Closed dedrone-fb closed 2 months ago

dedrone-fb commented 3 months ago

What happened?

Using 2.40.0 of the IntelliJ plugin on recently released 2024.1, the format shortcut does not seem to be intercepted anymore and the default IntelliJ formatter is run instead of palantir.

What did you want to happen?

The format shortcut should be intercepted on IntelliJ 2024.1

rkraneis commented 3 months ago

Same issue here. I also tried disabling and re-enabling the plugin (on the project as well as globally). Re-installation didn't fix the issue, either. No exceptions are reported by IntelliJ.

rkraneis commented 3 months ago

~A workaround seems to be to not set the Code Style to “Project”, but to “Default IDE”. This is suboptimal, as enabling Palantir already is a project option, and we still want to use per-project options to configure formatting of non-Java files.~

“Default IDE” was just close enough on the file in question, that I only spotted the difference when reformatting twice in a row, removing custom line breaks.

Xigua7i commented 3 months ago

I'm running into this issue as well.

marquiswang commented 3 months ago

I experienced this on the EAP, but it appears to be working fine for me on 2024.1. I haven't investigated at all, just wanted to provide a counterpoint. I wonder if it depends on what other plugins you have enabled?

mszalbach commented 3 months ago

I have the same problem with 2024.1. I disabled all third party dependencies and it does not change anyhting. However I never testet it before 2024.1 with the same project.

Xigua7i commented 3 months ago

I'm running into this issue as well.

`java.lang.RuntimeException: Error running formatter command at com.palantir.javaformat.bootstrap.BootstrappingFormatterService.getFormatReplacements(BootstrappingFormatterService.java:58) at com.palantir.javaformat.intellij.PalantirCodeStyleManager.getReplacements(PalantirCodeStyleManager.java:87) at com.palantir.javaformat.intellij.PalantirCodeStyleManager.format(PalantirCodeStyleManager.java:204) at com.palantir.javaformat.intellij.PalantirCodeStyleManager.formatInternal(PalantirCodeStyleManager.java:187) at com.palantir.javaformat.intellij.PalantirCodeStyleManager.reformatText(PalantirCodeStyleManager.java:112) at com.intellij.codeInsight.completion.JavaChainLookupElement.handleInsert(JavaChainLookupElement.java:124) at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$insertItem$15(CodeCompletionHandlerBase.java:713) at com.intellij.util.indexing.FileBasedIndex.lambda$ignoreDumbMode$0(FileBasedIndex.java:219) at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:111) at com.intellij.util.indexing.FileBasedIndexEx.ignoreDumbMode(FileBasedIndexEx.java:637) at com.intellij.util.indexing.FileBasedIndex.ignoreDumbMode(FileBasedIndex.java:218) at com.intellij.util.indexing.DumbModeAccessType.ignoreDumbMode(DumbModeAccessType.java:43) at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$insertItem$16(CodeCompletionHandlerBase.java:712) at com.intellij.openapi.application.impl.RwLockHolder.runWriteAction(RwLockHolder.kt:344) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:883) at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.insertItem(CodeCompletionHandlerBase.java:696) at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.doInsertItemForSingleCaret(CodeCompletionHandlerBase.java:640) at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$doInsertItem$13(CodeCompletionHandlerBase.java:612) at com.intellij.openapi.editor.impl.CaretModelImpl.lambda$runForEachCaret$3(CaretModelImpl.java:303) at com.intellij.openapi.editor.impl.CaretModelImpl.doWithCaretMerging(CaretModelImpl.java:412) at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:312) at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:289) at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.doInsertItem(CodeCompletionHandlerBase.java:604) at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.insertItemHonorBlockSelection(CodeCompletionHandlerBase.java:563) at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lookupItemSelected(CodeCompletionHandlerBase.java:509) at com.intellij.codeInsight.completion.CompletionProgressIndicator.itemSelected(CompletionProgressIndicator.java:211) at com.intellij.codeInsight.completion.BaseCompletionLookupArranger.itemSelected(BaseCompletionLookupArranger.java:227) at com.intellij.codeInsight.lookup.impl.LookupImpl.fireItemSelected(LookupImpl.java:996) at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookupInWritableFile(LookupImpl.java:613) at com.intellij.codeInsight.lookup.impl.LookupImpl.lambda$finishLookup$8(LookupImpl.java:569) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:216) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:177) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:167) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:153) at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookup(LookupImpl.java:567) at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookup(LookupImpl.java:552) at com.intellij.codeInsight.lookup.impl.actions.ChooseItemAction$Handler.doExecute(ChooseItemAction.java:57) at com.intellij.openapi.editor.actionSystem.DynamicEditorActionHandler.doExecute(DynamicEditorActionHandler.java:63) at com.intellij.openapi.editor.actionSystem.EditorActionHandler.lambda$execute$4(EditorActionHandler.java:199) at com.intellij.openapi.editor.actionSystem.EditorActionHandler.doIfEnabled(EditorActionHandler.java:89) at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:198) at com.intellij.openapi.editor.actionSystem.EditorAction.lambda$actionPerformed$0(EditorAction.java:92) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:225) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:177) at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:101) at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:77) at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.kt:305) at com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:32) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$actionProcessor$1.performAction(IdeKeyEventDispatcher.kt:495) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner$lambda$4$lambda$3(IdeKeyEventDispatcher.kt:844) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106) at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:95) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner$lambda$4(IdeKeyEventDispatcher.kt:844) at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.performWithActionCallbacks(ActionManagerImpl.kt:1161) at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.kt:322) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner(IdeKeyEventDispatcher.kt:842) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.access$doPerformActionInner(IdeKeyEventDispatcher.kt:1) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction$intellij_platform_ide_impl(IdeKeyEventDispatcher.kt:571) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.kt:508) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.kt:447) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.kt:440) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.kt:302) at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.kt:622) at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$11(IdeEventQueue.kt:585) at com.intellij.openapi.application.impl.RwLockHolder.runWithEnabledImplicitRead(RwLockHolder.kt:138) at com.intellij.openapi.application.impl.RwLockHolder.runWithImplicitRead(RwLockHolder.kt:129) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:585) at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:77) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:362) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:361) at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:843) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:361) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:356) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1021) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:114) at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1021) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$7(IdeEventQueue.kt:356) at com.intellij.openapi.application.impl.RwLockHolder.runIntendedWriteActionOnCurrentThread(RwLockHolder.kt:209) at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:830) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:398) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92) Caused by: java.io.IOException: Command terminated with exit value 1 Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/bin/java -cp /Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/palantir-java-format-spi-2.40.0.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/guava-33.0.0-jre.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/j2objc-annotations-2.8.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/jackson-datatype-guava-2.15.3.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/jackson-core-2.15.3.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/palantir-java-format-2.40.0.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/failureaccess-1.0.2.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/jackson-annotations-2.15.3.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/jackson-databind-2.15.3.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/functionaljava-4.8.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/jackson-datatype-jdk8-2.15.3.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/checker-qual-3.42.0.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/jsr305-3.0.2.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/jackson-module-parameter-names-2.15.3.jar:/Users/happycode/Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/palantir-java-format/impl/error_prone_annotations-2.24.1.jar com.palantir.javaformat.java.Main --character-ranges 4358:4375 --output-replacements --palantir - Stdout:

Stderr: Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: com/palantir/javaformat/java/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) at java.net.URLClassLoader.access$100(URLClassLoader.java:74) at java.net.URLClassLoader$1.run(URLClassLoader.java:369) at java.net.URLClassLoader$1.run(URLClassLoader.java:363) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:362) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

at com.palantir.javaformat.bootstrap.FormatterCommandRunner.runWithStdin(FormatterCommandRunner.java:53)
at com.palantir.javaformat.bootstrap.BootstrappingFormatterService.getFormatReplacementsInternal(BootstrappingFormatterService.java:83)
at com.palantir.javaformat.bootstrap.BootstrappingFormatterService.getFormatReplacements(BootstrappingFormatterService.java:56)
... 85 more

`

rkraneis commented 3 months ago

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: com/palantir/javaformat/java/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

This is quite likely caused by using Java 8. Try running IntelliJ with at least Java 11.

lefti696 commented 2 months ago

same here - formatting does not work in 2024.1 :disappointed: image

CRogers commented 2 months ago

google-java-format (which this is forked off) made this change to use <formatterService> about a year ago. I suspect this project also needs to make that change and implement the different API, although it could conceivably be something else.

As to when this can be fixed; I have a little time today I can spend on this, but it's looking likely the week of 22nd April at the earliest (as we cannot work on this next week). Until then, I would recommend downgrading IntelliJ (easy if you use Jetbrains Toolbox):

Screenshot 2024-04-12 at 13 14 46

or manually running ./gradlew format before committing if you really can't do that.

walles commented 2 months ago

I'm hoping / wondering if implementing that new API might also solve #808 and #992.

serpro69 commented 2 months ago

Oh, I was wracking my brain why intellij formatting is suddenly broken and the plugin doesn't seem to do anything in intellij anymore. Hopefully this can be fixed soon.

mrksph commented 2 months ago

Facing this issue as well in 2024.1 even with the formatted enabled

CRogers commented 2 months ago

Fix happening at https://github.com/palantir/palantir-java-format/pull/1078

Xigua7i commented 2 months ago

Fix happening at #1078

Thanks

CRogers commented 2 months ago

This got fixed in 2.44.0 - however it's stuck in the plugin portal awaiting moderation by jetbrains:

Screenshot 2024-04-26 at 17 19 22
ash211 commented 2 months ago

@CRogers It looks like the latest version on the JetBrains marketplace is 2.40.0

Screenshot 2024-04-26 at 10 06 47 AM

Do you know what happened to 41, 42, and 43? The release flow into Marketplace seems to have gotten stuck.

CRogers commented 2 months ago

@ash211 Please read my previous comment.

The previous versions that failed to publish were due to not checking a box in the Jetbrains Plugins UI for some EU regulation (which we have done a couple of weeks ago). Those versions did not contain IntelliJ plugin changes.

CRogers commented 2 months ago

It's now been approved

mrksph commented 1 month ago

Hi am I the only one getting an exception when trying to install/update plugins? Intellij 2024.1

image

mrksph commented 1 month ago

@CRogers

I'm having issues installing any version higher than 2.40.0 it almost always fails after downloading the first 3 Mbs of the plugin.

I've also tried to download the plugin manually from the Intellij Web Marketplace but fails with the same reason

I'm behind my company VPN and tried my home WiFi and my mobile network.

I've talked with IntelliJ people they tried to upload the plugin to their own file sharing service and still couldn't donwload it.

Could you check it please?