fix too strict hints offset condition

Required for RUBY-20196, see `ParamHintsTest.testRestAndBlock`
This commit is contained in:
Valentin Fondaratov
2017-10-03 15:13:14 +03:00
parent 6f06345c4a
commit b80a89e36d
@@ -94,8 +94,8 @@ public class ParameterHintsPass extends EditorBoundHighlightingPass {
inlays.forEach((hint) -> {
int offset = hint.getOffset();
TextRange rootRange = myRootElement.getTextRange();
if (offset <= rootRange.getStartOffset() || offset >= rootRange.getEndOffset()) return;
if (!canShowHintsAtOffset(offset)) return;
String presentation = provider.getInlayPresentation(hint.getText());
if (hint.isShowOnlyIfExistedBefore()) {
myShowOnlyIfExistedBeforeHints.put(offset, presentation);
@@ -138,6 +138,21 @@ public class ParameterHintsPass extends EditorBoundHighlightingPass {
return ContainerUtil.filter(inlays, (hint) -> manager.isParameterHint(hint));
}
/**
* Adding hints on the borders of root element (at startOffset or endOffset)
* is allowed only in the case when root element is a document
*
* @return true iff a given offset can be used for hint rendering
*/
private boolean canShowHintsAtOffset(int offset) {
TextRange rootRange = myRootElement.getTextRange();
if (!rootRange.containsOffset(offset)) return false;
if (offset > rootRange.getStartOffset() && offset < rootRange.getEndOffset()) return true;
return myDocument != null && myDocument.getTextLength() == rootRange.getLength();
}
public static class HintData {
public final String presentationText;