Description
What steps will reproduce the issue?
Create an IDE Kotlin script as below:
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.psi.PsiFile
import com.intellij.psi.codeStyle.CodeStyleManager
class ReformatListener(private val project: Project) : CodeStyleManager.Listener {
init {
LOGGER.info("Listener created for project " + project.name)
}
override fun beforeReformatText(file: PsiFile) {
LOGGER.info("beforeReformatText: " + project.name)
}
override fun afterReformatText(file: PsiFile) {
LOGGER.info("afterReformatText: " + project.name)
}
companion object {
private val LOGGER: Logger = Logger.getInstance(ReformatListener::class.java)
}
}
var project = ProjectManager.getInstance().openProjects[0] // Or the project instance you know
project.messageBus.connect().subscribe(CodeStyleManager.Listener.TOPIC, ReformatListener(project))
Run the script, and reformat any file.
What is the expected result?
Intellij log file idea.log
shows the logs Listener created for project <projectName>
, beforeReformatText: <projectName>
, and afterReformatText: <projectName>
, just like when the default formatter of Intellij is used.
What happens instead?
No logs are printed.
Paste information about IDE and OS (it can be copied from Help | About dialog).
IntelliJ IDEA 2023.3.1 (Community Edition)
Build #IC-233.11799.300, built on December 12, 2023
Runtime version: 17.0.9+7-b1087.7 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Registry:
debugger.new.tool.window.layout=true
ide.experimental.ui=true
Non-Bundled Plugins:
DevKit (233.11799.300)
EclipseCodeFormatter (23.3.223.000.0-Eclipse_2023-03)
com.demonwav.minecraft-dev (2023.3-1.6.12)
Kotlin: 233.11799.300-IJ
As used in com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl#reformatText(com.intellij.psi.PsiFile, com.intellij.formatting.FormatTextRanges)
, include the lines
this.original.getProject().getMessageBus().syncPublisher(Listener.TOPIC).beforeReformatText(file);
and
this.original.getProject().getMessageBus().syncPublisher(Listener.TOPIC).afterReformatText(file);
before and after formatting in EclipseCodeStyleManager
.