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

Do not use IntelliJ APIs marked as @Internal #813

Open
cies opened this issue Apr 12, 2024 · 2 comments
Open

Do not use IntelliJ APIs marked as @Internal #813

cies opened this issue Apr 12, 2024 · 2 comments

Comments

@cies
Copy link
Contributor

cies commented Apr 12, 2024

This should be the last changes needed to get this plugin accepted in the JetBrains Marketplace.

I'm in discussion with JetBrains' Albert Ishmukhametov to resolve this. I want to document the conversation here.


There are 3 instances where the plugin I try to publish (https://plugins.jetbrains.com/plugin/24075-elm) uses @Internal annotated API. I did not know this was reason to reject, but since it is I'm right on it.

image

All three are not listed and the help in the code comments is also not much helpful.

For the fireBefore/AfterActionPerformed the code comments say: Do not call directly, prefer [ActionUtil] methods.
See: https://github.com/JetBrains/intellij-community/blob/434fa3cc12140cd6004411afa75b8dfbea8c327c/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionManagerEx.kt#L106
But ActionUtil has nothing like these methods. I read the whole class.

For AnActionResult.PERFORMED there is not even a reference to what should be used instead.
See: https://github.com/JetBrains/intellij-community/blob/434fa3cc12140cd6004411afa75b8dfbea8c327c/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionResult.java#L13

The code I want to replace is quite simple:

fun executeAction(action: AnAction, place: String, dataContext: DataContext) {

fun executeAction(action: AnAction, place: String, dataContext: DataContext) {
    val event = AnActionEvent.createFromAnAction(action, null, place, dataContext)
    action.beforeActionPerformedUpdate(event)
    action.update(event)

    if (event.presentation.isEnabled && event.presentation.isVisible) {
        val actionManager = ActionManagerEx.getInstanceEx()
        actionManager.fireBeforeActionPerformed(action, event)
        action.actionPerformed(event)
        actionManager.fireAfterActionPerformed(action, event, AnActionResult.PERFORMED)
    }
}

I have no idea how to change this bit of code from using ActionManagerEx andfireBefore/AfterActionPerformed(...) to use ActionUtil instead. Is there some mode documentation somewhere, or do you have a link to a commit in an opensource plugin that does something similar?

It may be part of a larger problem, because, as I see (in the same file) NotificationGroup.balloonGroup(...) is deprecated, it may mean I have to create this balloonGroup notification widget differently.
The deprecation warning there says: Use com.intellij.notification.impl.NotificationGroupEP and com.intellij.notification.NotificationGroupManager

So I change:

private val pluginNotifications = NotificationGroup.balloonGroup("Elm Plugin")

into

private val pluginNotifications = NotificationGroupManager.getInstance().getNotificationGroup("Elm Plugin")

The argument name of balloonGroup(...) is displayId, where the argument name of getNotificationGroup(...) is groupId. After changing this IDEA complains saying: "Cannot resolve notification group id 'Elm Plugin'"

I think the documentation on how to rework code not to use deprecated or @Internal API is sometimes a bit sparse.

@kuglee
Copy link

kuglee commented Apr 12, 2024

Can't really help with the concrete issue. But for a quick dirty hack Java functions/methods can be dynamically called. Years ago my plugin used an internal api too. After I called the method dynamically it wasn't detected by JetBrains.
Here is an example from my plugin: https://github.com/kuglee/intellij-swift-format/blob/8de7ab182b31fc63b937a558ce2c48b88b028c82/src/main/kotlin/org/swiftformat/plugin/SwiftFormatInstaller.kt#L49

@cies
Copy link
Contributor Author

cies commented Apr 17, 2024

@kuglee I filed an issue with them asking for help on how to move away from some use of @Internal APIs. No response yet, but they have admitted the plugin to the Marketplace non the less.

Probably it was not that important I did not use the internal API :)

@cies cies removed the upgrade deps label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants