How to disable parameter hints for an editor instance? EditorSettingsExternalizable.SHOW_PARAMETER_NAME_HINTS is now ignored.

Answered

In my plugin, MissingInActions, I disabled parameter hints for active editor if more than one caret is displayed, to eliminate text displacement which made multi-caret ops harder to use.

I noticed that in 2023.1, EditorSettingsExternalizable.SHOW_PARAMETER_NAME_HINTS is now ignored.

Two questions:

1. Why no @Deprecated annotation, even post change, to highlight that this is no longer used.

2. How do I disable all inlay hints for a particular editor, without disabling them globally for all languages or globally for a language?

0
4 comments

I'm not sure about your first questions. As for your second one, can you try something like this:

editor.inlayModel.execute(false) {

editor.inlayModel
.getInlineElementsInRange(0, Int.MAX_VALUE, InlayPresentation::class.java)
.forEach { it.dispose() }

editor.inlayModel
.getBlockElementsInRange(0, Int.MAX_VALUE, InlayPresentation::class.java)
.forEach { it.dispose() }

...

}

It is from VisualFormattingLayerService

0

Thank you Patrick, I will try it. Is there an easy way to reverse the above changes to restore inlay display?

Question 1, refers to the fact that the setting is now silently ignored. I think it should be annotated with @Deprecated, even if it is after the fact. 

0

First, if you look at com.intellij.formatting.visualLayer.VisualFormattingLayerService, you'll see that there are functions enableForEditor() and disableForEditor(). I was just giving you the core, because I think the visual layer also turns on/off folding. But I haven't tested it.

I'm still not sure if there is a right way to turn on/off hints only for the current editor. I looked through the API some more and there is

  • com.intellij.codeInsight.hints.ToggleInlayHintsGloballyAction
  • com.intellij.codeInsight.hints.InlayHintsSwitch

but these toggle the hints globally and not on a per-editor basis. Would you try to dig into the API yourself with these starting points and see if you find a good solution?

 

0

Thank you Patrick for the detailed reply. I also found the ToggleInlayHintsGloballyAction and followed it to the InlayHintsSwitch.

I finally opted out to use the InlayHintsSwitch to switch the hints on/off globally because I felt that using anything deeper in the implementation would most likely break as the implementation evolved.

I will have to try it out in use cases where the current editor is switched while the hints are disabled, to one that does not have multiple carets and vice versa, to see if the toggling of hints globally does not create too  much disruption. However, for now it seems to be sufficient.

1

Please sign in to leave a comment.