use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class GradleConsoleFilter method applyFilter.
@Nullable
@Override
public Result applyFilter(final String line, final int entireLength) {
String[] filePrefixes = new String[] { "Build file '", "build file '" };
String[] linePrefixes = new String[] { "' line: ", "': " };
String filePrefix = null;
String linePrefix = null;
for (int i = 0; i < filePrefixes.length; i++) {
int filePrefixIndex = StringUtil.indexOf(line, filePrefixes[i]);
if (filePrefixIndex != -1) {
filePrefix = filePrefixes[i];
linePrefix = linePrefixes[i];
break;
}
}
if (filePrefix == null || linePrefix == null) {
return null;
}
int filePrefixIndex = StringUtil.indexOf(line, filePrefix);
final String fileAndLineNumber = line.substring(filePrefix.length() + filePrefixIndex);
int linePrefixIndex = StringUtil.indexOf(fileAndLineNumber, linePrefix);
if (linePrefixIndex == -1) {
return null;
}
final String fileName = fileAndLineNumber.substring(0, linePrefixIndex);
myFilteredFileName = fileName;
String lineNumberStr = fileAndLineNumber.substring(linePrefixIndex + linePrefix.length(), fileAndLineNumber.length()).trim();
int lineNumberEndIndex = 0;
for (int i = 0; i < lineNumberStr.length(); i++) {
if (Character.isDigit(lineNumberStr.charAt(i))) {
lineNumberEndIndex = i;
} else {
break;
}
}
lineNumberStr = lineNumberStr.substring(0, lineNumberEndIndex + 1);
int lineNumber;
try {
lineNumber = Integer.parseInt(lineNumberStr);
myFilteredLineNumber = lineNumber;
} catch (NumberFormatException e) {
return null;
}
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(fileName.replace(File.separatorChar, '/'));
if (file == null) {
return null;
}
int textStartOffset = entireLength - line.trim().length() + filePrefix.length() - 1;
int highlightEndOffset = textStartOffset + fileName.length();
OpenFileHyperlinkInfo info = new OpenFileHyperlinkInfo(myProject, file, Math.max(lineNumber - 1, 0));
TextAttributes attributes = HYPERLINK_ATTRIBUTES.clone();
if (!ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file)) {
Color color = UIUtil.getInactiveTextColor();
attributes.setForegroundColor(color);
attributes.setEffectColor(color);
}
return new Result(textStartOffset, highlightEndOffset, info, attributes);
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class ChameleonSyntaxHighlightingPass method collectHighlights.
private void collectHighlights(@NotNull PsiElement element, @NotNull List<HighlightInfo> inside, @NotNull List<HighlightInfo> outside, @NotNull ProperTextRange priorityRange) {
EditorColorsScheme scheme = ObjectUtils.notNull(getColorsScheme(), EditorColorsManager.getInstance().getGlobalScheme());
TextAttributes defaultAttrs = scheme.getAttributes(HighlighterColors.TEXT);
Language language = ILazyParseableElementType.LANGUAGE_KEY.get(element.getNode());
if (language == null)
return;
SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, myFile.getVirtualFile());
for (PsiElement token : psiTraverser(element).traverse(TreeTraversal.LEAVES_DFS)) {
TextRange tr = token.getTextRange();
if (tr.isEmpty())
continue;
IElementType type = PsiUtilCore.getElementType(token);
TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(type);
// force attribute colors to override host' ones
TextAttributes attributes = null;
for (TextAttributesKey key : keys) {
TextAttributes attrs2 = scheme.getAttributes(key);
if (attrs2 != null) {
attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
}
}
TextAttributes forcedAttributes;
if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
forcedAttributes = TextAttributes.ERASE_MARKER;
} else {
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
(priorityRange.contains(tr) ? inside : outside).add(info);
forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
}
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(forcedAttributes).createUnconditionally();
(priorityRange.contains(tr) ? inside : outside).add(info);
}
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class InjectedGeneralHighlightingPass method addInjectedPsiHighlights.
// returns false if canceled
private boolean addInjectedPsiHighlights(@NotNull final Set<PsiFile> injectedFiles, @NotNull final ProgressIndicator progress, @NotNull final Collection<HighlightInfo> outInfos) {
if (injectedFiles.isEmpty())
return true;
final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(myProject);
final TextAttributes injectedAttributes = myGlobalScheme.getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT);
return JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(injectedFiles), progress, isFailFastOnAcquireReadAction(), injectedPsi -> addInjectedPsiHighlights(injectedPsi, injectedAttributes, outInfos, progress, injectedLanguageManager));
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class SeverityUtil method getSeverityBasedTextAttributes.
private static SeverityRegistrar.SeverityBasedTextAttributes getSeverityBasedTextAttributes(@NotNull SeverityRegistrar registrar, @NotNull HighlightInfoType type) {
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final TextAttributes textAttributes = scheme.getAttributes(type.getAttributesKey());
if (textAttributes != null) {
return new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes, (HighlightInfoType.HighlightInfoTypeImpl) type);
}
TextAttributes severity = registrar.getTextAttributesBySeverity(type.getSeverity(null));
return new SeverityRegistrar.SeverityBasedTextAttributes(severity, (HighlightInfoType.HighlightInfoTypeImpl) type);
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class HighlightUsagesHandler method highlightOtherOccurrences.
public static void highlightOtherOccurrences(final List<PsiElement> otherOccurrences, Editor editor, boolean clearHighlights) {
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
PsiElement[] elements = PsiUtilCore.toPsiElementArray(otherOccurrences);
doHighlightElements(editor, elements, attributes, clearHighlights);
}
Aggregations