Restarting inlay hints provider

已回答

How can I trigger the inlay hints to be computed again for any open (selected) editors?

DaemonCodeAnalyzer.getInstance(project).restart(); doesnt't work.

I also tried:

DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project);
        final FileEditor selectedEditor = FileEditorManager.getInstance(project).getSelectedEditor();
        if (selectedEditor != null) {
            final VirtualFile file = selectedEditor.getFile();
            if (file != null) {
                final PsiFile psiFile = ReadAction.compute(() -> PsiManager.getInstance(project).findFile(file));
                final Document document = ReadAction.compute(() -> FileDocumentManager.getInstance().getDocument(file));
                final ProgressIndicator daemonIndicator = new DaemonProgressIndicator();
                ProgressManager.getInstance().runProcess(() -> {
                    ReadAction.run(() -> codeAnalyzer.runMainPasses(psiFile, document, daemonIndicator));

                }, daemonIndicator);
                codeAnalyzer.restart();
            }
        }

Writing anything in the open file causes the inlay hints to be recomputed but I want to trigger it programmatically.

Thanks!

0

ParameterHintsPassFactory#forceHintsUpdateOnNextPass  before DaemonCodeAnalyzer#restart to force redraw

1

I'm trying to get an InlayHintProvider (subclass of com.intellij.codeInsight.hints.InlayHintsProvider) to trigger again with this method in IC 2023.1 but it doesn't seem to do anything.

Is there a new approach to force the inlay provider to re-render?

For context, the reason why I need to re-render is because my plugin's inlay provider needs to load information asynchronously (i.e. in a background thread), while collect() is called on the UI thread. Perhaps there's a better way to do this!

0

Make sure these calls are performed from EDT. If it still doesn't work, please share your code.

0

Thank you Yann Cebron. This doesn't work for me, so here's a minimal repo you can clone to reproduce the issue: https://github.com/fwouts/intellij-inlays-refresh. This is a contrived example with an InlayProvider that should show a counter that increases once per second.

0

Thanks for the sample. It works when using InlayHintsPassFactory.forceHintsUpdateOnNextPass() instead of ParameterHintsPassFactory.forceHintsUpdateOnNextPass().
ParameterHintsPassFactory only highlights inlays contributed via com.intellij.codeInsight.hints.InlayParameterHintsProvider extension point.

0

Thank you so much Yann Cebron, this was exactly what I needed. My plugin can finally work without blocking the main thread 🥳 Here's the source for anyone else looking for a concrete example.

0

FYI to anyone reading this thread after December 2023: InlayHintsPassFactory.forceHintsUpdateOnNextPass() has been moved to an internal package and you can no longer use this. You can use DaemonCodeAnalyzer.getInstance(project).restart(psiFile) instead, although I'm not sure it's as efficient. See https://youtrack.jetbrains.com/issue/IDEA-333164 for discussion.

0

I discovered this worked for me since I was using declaritvie Inlay Hints

DeclarativeInlayHintsPassFactory.scheduleRecompute(textEditor.getEditor(), project)

 

0

请先登录再写评论。