krasa / EclipseCodeFormatter

IntelliJ plugin - use Eclipse's code formatter directly from IntelliJ. https://plugins.jetbrains.com/plugin/6546
Apache License 2.0
487 stars 117 forks source link

Failed to format with Adapter for Eclipse Code Formatter. Formatter config file not resolved. #256

Closed korner11 closed 1 year ago

korner11 commented 1 year ago

After update of IDEA from v2022.3 to 2023.1 plugin stared to throw this error. notifi

I am running IDEA community in WSL2 (Ubuntu 20.04) via Xserver with fallowing settings: AECF_settings

What scenarios do I tried to fix this error? Reinstalling plugin. Erase IDEA cache. Reverting the update of IDEA back to 2022.3 (Now it happens also on the older version) Installing other version of IDEA (2022.3.3) Installing trial ultimate version of IDEA (2023.1). Checkout new copy of repository. Open project located in WSL hard-drive via Windows installation of IDEA (still not working).

These are the log files from IDEA: IntelliJ IDEA 2023.1 (Community Edition) Build #IC-231.8109.175, built on March 28, 2023 WSL2 - Ubuntu 20.04

2023-04-11 08:53:49,092 [ 199773]   FINE - krasa.formatter.plugin.ProxyCodeStyleManagerDelegator - invoking overriding {}({})reformatText[PsiJavaFile:SimpleAopCommentsComponent.java, [(0,9450)]]
2023-04-11 08:53:49,092 [ 199773]   FINE - krasa.formatter.plugin.EclipseCodeStyleManager_IJ_2016_3plus - format SimpleAopCommentsComponent.java 0 9450
2023-04-11 08:53:49,092 [ 199773]   FINE - krasa.formatter.plugin.EclipseCodeFormatter - #format 0-9450
2023-04-11 08:53:49,092 [ 199773]   FINE - krasa.formatter.plugin.EclipseCodeFormatter - #formatWhenEditorIsOpen SimpleAopCommentsComponent.java
2023-04-11 08:53:49,094 [ 199775]   FINE - krasa.formatter.eclipse.JavaCodeFormatterFacade - config located in 0ms (null)
2023-04-11 08:53:49,094 [ 199775]   FINE - krasa.formatter.plugin.EclipseCodeStyleManager_IJ_2016_3plus - startOffset0, endOffset:9450, length of file 9450
krasa.formatter.exception.FormattingFailedException: Formatter config file not resolved.
    at krasa.formatter.eclipse.JavaCodeFormatterFacade.getCodeFormatter(JavaCodeFormatterFacade.java:68)
    at krasa.formatter.eclipse.JavaCodeFormatterFacade.format(JavaCodeFormatterFacade.java:56)
    at krasa.formatter.plugin.EclipseCodeFormatter.reformat(EclipseCodeFormatter.java:111)
    at krasa.formatter.plugin.EclipseCodeFormatter.formatWhenEditorIsOpen(EclipseCodeFormatter.java:87)
    at krasa.formatter.plugin.EclipseCodeFormatter.format(EclipseCodeFormatter.java:52)
    at krasa.formatter.plugin.EclipseCodeStyleManager.formatWithEclipse(EclipseCodeStyleManager.java:206)
    at krasa.formatter.plugin.EclipseCodeStyleManager.formatInternal(EclipseCodeStyleManager.java:130)
    at krasa.formatter.plugin.EclipseCodeStyleManager.reformatText(EclipseCodeStyleManager.java:80)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at krasa.formatter.plugin.ProxyCodeStyleManagerDelegator.invoke(ProxyCodeStyleManagerDelegator.java:42)
    at net.sf.cglib.empty.Object$$EnhancerByCGLIB$$a6c18dd5.reformatText(<generated>)
    at com.intellij.codeInsight.actions.ReformatCodeProcessor.lambda$doReformat$5(ReformatCodeProcessor.java:201)
    at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:194)
    at com.intellij.codeInsight.actions.ReformatCodeProcessor.lambda$doReformat$6(ReformatCodeProcessor.java:185)
    at com.intellij.openapi.editor.ex.util.EditorScrollingPositionKeeper.perform(EditorScrollingPositionKeeper.java:101)
    at com.intellij.codeInsight.actions.ReformatCodeProcessor.doReformat(ReformatCodeProcessor.java:185)
    at com.intellij.codeInsight.actions.ReformatCodeProcessor.lambda$prepareTask$2(ReformatCodeProcessor.java:133)
    at com.intellij.application.options.CodeStyle.doWithTemporarySettings(CodeStyle.java:345)
    at com.intellij.codeInsight.actions.ReformatCodeProcessor.lambda$prepareTask$3(ReformatCodeProcessor.java:129)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.intellij.codeInsight.actions.AbstractLayoutCodeProcessor$ProcessingTask.lambda$performFileProcessing$7(AbstractLayoutCodeProcessor.java:474)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$1(WriteCommandAction.java:149)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:958)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$2(WriteCommandAction.java:147)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:184)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.doRunWriteCommandAction(WriteCommandAction.java:156)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:123)
    at com.intellij.codeInsight.actions.AbstractLayoutCodeProcessor$ProcessingTask.lambda$performFileProcessing$8(AbstractLayoutCodeProcessor.java:474)
    at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
    at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21)
    at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
    at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:456)
    at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:101)
    at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:79)
    at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:122)
    at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:41)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:788)
    at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
    at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:731)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:758)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:666)
    at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$7(IdeEventQueue.kt:570)
    at com.intellij.openapi.application.impl.ApplicationImpl.withoutImplicitRead(ApplicationImpl.java:1446)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:570)
    at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:68)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:349)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:348)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:787)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:348)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:343)
    at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:994)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
    at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:994)
    at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$4(IdeEventQueue.kt:343)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:385)
    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)
2023-04-11 08:53:50,672 [ 201353]   INFO - #c.i.w.i.i.j.s.JpsGlobalModelSynchronizerImpl - Saving global entities to files

It works when using Windows installation with project located on windows hard-drive. These are the log files from windows installation: IntelliJ IDEA 2023.1 (Community Edition) Build #IC-231.8109.175, built on March 28, 2023 Windows 10

2023-04-11 08:57:25,551 [ 372234]   FINE - krasa.formatter.plugin.ProxyCodeStyleManagerDelegator - invoking overriding {}({})reformatText[PsiJavaFile:SimpleAopCommentsComponent.java, [(0,1089)]]
2023-04-11 08:57:25,553 [ 372236]   FINE - krasa.formatter.plugin.EclipseCodeStyleManager_IJ_2016_3plus - format SimpleAopCommentsComponent.java 0 1089
2023-04-11 08:57:25,556 [ 372239]   FINE - krasa.formatter.plugin.EclipseCodeFormatter - #format 0-1089
2023-04-11 08:57:25,556 [ 372239]   FINE - krasa.formatter.plugin.EclipseCodeFormatter - #formatWhenEditorIsOpen SimpleAopCommentsComponent.java
2023-04-11 08:57:25,557 [ 372240]   FINE - krasa.formatter.eclipse.ConfigFileLocator - moduleFileDir=C:/PM1GitIdea/pm1j/pm...ui
2023-04-11 08:57:25,565 [ 372248]   FINE - krasa.formatter.eclipse.JavaCodeFormatterFacade - config located in 8ms (file://C:/PM1GitIdea/pm1j/pm...ui/.settings/org.eclipse.jdt.core.prefs)
2023-04-11 08:57:25,567 [ 372250]   INFO - krasa.formatter.eclipse.Classloaders - Creating classloader for [file:/C:/Users/mda/AppData/Roaming/JetBrains/IdeaIC2023.1/plugins/EclipseFormatter/lib/adapter.jar, file:/C:/Users/mda/AppData/Roaming/JetBrains/IdeaIC2023.1/plugins/EclipseFormatter/lib/eclipse.jar]
2023-04-11 08:57:25,618 [ 372301]   INFO - krasa.formatter.eclipse.JavaCodeFormatterFacade - newCodeFormatter in 53ms, (file://C:/PM1GitIdea/pm1j/pm....ui/.settings/org.eclipse.jdt.core.prefs)
2023-04-11 08:57:25,619 [ 372302]   FINE - krasa.formatter.adapter.EclipseJavaFormatterAdapter - #formatInternal
2023-04-11 08:57:25,631 [ 372314]   FINE - krasa.formatter.adapter.EclipseJavaFormatterAdapter - #starting to format by eclipse formatter
2023-04-11 08:57:26,042 [ 372725]   FINE - krasa.formatter.adapter.EclipseJavaFormatterAdapter - reformatting done
2023-04-11 08:57:26,078 [ 372761]   FINE - krasa.formatter.plugin.EclipseCodeFormatter - #formatWhenEditorIsOpen done
2023-04-11 08:57:28,081 [ 374764]   INFO - #c.i.w.i.i.j.s.JpsGlobalModelSynchronizerImpl - Saving global entities to files

Any idea what could go wrong? (Any tips to fix this)

krasa commented 1 year ago

Formatter config file not resolved it is looking for a config within your project, create it, or select it manually.

korner11 commented 1 year ago

It should be located in the ".settings/org.eclipse.jdt.core.prefs" of the currently opened maven module.

Project specific config option should find it under maven module folder right? But looks like it wont find it for unknown reason.

krasa commented 1 year ago

Seems broken :(

korner11 commented 1 year ago

Any tip what could be wrong that file is not visible for plugin?

krasa commented 1 year ago

Some platform change, I need to convert the project to Gradle and debug it.

korner11 commented 1 year ago

OK. Please let me know if you find something.

krasa commented 1 year ago

it seems that it only needed a recompilation

you can try it before an approval: EclipseFormatter-23.0.223.000.0-Eclipse_2023-03.zip

korner11 commented 1 year ago

Thank you. But it still not work for me. Maybe I will need to reinstall WSL.

krasa commented 1 year ago

Perhaps you could debug the plugin?
krasa.formatter.eclipse.ConfigFileLocator#traverseToFindConfigurationFileByConvention

korner11 commented 1 year ago

Thank you for the tip. :) After debugging of the plugin I found out that problem is missing *.iml file in the module directory. We also discovered that newer version of IDEA do not generate these files automatically anymore. User have to uncheck "Enable Fast import" option and check "Store generated project files under the project root" idea_mvn_settings

However this options became deprecated and probably will be removed in the future. We submitted new issue to JetBrain guys to provide a new way of determination of the parent module directory, so the plugin can be then updated accordingly. https://youtrack.jetbrains.com/issue/IDEA-317813/Missing-iml-files-for-maven-modules

krasa commented 1 year ago

Well, Module#getModuleFile should not be used anyway, perhaps this will work.

korner11 commented 1 year ago

Thanks, looks like fix is working.

krasa commented 1 year ago

Thanks, I will release it.