diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LayeredLexerEditorHighlighter.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LayeredLexerEditorHighlighter.java index 1328c862c46e..8719c0735840 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LayeredLexerEditorHighlighter.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LayeredLexerEditorHighlighter.java @@ -16,6 +16,8 @@ package com.intellij.openapi.editor.ex.util; +import com.intellij.openapi.diagnostic.Attachment; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.colors.EditorColorsScheme; @@ -26,10 +28,12 @@ import com.intellij.openapi.editor.highlighter.HighlighterClient; import com.intellij.openapi.editor.highlighter.HighlighterIterator; import com.intellij.openapi.editor.impl.DocumentImpl; import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.tree.IElementType; import com.intellij.util.containers.FactoryMap; import com.intellij.util.containers.IntArrayList; @@ -45,6 +49,7 @@ import java.util.*; * @author max */ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter { + private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.ex.util.LayeredLexerEditorHighlighter"); private final Map myTokensToLayer = new HashMap<>(); private final Map myLayerBuffers = new HashMap<>(); @@ -107,11 +112,20 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter { final int len = lengths.get(i); start += mySeparator.length(); final int globalIndex = index2Global.get(i); - assert getSegments().myRanges[globalIndex] == null : myText; + checkNull(type, getSegments().myRanges[globalIndex]); getSegments().myRanges[globalIndex] = new MappedRange(mapper, document.createRangeMarker(start, start + len), type); start += len; } } + + private void checkNull(IElementType type, MappedRange range) { + if (range != null) { + Document mainDocument = getDocument(); + VirtualFile file = mainDocument == null ? null : FileDocumentManager.getInstance().getFile(mainDocument); + LOG.error("Expected null range on " + type + ", found " + range + "; highlighter=" + getSyntaxHighlighter(), + new Attachment(file != null ? file.getName() : "editorText.txt", myText.toString())); + } + } } @Override @@ -456,6 +470,11 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter { this.outerToken = outerToken; assert mapper.doc == range.getDocument(); } + + @Override + public String toString() { + return "MappedRange{range=" + range + ", outerToken=" + outerToken + '}'; + } } @Nullable