use of com.intellij.openapi.fileTypes.SyntaxHighlighter in project intellij-community by JetBrains.
the class SimpleEditorPreview method navigate.
private void navigate(boolean select, @NotNull final LogicalPosition pos) {
int offset = myEditor.logicalPositionToOffset(pos);
final SyntaxHighlighter highlighter = myPage.getHighlighter();
String type;
HighlightData highlightData = getDataFromOffset(offset);
if (highlightData != null) {
// tag-based navigation first
type = RainbowHighlighter.isRainbowTempKey(highlightData.getHighlightKey()) ? RainbowHighlighter.RAINBOW_TYPE : highlightData.getHighlightType();
} else {
// if failed, try the highlighter-based navigation
type = selectItem(myEditor.getHighlighter().createIterator(offset), highlighter);
}
setCursor(type == null ? Cursor.TEXT_CURSOR : Cursor.HAND_CURSOR);
if (select && type != null) {
myDispatcher.getMulticaster().selectionInPreviewChanged(type);
}
}
use of com.intellij.openapi.fileTypes.SyntaxHighlighter in project intellij-community by JetBrains.
the class LanguageConsoleImpl method printWithHighlighting.
public static String printWithHighlighting(@NotNull LanguageConsoleView console, @NotNull Editor inputEditor, @NotNull TextRange textRange) {
String text;
EditorHighlighter highlighter;
if (inputEditor instanceof EditorWindow) {
PsiFile file = ((EditorWindow) inputEditor).getInjectedFile();
highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), console.getProject());
String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null);
highlighter.setText(fullText);
text = textRange.substring(fullText);
} else {
text = inputEditor.getDocument().getText(textRange);
highlighter = ((EditorEx) inputEditor).getHighlighter();
}
SyntaxHighlighter syntax = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter) highlighter).getSyntaxHighlighter() : null;
((LanguageConsoleImpl) console).doAddPromptToHistory();
if (syntax != null) {
ConsoleViewUtil.printWithHighlighting(console, text, syntax);
} else {
console.print(text, ConsoleViewContentType.USER_INPUT);
}
console.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
return text;
}
use of com.intellij.openapi.fileTypes.SyntaxHighlighter in project intellij-community by JetBrains.
the class MultiHostRegistrarImpl method obtainHighlightTokensFromLexer.
// returns lexer element types with corresponding ranges in encoded (injection host based) PSI
private static List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> obtainHighlightTokensFromLexer(Language language, StringBuilder outChars, List<LiteralTextEscaper<? extends PsiLanguageInjectionHost>> escapers, Place shreds, VirtualFileWindow virtualFile, Project project) {
List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> tokens = new ArrayList<>(10);
SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, (VirtualFile) virtualFile);
Lexer lexer = syntaxHighlighter.getHighlightingLexer();
lexer.start(outChars);
int hostNum = -1;
int prevHostEndOffset = 0;
SmartPsiElementPointer<PsiLanguageInjectionHost> host = null;
LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = null;
int prefixLength = 0;
int suffixLength = 0;
TextRange rangeInsideHost = null;
int shredEndOffset = -1;
for (IElementType tokenType = lexer.getTokenType(); tokenType != null; lexer.advance(), tokenType = lexer.getTokenType()) {
TextRange range = new ProperTextRange(lexer.getTokenStart(), lexer.getTokenEnd());
while (range != null && !range.isEmpty()) {
if (range.getStartOffset() >= shredEndOffset) {
hostNum++;
PsiLanguageInjectionHost.Shred shred = shreds.get(hostNum);
shredEndOffset = shred.getRange().getEndOffset();
prevHostEndOffset = range.getStartOffset();
host = ((ShredImpl) shred).getSmartPointer();
escaper = escapers.get(hostNum);
rangeInsideHost = shred.getRangeInsideHost();
prefixLength = shred.getPrefix().length();
suffixLength = shred.getSuffix().length();
}
//in prefix/suffix or spills over to next fragment
if (range.getStartOffset() < prevHostEndOffset + prefixLength) {
range = new UnfairTextRange(prevHostEndOffset + prefixLength, range.getEndOffset());
}
TextRange spilled = null;
if (range.getEndOffset() > shredEndOffset - suffixLength) {
spilled = new UnfairTextRange(shredEndOffset, range.getEndOffset());
range = new UnfairTextRange(range.getStartOffset(), shredEndOffset - suffixLength);
}
if (!range.isEmpty()) {
int start = escaper.getOffsetInHost(range.getStartOffset() - prevHostEndOffset - prefixLength, rangeInsideHost);
if (start == -1)
start = rangeInsideHost.getStartOffset();
int end = escaper.getOffsetInHost(range.getEndOffset() - prevHostEndOffset - prefixLength, rangeInsideHost);
if (end == -1) {
end = rangeInsideHost.getEndOffset();
prevHostEndOffset = shredEndOffset;
}
TextRange rangeInHost = new ProperTextRange(start, end);
tokens.add(Trinity.create(tokenType, host, rangeInHost));
}
range = spilled;
}
}
return tokens;
}
use of com.intellij.openapi.fileTypes.SyntaxHighlighter in project intellij-community by JetBrains.
the class LanguagePanel method updateHighlighters.
void updateHighlighters() {
final EditorImpl editor = ((EditorImpl) myPrefix.getEditor());
if (editor == null)
return;
final EditorImpl editor2 = ((EditorImpl) mySuffix.getEditor());
assert editor2 != null;
final Language language = InjectedLanguage.findLanguageById(getLanguage());
if (language == null) {
editor.setHighlighter(new LexerEditorHighlighter(new PlainSyntaxHighlighter(), editor.getColorsScheme()));
editor2.setHighlighter(new LexerEditorHighlighter(new PlainSyntaxHighlighter(), editor.getColorsScheme()));
} else {
final SyntaxHighlighter s1 = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, null);
final SyntaxHighlighter s2 = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, null);
editor.setHighlighter(new LexerEditorHighlighter(s1, editor.getColorsScheme()));
editor2.setHighlighter(new LexerEditorHighlighter(s2, editor2.getColorsScheme()));
}
}
use of com.intellij.openapi.fileTypes.SyntaxHighlighter in project intellij-community by JetBrains.
the class GroovyEditorHighlighter method registerGroovydocHighlighter.
private void registerGroovydocHighlighter() {
// Register GroovyDoc Highlighter
SyntaxHighlighter groovyDocHighlighter = new GroovyDocSyntaxHighlighter();
final LayerDescriptor groovyDocLayer = new LayerDescriptor(groovyDocHighlighter, "\n", GroovySyntaxHighlighter.DOC_COMMENT_CONTENT);
registerLayer(GroovyDocElementTypes.GROOVY_DOC_COMMENT, groovyDocLayer);
}
Aggregations