live-plugin
live-plugin copied to clipboard
Question: How can I trigger a "reload" from within my plugin ?
I have a problem with my plugin stopping to work for some reason, it might be LivePlugin related or something else I can't figure out. However, a click on "reload" solves it. I would like the plugin to reload itself when it detects the problem, is that possible ?
It's not very clear what you mean by "stopping to work" and it's hard to guess without knowing what the plugin does.
In general, it's not the best idea to leave things broken. You might be able to see if something went wrong in IDE logs. It's also possible that some of IJ APIs swallow exceptions, so you can wrap some of your code with try/catch to log exceptions yourself.
To reload plugin you try using these functions:
- liveplugin.implementation.Actions#unloadLivePlugin
- liveplugin.implementation.Actions#runLivePlugin
thanks!
Regarding stopping to work: It's that plugin: https://github.com/cmp-nct/Stewardess The plugin looks at the official Copilot completions displayed and offers a word-by-word completion instead (without this copilot is quite a cancer and blurps dysfunctional code all over the screen).
It's not that easy to debug (Plus I've written that in PHPStorm, so no syntax support and I don't know kotlin, a wonder I got that far) After some days it happens that the plugin does not see the completions of copilot anymore. When restarting the plugin all works fine immediately. Something internally gets broken and it doesn't look like I can fix the actual issue. It might be anything, unlikely my own code.
Thank you for sharing the link to the project. It looks like an interesting idea!
As a random guess var project = copilot.findCurrentProject()
will assign project once on plugin startup, so if you switch to a different project, this definitely won't work. Ideally, project
should be passed from ActionEvent
.
If I understand it correctly, ultimately the problem is that editorManager.collectInlays()
doesn't return any inlays.
Looking at its decompiled code, it doesn't really do anything very complicated, just standard IJ API:
@RequiresEdt
public @NotNull List<CopilotInlayRenderer> collectInlays(@NotNull Editor editor, int startOffset, int endOffset) {
InlayModel model = editor.getInlayModel();
ArrayList<Inlay<?>> inlays = new ArrayList();
inlays.addAll(model.getInlineElementsInRange(startOffset, endOffset));
inlays.addAll(model.getAfterLineEndElementsInRange(startOffset, endOffset));
inlays.addAll(model.getBlockElementsInRange(startOffset, endOffset));
ArrayList<CopilotInlayRenderer> renderers = new ArrayList();
Iterator var7 = inlays.iterator();
while(var7.hasNext()) {
Inlay<?> inlay = (Inlay)var7.next();
if (inlay.getRenderer() instanceof CopilotInlayRenderer) {
renderers.add((CopilotInlayRenderer)inlay.getRenderer());
}
}
return renderers;
}
Btw, there is an option to create a "proper" plugin using Create Kotlin Plugin Zip
action (it's a bit experimental though) 🙂