From 1d1d3d22385d6b3ac43f7382620a3d26330bbd85 Mon Sep 17 00:00:00 2001 From: "Maxim.Kolmakov" Date: Fri, 6 Sep 2024 18:22:47 +0200 Subject: [PATCH] Remove the doHighlight command and its corresponding tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The initial purpose of doHighlight was to measure the time it takes to apply different text attributes (color, style, etc.) to tokens. However, there hasn't been (and still isn't) a generic way to achieve this effectively. Currently, this command triggers HighlightVisitorBasedInspection, which is essentially a "mock" inspection used in Global Analysis tools (such as inspect.sh, Qodana, etc.). This inspection combines three functionalities—syntax error, annotator, and generic error—into one. As a result, the highlighting produced by this command is a very rough estimation, if not just random values. Highlighting in general is handled by the editor, which leverages information from the parser, annotators, additional passes, and specific inspections (e.g., dead code, which has a unique severity that makes the code appear grey). At this point, we do not have a clear way to make doHighlight work correctly, nor are we certain it's needed at all. GitOrigin-RevId: 8c821f456e867395bb6de55a142a000cfc3a50a9 --- .../commands/generalCommandChain.kt | 8 -- .../BaseCommandProvider.java | 1 - .../commands/DoHighlighting.java | 90 ------------------- 3 files changed, 99 deletions(-) delete mode 100644 plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/DoHighlighting.java diff --git a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt index 3a6edef3ce0c..b6e249e03665 100644 --- a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt +++ b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt @@ -361,14 +361,6 @@ fun T.doComplete(times: Int): T = apply { } } -fun T.doHighlightingWarmup(): T = apply { - addCommand("${CMD_PREFIX}doHighlight", WARMUP) -} - -fun T.doHighlighting(): T = apply { - addCommand("${CMD_PREFIX}doHighlight") -} - fun T.openProjectView(): T = apply { addCommand("${CMD_PREFIX}openProjectView") } diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java index ad1436460447..52cd6286bfbf 100644 --- a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java +++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java @@ -60,7 +60,6 @@ public final class BaseCommandProvider implements CommandProvider { Map.entry(SearchEverywhereCommand.PREFIX, SearchEverywhereCommand::new), Map.entry(SelectFileInProjectViewCommand.PREFIX, SelectFileInProjectViewCommand::new), Map.entry(ExpandProjectMenuCommand.PREFIX, ExpandProjectMenuCommand::new), - Map.entry(DoHighlighting.PREFIX, DoHighlighting::new), Map.entry(ReloadFilesCommand.PREFIX, ReloadFilesCommand::new), Map.entry(AddFileCommand.PREFIX, AddFileCommand::new), Map.entry(RenameFileCommand.PREFIX, RenameFileCommand::new), diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/DoHighlighting.java b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/DoHighlighting.java deleted file mode 100644 index e4b77d22dc6a..000000000000 --- a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/DoHighlighting.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.jetbrains.performancePlugin.commands; - -import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator; -import com.intellij.codeInsight.daemon.impl.HighlightVisitorBasedInspection; -import com.intellij.codeInspection.GlobalInspectionContext; -import com.intellij.codeInspection.GlobalInspectionTool; -import com.intellij.codeInspection.InspectionEngine; -import com.intellij.codeInspection.InspectionManager; -import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.playback.PlaybackContext; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.platform.diagnostic.telemetry.helpers.TraceKt; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiFile; -import com.intellij.util.concurrency.AppExecutorUtil; -import com.jetbrains.performancePlugin.PerformanceTestSpan; -import com.jetbrains.performancePlugin.utils.ActionCallbackProfilerStopper; -import io.opentelemetry.context.Context; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.concurrency.Promise; -import org.jetbrains.concurrency.Promises; - -import java.util.concurrent.Callable; - -import static com.intellij.psi.PsiManager.getInstance; - -/** - * Command runs highlighting pass. - * Runs all highlighting passes. Can't be invoked multiple times in a row since it drops caches before run. - * Example: %doHighlighting - */ -public final class DoHighlighting extends PerformanceCommand { - public static final String NAME = "doHighlight"; - public static final String PREFIX = CMD_PREFIX + NAME; - - public static final String SPAN_NAME = "highlighting"; - public static final int MILLIS_IN_NANO = 1000000; - - public DoHighlighting(@NotNull String text, int line) { - super(text, line); - } - - @Override - protected String getName() { - return NAME; - } - - @NotNull - @Override - protected Promise _execute(@NotNull PlaybackContext context) { - ActionCallback actionCallback = new ActionCallbackProfilerStopper(); - ApplicationManager.getApplication().invokeAndWait(Context.current().wrap(() -> { - Project project = context.getProject(); - final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); - if (editor == null) { - actionCallback.reject("Editor is not open"); - return; - } - PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); - if (psiFile == null) { - actionCallback.reject("Missing PSI file in the editor"); - return; - } - getInstance(project).dropPsiCaches(); - ReadAction.nonBlocking(Context.current().wrap((Callable)() -> { - long start = System.nanoTime(); - TraceKt.use(PerformanceTestSpan.TRACER.spanBuilder(SPAN_NAME), span -> { - GlobalInspectionTool tool = new HighlightVisitorBasedInspection() - .setHighlightErrorElements(true).setRunAnnotators(true).setRunVisitors(false); - InspectionManager inspectionManager = InspectionManager.getInstance(project); - GlobalInspectionContext globalContext = inspectionManager.createNewGlobalContext(); - InspectionEngine.runInspectionOnFile(psiFile, new GlobalInspectionToolWrapper(tool), globalContext); - - span.setAttribute("lines", editor.getDocument().getLineCount()); - long stop = System.nanoTime(); - span.setAttribute("timeToLines", (double)(stop - start) / MILLIS_IN_NANO / (Math.max(1, editor.getDocument().getLineCount()))); - return null; - }); - actionCallback.setDone(); - return null; - })).wrapProgress(new DaemonProgressIndicator()).submit(AppExecutorUtil.getAppExecutorService()); - })); - return Promises.toPromise(actionCallback); - } -}