From e68914fc87b8592e6060df2b44dc4e396f2a1f1e Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Fri, 7 Jun 2019 20:09:56 +0300 Subject: [PATCH] Allow to customize data storage for lexer-based highlighting GitOrigin-RevId: 6cb1bea1bb069fe3c79b1fc943b99b175b9075be --- .../editor/ex/util/DataStorageFactory.java | 33 +++++++++++++++++++ .../ex/util/LexerEditorHighlighter.java | 4 +-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 platform/core-impl/src/com/intellij/openapi/editor/ex/util/DataStorageFactory.java diff --git a/platform/core-impl/src/com/intellij/openapi/editor/ex/util/DataStorageFactory.java b/platform/core-impl/src/com/intellij/openapi/editor/ex/util/DataStorageFactory.java new file mode 100644 index 000000000000..6c1b1520f857 --- /dev/null +++ b/platform/core-impl/src/com/intellij/openapi/editor/ex/util/DataStorageFactory.java @@ -0,0 +1,33 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.editor.ex.util; + +import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * An experiment API for providing custom way of storing lexer-based highlighting data. + *

+ * By default a highlighting lexer uses {@link ShortBasedStorage} implementation which + * serializes information about element type to be highlighted with their indices ({@link IElementType#getIndex()}) + * and deserializes ids back to {@link IElementType} using + * element types registry {@link IElementType#find(short)}. + *

+ * If you need to store more information during syntax highlighting or + * if your element types cannot be restored from {@link IElementType#getIndex()}, + * you can implement you own storage and make your highlighting lexer implement {@link DataStorageFactory} + * that will create the custom storage. + *

+ * As an example, see {@link org.jetbrains.plugins.textmate.language.syntax.lexer.TextMateHighlightingLexer}, + * that lexes files with unregistered (whitout index) element types and + * its data storage ({@link org.jetbrains.plugins.textmate.language.syntax.lexer.TextMateLexerDataStorage} + * serializes/deserializes them to/from strings. + * + * @see com.intellij.openapi.editor.ex.util.LexerEditorHighlighter + * @see SegmentArrayWithData + */ +@ApiStatus.Experimental +public interface DataStorageFactory { + @NotNull + DataStorage createDataStorage(); +} diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java index 69409a662cb1..d51a1a4404c1 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.editor.ex.util; import com.intellij.lexer.FlexAdapter; @@ -61,7 +61,7 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc @NotNull protected SegmentArrayWithData createSegments() { - return new SegmentArrayWithData(myLexer instanceof RestartableLexer ? new IntBasedStorage() : new ShortBasedStorage()); + return new SegmentArrayWithData(myLexer instanceof DataStorageFactory ? ((DataStorageFactory)myLexer).createDataStorage() : new ShortBasedStorage()); } public boolean isPlain() {