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

Question: How can I trigger a "reload" from within my plugin ? #154

Open
cmp-nct opened this issue Feb 6, 2023 · 4 comments
Open

Question: How can I trigger a "reload" from within my plugin ? #154

cmp-nct opened this issue Feb 6, 2023 · 4 comments

Comments

@cmp-nct
Copy link

cmp-nct commented Feb 6, 2023

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 ?

@dkandalov
Copy link
Owner

dkandalov commented Feb 7, 2023

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

@cmp-nct
Copy link
Author

cmp-nct commented Mar 23, 2023

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.

@dkandalov
Copy link
Owner

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;
    }

@dkandalov
Copy link
Owner

Btw, there is an option to create a "proper" plugin using Create Kotlin Plugin Zip action (it's a bit experimental though) 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants