List<CommentRange> (final PsiFile file, final CharSequence chars, final TextRange range, final boolean multiLine) { if (file instanceof PsiPlainTextFile) { FileType fType = file.getFileType(); if (fType instanceof CustomSyntaxTableFileType) { Lexer lexer = SyntaxHighlighterFactory.getSyntaxHighlighter(fType, file.getProject(), file.getVirtualFile()).getHighlightingLexer(); return findComments(lexer, chars, range, COMMENT_TOKENS, null, multiLine); } else { return Collections.singletonList(new CommentRange(0, file.getTextLength())); } } else { List<CommentRange> commentRanges = new ArrayList<>(); final FileViewProvider viewProvider = file.getViewProvider(); final Set<Language> relevantLanguages = viewProvider.getLanguages(); for (Language lang : relevantLanguages) { final SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(lang, file.getProject(), file.getVirtualFile()); Lexer lexer = syntaxHighlighter.getHighlightingLexer(); TokenSet commentTokens = null; IndexPatternBuilder builderForFile = null; for (IndexPatternBuilder builder : IndexPatternBuilder.EP_NAME.getExtensionList()) { Lexer lexerFromBuilder = builder.getIndexingLexer(file); if (lexerFromBuilder != null) { lexer = lexerFromBuilder; commentTokens = builder.getCommentTokenSet(file); builderForFile = builder; } } if (builderForFile == null) { final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang); if (parserDefinition != null) { commentTokens = parserDefinition.getCommentTokens(); } } if (commentTokens != null) { List<CommentRange> langRanges = findComments(lexer, chars, range, commentTokens, builderForFile, multiLine); mergeCommentLists(commentRanges, langRanges); } } return commentRanges; } }