From b80a89e36d5dc62c49ccfd975756c9583949c69c Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Tue, 3 Oct 2017 15:12:39 +0300 Subject: [PATCH] fix too strict hints offset condition Required for RUBY-20196, see `ParamHintsTest.testRestAndBlock` --- .../codeInsight/hints/ParameterHintsPass.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPass.java index 2c04f53821d6..e179b586c1a0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPass.java @@ -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;