Question:
The Rider plugin I am working on needs to run code when the “build solution” starts, succeeds, and fails. I tried implementing ProjectTaskListener to override the started and finished methods and use the result variable to determine whether the build failed or not. However, while this works on IntelliJ IDEA, it did not work on Rider, as ProjectTaskListener is not called. What listener to use instead? There are hundreds of extension points and listeners at https://plugins.jetbrains.com/docs/intellij/intellij-platform-extension-point-list.html, and every open-source plugin I saw that did the same thing used ProjectTaskListener, which is not called in Rider during the build solution event.
Answer:
Implement something like this:
class BuildRunListener : SolutionExtListener<BuildModel> {
override fun extensionCreated(lifetime: Lifetime, session: ClientProjectSession, model: BuildModel) {
model.buildSession.viewNotNull(lifetime) { buildSessionLt, buildSession ->
buildSession.result.advise(buildSessionLt) {
when (it.kind) {
BuildResultKind.Successful, BuildResultKind.HasWarnings -> // build success
BuildResultKind.HasErrors -> // build error
BuildResultKind.Canceled -> // user cancellation
BuildResultKind.Crashed -> // critical build error, MSBuild crashed
}
}
}
}
}
and then register in your plugin.xml like this:
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<rd.solutionExtListener endpoint="IDE Frontend"
listener="your.package.BuildRunListener"/>
</extensions>
</idea-plugin>
The buildSession object has properties, such as result, that you may subscribe to and analyze.
Note that this event will be delivered asynchronously. Also, it may also be emitted on certain other operations, such as NuGet restore and publish/deployment.
If you are only interested in actual build operations, add a check for buildSession.operation is BuildTarget.
Limitations:
SolutionExtListener is an internal API, if your plugin used this class, you can only install it to your local Rider dev env but can't be published to the JetBrains Marketplace.
Comments
0 comments
Please sign in to leave a comment.