fix: [NO BACKPORT] replace internal API usage with safe reflection
This commit is contained in:
parent
52a3714175
commit
a76138ddea
2 changed files with 63 additions and 12 deletions
|
@ -19,9 +19,9 @@ package com.falsepattern.zigbrains.zig.lsp;
|
|||
import com.falsepattern.zigbrains.ZigBundle;
|
||||
import com.falsepattern.zigbrains.common.util.ApplicationUtil;
|
||||
import com.falsepattern.zigbrains.zig.settings.ZLSProjectSettingsService;
|
||||
import com.falsepattern.zigbrains.zig.util.JBInternalPluginManagerConfigurable;
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.ide.plugins.PluginManagerConfigurable;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationAction;
|
||||
import com.intellij.notification.NotificationType;
|
||||
|
@ -69,17 +69,17 @@ public class ZLSStartupActivity implements ProjectActivity {
|
|||
ZigBundle.message("notification.nativedebug.text"),
|
||||
NotificationType.INFORMATION
|
||||
);
|
||||
notif.addAction(new NotificationAction(ZigBundle.message("notification.nativedebug.market")) {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
|
||||
val configurable = new PluginManagerConfigurable();
|
||||
ShowSettingsUtil.getInstance().editConfigurable((Project)null,
|
||||
configurable,
|
||||
() -> {
|
||||
configurable.openMarketplaceTab("/vendor:\"JetBrains s.r.o.\" /tag:Debugging \"Native Debugging Support\"");
|
||||
});
|
||||
}
|
||||
});
|
||||
if (JBInternalPluginManagerConfigurable.successful) {
|
||||
notif.addAction(new NotificationAction(ZigBundle.message("notification.nativedebug.market")) {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
|
||||
val configurable = new JBInternalPluginManagerConfigurable();
|
||||
ShowSettingsUtil.getInstance().editConfigurable((Project) null, configurable.instance, () -> {
|
||||
configurable.openMarketplaceTab("/vendor:\"JetBrains s.r.o.\" /tag:Debugging \"Native Debugging Support\"");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
notif.addAction(new NotificationAction(ZigBundle.message("notification.nativedebug.browser")) {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.falsepattern.zigbrains.zig.util;
|
||||
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import lombok.val;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
//JetBrains Internal API, but we need to access it, so access it reflectively (hopefully safe enough to pass verifier)
|
||||
public class JBInternalPluginManagerConfigurable {
|
||||
private static final Constructor<?> constructor;
|
||||
private static final Method openMarketplaceTab;
|
||||
public static final boolean successful;
|
||||
|
||||
public final Configurable instance;
|
||||
|
||||
static {
|
||||
boolean success = false;
|
||||
Constructor<?> constructor1 = null;
|
||||
Method openMarketplaceTab1 = null;
|
||||
try {
|
||||
val theClass = Class.forName("com_intellij_ide_plugins_PluginManagerConfigurable".replace('_', '.'));
|
||||
constructor1 = theClass.getDeclaredConstructor();
|
||||
constructor1.setAccessible(true);
|
||||
openMarketplaceTab1 = theClass.getDeclaredMethod("openMarketplaceTab", String.class);
|
||||
openMarketplaceTab1.setAccessible(true);
|
||||
success = true;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
successful = success;
|
||||
constructor = constructor1;
|
||||
openMarketplaceTab = openMarketplaceTab1;
|
||||
}
|
||||
|
||||
public JBInternalPluginManagerConfigurable() {
|
||||
try {
|
||||
instance = (Configurable) constructor.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void openMarketplaceTab(String option) {
|
||||
try {
|
||||
openMarketplaceTab.invoke(instance, option);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue