11package net .seesharpsoft .intellij .plugins .csv ;
22
3+ import com .intellij .codeInsight .daemon .impl .DaemonCodeAnalyzerImpl ;
4+ import com .intellij .codeInsight .daemon .impl .HighlightInfo ;
5+ import com .intellij .codeInsight .daemon .impl .HighlightInfoType ;
6+ import com .intellij .openapi .Disposable ;
7+ import com .intellij .openapi .editor .Document ;
8+ import com .intellij .openapi .project .DumbService ;
9+ import com .intellij .openapi .project .Project ;
10+ import com .intellij .openapi .util .Disposer ;
11+ import com .intellij .psi .PsiDocumentManager ;
12+ import com .intellij .psi .PsiFile ;
13+ import com .intellij .psi .impl .cache .CacheManager ;
14+ import com .intellij .psi .impl .source .PsiFileImpl ;
15+ import com .intellij .psi .impl .source .tree .FileElement ;
16+ import com .intellij .psi .search .GlobalSearchScope ;
17+ import com .intellij .testFramework .EdtTestUtil ;
18+ import com .intellij .testFramework .ExpectedHighlightingData ;
319import com .intellij .testFramework .fixtures .LightCodeInsightFixtureTestCase ;
20+ import org .jetbrains .annotations .NotNull ;
21+
22+ import java .util .Collections ;
23+ import java .util .Iterator ;
24+ import java .util .List ;
25+
26+ import static net .seesharpsoft .intellij .plugins .csv .CsvAnnotator .CSV_COLUMN_INFO_SEVERITY ;
427
528public class CsvAnnotatorTest extends LightCodeInsightFixtureTestCase {
629
@@ -11,7 +34,68 @@ protected String getTestDataPath() {
1134
1235 public void testAnnotator () {
1336 myFixture .configureByFile ("AnnotatorTestData.csv" );
14- myFixture .checkHighlighting (true , true , true , true );
37+ this .collectAndCheckHighlighting ();
38+ }
39+
40+ private long collectAndCheckHighlighting () {
41+ ExpectedHighlightingData data = new ExpectedHighlightingData (myFixture .getEditor ().getDocument (), false , false , true , false , this .getHostFile ());
42+ data .registerHighlightingType ("csv_column_info" , new ExpectedHighlightingData .ExpectedHighlightingSet (CSV_COLUMN_INFO_SEVERITY , false , true ));
43+ data .init ();
44+ return this .collectAndCheckHighlighting (data );
45+ }
46+
47+ private PsiFile getHostFile () {
48+ return myFixture .getFile ();
49+ }
50+
51+ private long collectAndCheckHighlighting (@ NotNull ExpectedHighlightingData data ) {
52+ Project project = myFixture .getProject ();
53+ EdtTestUtil .runInEdtAndWait (() -> {
54+ PsiDocumentManager .getInstance (project ).commitAllDocuments ();
55+ });
56+ PsiFileImpl file = (PsiFileImpl )this .getHostFile ();
57+ FileElement hardRefToFileElement = file .calcTreeElement ();
58+ if (!DumbService .isDumb (project )) {
59+ CacheManager .SERVICE .getInstance (project ).getFilesWithWord ("XXX" , (short )2 , GlobalSearchScope .allScope (project ), true );
60+ }
61+
62+ long start = System .currentTimeMillis ();
63+ Disposable disposable = Disposer .newDisposable ();
64+
65+ List infos ;
66+ try {
67+ infos = myFixture .doHighlighting ();
68+ this .removeDuplicatedRangesForInjected (infos );
69+ } finally {
70+ Disposer .dispose (disposable );
71+ }
72+
73+ long elapsed = System .currentTimeMillis () - start ;
74+ data .checkResult (infos , file .getText ());
75+ if (data .hasLineMarkers ()) {
76+ Document document = myFixture .getDocument (this .getFile ());
77+ data .checkLineMarkers (DaemonCodeAnalyzerImpl .getLineMarkers (document , myFixture .getProject ()), document .getText ());
78+ }
79+
80+ hardRefToFileElement .hashCode ();
81+ return elapsed ;
82+ }
83+
84+ private static void removeDuplicatedRangesForInjected (@ NotNull List <HighlightInfo > infos ) {
85+ Collections .sort (infos , (o1 , o2 ) -> {
86+ int i = o2 .startOffset - o1 .startOffset ;
87+ return i != 0 ? i : o1 .getSeverity ().myVal - o2 .getSeverity ().myVal ;
88+ });
89+ HighlightInfo prevInfo = null ;
90+
91+ HighlightInfo info ;
92+ for (Iterator it = infos .iterator (); it .hasNext (); prevInfo = info .type == HighlightInfoType .INJECTED_LANGUAGE_FRAGMENT ? info : null ) {
93+ info = (HighlightInfo )it .next ();
94+ if (prevInfo != null && info .getSeverity () == HighlightInfoType .SYMBOL_TYPE_SEVERITY && info .getDescription () == null && info .startOffset == prevInfo .startOffset && info .endOffset == prevInfo .endOffset ) {
95+ it .remove ();
96+ }
97+ }
98+
1599 }
16100
17101}
0 commit comments