com.intellij.openapi.fileTypes.FileTypeEditorHighlighterProviders Java Examples

The following examples show how to use com.intellij.openapi.fileTypes.FileTypeEditorHighlighterProviders. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoyFileType.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
private SoyFileType() {
  super(SoyLanguage.INSTANCE);
  FileTypeEditorHighlighterProviders.INSTANCE.addExplicitExtension(
      this,
      (@Nullable Project project,
          @NotNull FileType fileType,
          @Nullable VirtualFile virtualFile,
          @NotNull EditorColorsScheme editorColorsScheme) ->
          new SoyLayeredHighlighter(project, virtualFile, editorColorsScheme));
}
 
Example #2
Source File: LatteFileType.java    From intellij-latte with MIT License 5 votes vote down vote up
private LatteFileType() {
	super(LatteLanguage.INSTANCE);

	FileTypeEditorHighlighterProviders.INSTANCE.addExplicitExtension(this, new EditorHighlighterProvider() {
		public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) {
			return new LatteEditorHighlighter(project, virtualFile,colors);
		}
	});
}
 
Example #3
Source File: DustFileType.java    From Intellij-Dust with MIT License 5 votes vote down vote up
private DustFileType() {
  super(DustLanguage.INSTANCE);
  // register highlighter - lazy singleton factory
  FileTypeEditorHighlighterProviders.INSTANCE.addExplicitExtension(this, new EditorHighlighterProvider() {
    public EditorHighlighter getEditorHighlighter(@Nullable Project project,
                                                  @NotNull FileType fileType,
                                                  @Nullable VirtualFile virtualFile,
                                                  @NotNull EditorColorsScheme editorColorsScheme) {
      return new DustLayeredSyntaxHighlighter(project, virtualFile, editorColorsScheme);
    }
  });
}
 
Example #4
Source File: CustomizableLanguageCodeStylePanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
protected EditorHighlighter createHighlighter(final EditorColorsScheme scheme) {
  FileType fileType = getFileType();
  return FileTypeEditorHighlighterProviders.INSTANCE.forFileType(fileType).getEditorHighlighter(ProjectUtil.guessCurrentProject(getPanel()), fileType, null, scheme);
}
 
Example #5
Source File: InjectionRegistrarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static List<InjectedLanguageUtil.TokenInfo> obtainHighlightTokensFromLexer(@Nonnull LanguageVersion languageVersion,
                                                                                   @Nonnull CharSequence outChars,
                                                                                   @Nonnull VirtualFileWindow virtualFile,
                                                                                   @Nonnull Project project,
                                                                                   @Nonnull List<? extends PlaceInfo> placeInfos) {
  VirtualFile file = (VirtualFile)virtualFile;
  FileType fileType = file.getFileType();
  EditorHighlighterProvider provider = FileTypeEditorHighlighterProviders.INSTANCE.forFileType(fileType);
  EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  EditorHighlighter highlighter = provider.getEditorHighlighter(project, fileType, file, scheme);
  highlighter.setText(outChars);
  HighlighterIterator iterator = highlighter.createIterator(0);
  int hostNum = -1;
  int prevHostEndOffset = 0;
  LiteralTextEscaper escaper = null;
  int prefixLength = 0;
  int suffixLength = 0;
  TextRange rangeInsideHost = null;
  int shredEndOffset = -1;
  List<InjectedLanguageUtil.TokenInfo> tokens = new ArrayList<>(outChars.length() / 5); // avg. token per 5 chars
  while (!iterator.atEnd()) {
    IElementType tokenType = iterator.getTokenType();
    TextRange range = new ProperTextRange(iterator.getStart(), iterator.getEnd());
    while (range != null && !range.isEmpty()) {
      if (range.getStartOffset() >= shredEndOffset) {
        hostNum++;
        PlaceInfo info = placeInfos.get(hostNum);
        shredEndOffset = info.rangeInDecodedPSI.getEndOffset();
        prevHostEndOffset = range.getStartOffset();
        escaper = info.myEscaper;
        rangeInsideHost = info.rangeInHostElement;
        prefixLength = info.prefix.length();
        suffixLength = info.suffix.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;
        }
        ProperTextRange rangeInHost = new ProperTextRange(start, end);
        tokens.add(new InjectedLanguageUtil.TokenInfo(tokenType, rangeInHost, hostNum, iterator.getTextAttributes()));
      }
      range = spilled;
    }
    iterator.advance();
  }
  return tokens;
}