KTIJ-31347 High CPU usage when non-source root .kt file is opened

(cherry picked from commit 4fe1aada132f89fa8a515d5477d2c511dafa3863)

IJ-CR-153631

GitOrigin-RevId: 095ebbc613cd5e3a5685b64c3dab5af3a03b3010
This commit is contained in:
Alexey Kudravtsev
2024-10-14 17:59:21 +02:00
committed by intellij-monorepo-bot
parent 5d69e05337
commit 0d206b1e3e

View File

@@ -176,6 +176,7 @@ public final class TextEditorHighlightingPassRegistrarImpl extends TextEditorHig
PassConfig[] frozenPassConfigs = freezeRegisteredPassFactories();
List<TextEditorHighlightingPass> result = new ArrayList<>(frozenPassConfigs.length);
IntList passesRefusedToCreate = new IntArrayList();
boolean shouldHighlightFile = ProblemHighlightFilter.shouldHighlightFile(psiFile);
try (AccessToken ignored = ClientId.withExplicitClientId(ClientEditorManager.Companion.getClientId(editor))) {
for (int passId = 1; passId < frozenPassConfigs.length; passId++) {
ProgressManager.checkCanceled();
@@ -185,8 +186,8 @@ public final class TextEditorHighlightingPassRegistrarImpl extends TextEditorHig
continue;
}
TextEditorHighlightingPassFactory factory = passConfig.passFactory;
TextEditorHighlightingPass pass = DumbService.getInstance(myProject).isUsableInCurrentContext(factory)
&& ProblemHighlightFilter.shouldHighlightFile(psiFile) ? factory.createHighlightingPass(psiFile, editor) : null;
TextEditorHighlightingPass pass = shouldHighlightFile && DumbService.getInstance(myProject).isUsableInCurrentContext(factory) ?
factory.createHighlightingPass(psiFile, editor) : null;
if (pass == null || !DumbService.getInstance(myProject).isUsableInCurrentContext(pass)) {
passesRefusedToCreate.add(passId);
}
@@ -216,8 +217,13 @@ public final class TextEditorHighlightingPassRegistrarImpl extends TextEditorHig
DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject);
FileStatusMap statusMap = daemonCodeAnalyzer.getFileStatusMap();
for (IntListIterator iterator = passesRefusedToCreate.iterator(); iterator.hasNext(); ) {
statusMap.markFileUpToDate(document, iterator.nextInt());
for (int i = 0; i < passesRefusedToCreate.size(); i++) {
int id = passesRefusedToCreate.getInt(i);
statusMap.markFileUpToDate(document, id);
}
if (!shouldHighlightFile) {
// in case when some extension prohibited highlighting, return empty pass to distinguish from error during pass creation and endless restart
result.add(new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, document));
}
return result;
}