From 07a569ad48a1e4eda6fe70bce135b5825e259b97 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Tue, 31 Jul 2012 08:57:20 +0400 Subject: [PATCH] IDEA-89471 Vertical guidelines are drawn incorrectly --- .../TextEditorHighlightingPass.java | 9 +++--- .../codeInsight/daemon/impl/IndentsPass.java | 28 +++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java index 7c7a123b3d5d..f6a44ddce93d 100644 --- a/platform/lang-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ import java.util.List; public abstract class TextEditorHighlightingPass implements HighlightingPass { public static final TextEditorHighlightingPass[] EMPTY_ARRAY = new TextEditorHighlightingPass[0]; - protected final Document myDocument; - protected final Project myProject; + @Nullable protected final Document myDocument; + @NotNull protected final Project myProject; private final boolean myRunIntentionPassAfter; private final long myInitialStamp; private int[] myCompletionPredecessorIds = ArrayUtil.EMPTY_INT_ARRAY; @@ -81,7 +81,7 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass { } if (myDocument != null && myDocument.getModificationStamp() != myInitialStamp) return false; - if (myProject != null && myDocument != null) { + if (myDocument != null) { PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); if (file == null || !file.isValid()) return false; } @@ -128,6 +128,7 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass { myCompletionPredecessorIds = completionPredecessorIds; } + @Nullable public Document getDocument() { return myDocument; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java index 9f1627f4134e..dc17ab3e5f56 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java @@ -331,7 +331,11 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware } private boolean isBlankLine(int line, CharSequence chars) { - int startOffset = myDocument.getLineStartOffset(line); + Document document = myDocument; + if (document == null) { + return true; + } + int startOffset = document.getLineStartOffset(line); return CharArrayUtil.shiftForward(chars, startOffset, " \t") >= myDocument.getLineEndOffset(line); } @@ -339,6 +343,7 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware final Document doc = myDocument; CharSequence chars = doc.getCharsSequence(); int[] lineIndents = new int[doc.getLineCount()]; + boolean[] indentStartedInComment = new boolean[lineIndents.length]; TokenSet comments = LanguageParserDefinitions.INSTANCE.forLanguage(myFile.getLanguage()).getCommentTokens(); int prevColumn = -1; @@ -353,11 +358,24 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware int nonWhitespaceOffset = CharArrayUtil.shiftForward(chars, lineStart, " \t"); if (nonWhitespaceOffset < lineEnd) { final int column = myEditor.calcColumnNumber(nonWhitespaceOffset, line); - if (column < prevColumn) { + if (column != prevColumn) { final HighlighterIterator it = highlighter.createIterator(nonWhitespaceOffset); - if (comments.contains(it.getTokenType())) { - lineIndents[line] = -1; - continue; + boolean comment = comments.contains(it.getTokenType()); + if (column > prevColumn && comment) { + indentStartedInComment[line] = true; + } + else if (column < prevColumn && comment) { + boolean startInComment = false; + for (int i = line - 1; i >= 0 && (lineIndents[i] < 0 || lineIndents[i] >= column); i--) { + if (indentStartedInComment[i]) { + startInComment = true; + break; + } + } + if (!startInComment) { + lineIndents[line] = -1; + continue; + } } }